-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from smplrspace/next
v2.25.0
- Loading branch information
Showing
9 changed files
with
380 additions
and
15 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 |
---|---|---|
@@ -1,14 +1,18 @@ | ||
--- | ||
sidebar_position: 3 | ||
sidebar_label: Legend | ||
sidebar_label: Legends | ||
slug: legend | ||
--- | ||
|
||
import Legend from '@site/src/components/Legend'; | ||
import ColorSwatches from '@site/src/components/ColorSwatches'; | ||
import IconsSwatches from '@site/src/components/IconsSwatches'; | ||
|
||
# Legend | ||
# Legends | ||
|
||
## React component | ||
## Numerical scale legends | ||
|
||
### React component | ||
|
||
To render the legend of a numerical color scale, you can use the `<Legend>` component as follow: | ||
|
||
|
@@ -49,7 +53,7 @@ interface LegendProps { | |
|
||
Note that the Legend will fill the width of its container. [Get in touch](mailto:[email protected]) if you have ideas on improvements or pragmatic options we may have missed. | ||
|
||
## Vanilla javascript | ||
### Vanilla javascript | ||
|
||
For non-react codebases, we provide a vanilla Javascript function that wraps this component and renders it into a container. | ||
|
||
|
@@ -76,9 +80,9 @@ smplr.Color.drawLegend({ | |
``` | ||
|
||
- `containerId` is the "id" of the html container where smplr.js should render the legend, something like "smplr-legend" that can be found in your html. Only ids are supported, not classes. | ||
- `...legendProps` represents all other options as per the [react component section](#react-component). | ||
- `...legendProps` represents all other options as per the previous section. | ||
|
||
## Example legend | ||
### Example | ||
|
||
<Legend /> | ||
|
||
|
@@ -100,3 +104,196 @@ smplr.Color.drawLegend({ | |
}, | ||
}); | ||
``` | ||
|
||
## Categorical scale legends | ||
|
||
### React component | ||
|
||
To render the legend of a numerical color scale, you can use the `<ColorSwatches>` component as follow: | ||
|
||
```tsx | ||
interface ColorSwatchesProps { | ||
swatches: { | ||
color: string | ||
label: string | ||
group?: string | ||
}[] | ||
size?: number | ||
correctColor?: boolean | ||
noLabels?: boolean | ||
} | ||
<ColorSwatches {...props: ColorSwatchesProps}> | ||
|
||
// example usage with Color from smplr | ||
<smplr.Color.ColorSwatches | ||
swatches={[ | ||
{ | ||
color: 'red', | ||
label: 'Alert', | ||
}, | ||
{ | ||
color: 'orange', | ||
label: 'Warning', | ||
}, | ||
{ | ||
color: 'green', | ||
label: 'All ok', | ||
}, | ||
]} | ||
/> | ||
``` | ||
|
||
- `swatches` defines the colors and labels used for the swatches. Note that an optional group can be provided to create multiple lines with a label ahead of each group. You can refer to the [`ragSwatches`](/api-reference/color/scales#ragscale) and [`categorySwatches`](/api-reference/color/scales#categoryscale) helpers to generate swatches for categorical scales generated with our functions. | ||
- `size` - _optional_ - is the size in pixels of each swatch. _Default value: 10._ | ||
- `correctColor` - _optional_ - lets you choose if the colors of the legend should be corrected to match the ones from the viewer as per the explanation in the [color mapping section](./overview#color-mapping). We correct them by default. _Default value: true._ | ||
- `noLabels` - _optional_ - set this to true to hide labels. _Default value: false._ | ||
|
||
|
||
### Vanilla javascript | ||
|
||
For non-react codebases, we provide a vanilla Javascript function that wraps this component and renders it into a container. | ||
|
||
```ts | ||
smplr.Color.drawColorSwatches({ | ||
containerId: string | ||
...swatchesProps: ColorSwatchesProps // see above | ||
}) | ||
|
||
// example usage | ||
smplr.Color.drawColorSwatches({ | ||
containerId: 'smplr-legend', | ||
swatches: [ | ||
{ | ||
color: 'red', | ||
label: 'Alert', | ||
}, | ||
{ | ||
color: 'orange', | ||
label: 'Warning', | ||
}, | ||
{ | ||
color: 'green', | ||
label: 'All ok', | ||
}, | ||
] | ||
}) | ||
``` | ||
|
||
- `containerId` is the "id" of the html container where smplr.js should render the legend, something like "smplr-legend" that can be found in your html. Only ids are supported, not classes. | ||
- `...swatchesProps` represents all other options as per the previous section. | ||
|
||
### Example | ||
|
||
<ColorSwatches /> | ||
|
||
was rendered with the code below: | ||
|
||
```ts | ||
smplr.Color.drawColorSwatches({ | ||
containerId: 'smplr-legend', | ||
swatches: [ | ||
{ | ||
color: 'red', | ||
label: 'Alert', | ||
}, | ||
{ | ||
color: 'orange', | ||
label: 'Warning', | ||
}, | ||
{ | ||
color: 'green', | ||
label: 'All ok', | ||
}, | ||
] | ||
}); | ||
``` | ||
|
||
## Icons legends | ||
|
||
### React component | ||
|
||
To render the legend of a numerical color scale, you can use the `<IconsSwatches>` component as follow: | ||
|
||
```tsx | ||
interface IconsSwatchesProps { | ||
icons: { | ||
url: string | ||
label: string | ||
group?: string | ||
}[] | ||
height?: number | ||
noLabels?: boolean | ||
} | ||
<IconsSwatches {...props: IconsSwatchesProps}> | ||
|
||
// example usage with Color from smplr | ||
<smplr.Color.IconsSwatches | ||
icons={[ | ||
{ | ||
url: 'https://retail.smplrspace.io/img/electric.png', | ||
label: 'EV charging', | ||
}, | ||
{ | ||
url: 'https://retail.smplrspace.io/img/wheelchair.png', | ||
label: 'Reduced mobility', | ||
} | ||
]} | ||
/> | ||
``` | ||
|
||
- `icons` defines the icons and labels used for the swatches. Note that an optional group can be provided to create multiple lines with a label ahead of each group. | ||
- `height` - _optional_ - is the height in pixels of each swatch. _Default value: 16._ | ||
- `noLabels` - _optional_ - set this to true to hide labels. _Default value: false._ | ||
|
||
|
||
### Vanilla javascript | ||
|
||
For non-react codebases, we provide a vanilla Javascript function that wraps this component and renders it into a container. | ||
|
||
```ts | ||
smplr.Color.drawIconsSwatches({ | ||
containerId: string | ||
...swatchesProps: IconsSwatchesProps // see above | ||
}) | ||
|
||
// example usage | ||
smplr.Color.drawIconsSwatches({ | ||
containerId: 'smplr-legend', | ||
icons: [ | ||
{ | ||
url: 'https://retail.smplrspace.io/img/electric.png', | ||
label: 'EV charging', | ||
}, | ||
{ | ||
url: 'https://retail.smplrspace.io/img/wheelchair.png', | ||
label: 'Reduced mobility', | ||
} | ||
] | ||
}) | ||
``` | ||
|
||
- `containerId` is the "id" of the html container where smplr.js should render the legend, something like "smplr-legend" that can be found in your html. Only ids are supported, not classes. | ||
- `...swatchesProps` represents all other options as per the previous section. | ||
|
||
### Example | ||
|
||
<IconsSwatches /> | ||
|
||
was rendered with the code below: | ||
|
||
```ts | ||
smplr.Color.drawIconsSwatches({ | ||
containerId: 'smplr-legend', | ||
icons: [ | ||
{ | ||
url: 'https://retail.smplrspace.io/img/electric.png', | ||
label: 'EV charging', | ||
}, | ||
{ | ||
url: 'https://retail.smplrspace.io/img/wheelchair.png', | ||
label: 'Reduced mobility', | ||
} | ||
], | ||
height: 20 | ||
}); | ||
``` |
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
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
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
Oops, something went wrong.