0.5.0 • Published 9 months ago

@redsift/d3-rs-legends v0.5.0

Weekly downloads
519
License
MIT
Repository
github
Last release
9 months ago

d3-rs-legends

d3-rs-legends generate a legend for charts.

Builds

Circle CI

Example

View @redsift/d3-rs-legends on Codepen

Default

Default bottom orientation(https://bricks.redsift.io/reusable/d3-rs-legends.svg?_datum=['A', 'B', 'C'])

Left

Left orientation(https://bricks.redsift.io/reusable/d3-rs-legends.svg?_datum=['A', 'B', 'C']&orientation=left)

Right

Right orientation(https://bricks.redsift.io/reusable/d3-rs-legends.svg?_datum=['A Short', 'B', 'C Long']&orientation=right)

Top, rounded and spaced out

Top orientation(https://bricks.redsift.io/reusable/d3-rs-legends.svg?_datum=['A', 'B', 'C']&orientation=top&radius=10&padding=40)

Usage

Browser

<script src="//static.redsift.io/reusable/d3-rs-legends/latest/d3-rs-legends.umd-es2015.min.js"></script>
<script>
	var chart = d3_rs_legends.html();
	d3.select('body').datum([ 'A', 'B' ]).call(chart);
</script>

ES6

import { chart } from "@redsift/d3-rs-legends";
let eml = chart.html();
...

Require

var chart = require("@redsift/d3-rs-legends");
var eml = chart.html();
...

Datum

  • Simplest form, array of strings: ['A', 'B', 'C', ...]

Parameters

PropertyDescriptionTransitionPreview
classedString SVG custom classN
width, height, size, scaleInteger SVG container sizes. Typically, use size to scale the chartY
marginObject, Number Margin affecting all chart elements
insetObject, Number Margin affecting the legend
styleString Custom CSS to inject into chartN
backgroundColor
theme*lightdark*
orientationString Location of the legend, one of top, bottom, left, rightN
legendSizeInteger Size of the color sampleN
spacingInteger Estimator of the amount of space to resere of each char in the text label
paddingInteger Pixels between each legend element
radiusInteger Radius of the legend rectangle. Rounds the element
fillArray, Function Colors to assign to legend in order
toggleableBoolean If true will add a new Checkbox on the left side of the color square to add capability to enable/disable legend items.N
onEnabledLegendItemsChangeFunction To be called whenever enabled legend items changed. It's called passing an array of the enabled legend indexesN
tintColorString Color to use for checkboxN