@vx/legend
Legends associate shapes and colors to data.
Example
import { LegendThreshold } from '@vx/legend';
import { scaleThreshold } from '@vx/scale';
const threshold = scaleThreshold({
domain: [0.02, 0.04, 0.06, 0.08, 0.1],
range: ['#f2f0f7', '#dadaeb', '#bcbddc', '#9e9ac8', '#756bb1', '#54278f']
});
function MyChart() {
return (
<div>
<svg>{/** chart stuff */}</svg>
<LegendThreshold
scale={threshold}
direction="column-reverse"
itemDirection="row-reverse"
labelMargin="0 20px 0 0"
shapeMargin="1px 0 0"
/>
</div>
);
}
Installation
npm install --save @vx/legend
Components
API
<Legend />
# Legend.children<func>
# Legend.className<string>
# Legend.direction<string>
# Legend.domain<array>
# Legend.fill<any>
# Legend.itemDirection<string>
# Legend.itemMargin<string>
# Legend.labelAlign<string>
# Legend.labelFlex<string>
# Legend.labelFormat<func>
# Legend.labelMargin<string>
# Legend.labelTransform<func>
Default | function defaultTransform({ scale, labelFormat }) {
return (d, i) => {
return {
datum: d,
index: i,
text: ${labelFormat(d, i)} ,
value: scale(d),
};
};
} |
# Legend.scale<union(func|object)> required
# Legend.shape<any>
# Legend.shapeHeight<union(number|string)>
# Legend.shapeMargin<any>
# Legend.shapeStyle<any>
# Legend.shapeWidth<union(number|string)>
# Legend.size<any>
# Legend.style<any>
Default | {
display: 'flex',
} |
<LegendItem />
# LegendItem.alignItems<string>
# LegendItem.children<any>
# LegendItem.display<string>
# LegendItem.flexDirection<string>
# LegendItem.margin<union(string|number)>
<LegendLabel />
# LegendLabel.align<string>
# LegendLabel.children<any>
# LegendLabel.flex<union(string|number)>
# LegendLabel.label<any>
# LegendLabel.margin<union(string|number)>
<LegendShape />
# LegendShape.fill<any>
# LegendShape.height<any>
# LegendShape.label<any>
# LegendShape.margin<any>
# LegendShape.shape<any>
# LegendShape.shapeStyle<any>
# LegendShape.size<any>
# LegendShape.width<any>
<Linear />
# Linear.domain<array>
# Linear.labelFormat<func>
# Linear.labelTransform<func>
Default | function defaultTransform({ scale, labelFormat }) {
return (d, i) => {
return {
text: ${labelFormat(d, i)} ,
value: scale(d),
};
};
} |
# Linear.scale<func> required
# Linear.steps<number>
<Ordinal />
# Ordinal.domain<array>
# Ordinal.labelFormat<func>
# Ordinal.labelTransform<func>
Default | function defaultTransform({ scale, labelFormat }) {
return (d, i) => {
return {
datum: d,
index: i,
text: ${labelFormat(d, i)} ,
value: scale(d),
};
};
} |
# Ordinal.scale<func> required
<Quantile />
# Quantile.domain<array>
# Quantile.labelDelimiter<string>
# Quantile.labelFormat<func>
# Quantile.labelTransform<func>
# Quantile.scale<func> required
<Size />
# Size.domain<array>
# Size.labelFormat<func>
# Size.labelTransform<func>
Default | function defaultTransform({ scale, labelFormat }) {
return (d, i) => {
return {
text: ${labelFormat(d, i)} ,
value: scale(d),
datum: d,
index: i,
};
};
} |
# Size.scale<func> required
# Size.steps<number>
<Threshold />
# Threshold.domain<array>
# Threshold.labelDelimiter<string>
# Threshold.labelFormat<func>
# Threshold.labelLower<string>
# Threshold.labelTransform<func>
# Threshold.labelUpper<string>
# Threshold.scale<func> required
<Circle />
# Circle.fill<any>
# Circle.height<union(number|string)>
# Circle.style<object>
# Circle.width<union(number|string)>
<Rect />
# Rect.fill<any>
# Rect.height<union(number|string)>
# Rect.style<object>
# Rect.width<union(number|string)>