-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
107 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// @flow weak | ||
|
||
import React from 'react'; | ||
import Surface from 'resonance/Surface'; | ||
|
||
/** | ||
* A simple example of `Surface` component. | ||
* By adopting the the convention of defining view and trbl props | ||
* it makes it easier to reason about the placement of child elements. | ||
* Note how the rect element has no translation and is drawn with the correct margins around it | ||
*/ | ||
const color = 'rgba(0,0,0,0.3)'; | ||
|
||
const view = [1000, 250]; // view [width, height] fed to SVG viewbox attribute | ||
const trbl = [10, 10, 10, 100]; // Margins [top, right, bottom, left] for the SVG | ||
|
||
const dims = [ // The usable dimensions. | ||
view[0] - trbl[1] - trbl[3], | ||
view[1] - trbl[0] - trbl[2], | ||
]; | ||
|
||
const Exmaple1 = () => ( | ||
<Surface | ||
view={view} | ||
trbl={trbl} | ||
style={{ backgroundColor: color }} | ||
> | ||
<rect width={dims[0]} height={dims[1]} fill={color} /> | ||
</Surface> | ||
); | ||
|
||
export default Exmaple1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// @flow weak | ||
|
||
import React from 'react'; | ||
import Surface from 'resonance/Surface'; | ||
|
||
/** | ||
* This example shows how surfaces will conform to their containers | ||
* NOTE: Bootstrap grid CSS is loaded on this page and are used to define the layout below | ||
*/ | ||
const color = 'rgba(0,0,0,0.3)'; | ||
|
||
const view = [1000, 250]; // view [width, height] fed to SVG viewbox attribute | ||
const trbl = [10, 10, 10, 100]; // Margins [top, right, bottom, left] for the SVG | ||
|
||
const dims = [ // The usable dimensions. | ||
view[0] - trbl[1] - trbl[3], | ||
view[1] - trbl[0] - trbl[2], | ||
]; | ||
|
||
const GreySurface = () => ( | ||
<Surface | ||
view={view} | ||
trbl={trbl} | ||
style={{ backgroundColor: color }} | ||
> | ||
<rect width={dims[0]} height={dims[1]} fill={color} /> | ||
</Surface> | ||
); | ||
|
||
const Example2 = () => ( | ||
<div className="row"> | ||
{[1, 2, 3, 4].map((d) => ( | ||
<div key={d} className="col-md-3 col-sm-6" style={{ padding: 2 }}> | ||
<GreySurface /> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
|
||
export default Example2; |
74 changes: 0 additions & 74 deletions
74
docs/src/routes/documentation/Surface/ExampleComposition.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
docs/src/routes/documentation/Surface/ExampleIconButton.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,22 @@ | ||
## Surface | ||
|
||
A basic SVG container for visualizations. | ||
A basic svg container for visualizations. | ||
It's completely optional to use the ***Surface*** as the other components do not depend on it. | ||
Using the ***Surface*** component, the svg will scale to fit its container as the window size adjusts but maintain a constant aspect ratio (unless you update the view prop). | ||
This is an alternative to using JavaScript listeners to update the svg's width and height in response to resize events. | ||
Changing the width and height of the svg via JavaScript can be inefficient for complex visualizations. | ||
Changing the aspect ratio also leads to distorted, inconsistent views of data at different window sizes. | ||
There are, of course, pros and cons to the different methods and in some cases where using JavaScript to resize the svg will be appropriate. | ||
|
||
### A couple of things to note: | ||
|
||
1. The outermost element is a div (not an svg element) with styles to make the contained svg scale correctly in most browsers. | ||
You can augment the outer div styles by sending a style object. | ||
|
||
2. The div has an svg element as its only child. The svg, in turn, contains a single g element as it's child. | ||
|
||
3. The g element is translated into position automatically for you according to the margins you define in your trbl prop. See the examples below. | ||
|
||
4. The child elements of the ***Surface*** will be placed inside of the translated g element. | ||
This makes it easier to adjust your visualization for titles, axes, notes, etc (just adjust the trbl prop). | ||
You can see how this works in the examples below. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters