d3plus-legend
A collection of chart legends and keys.
Installing
If you use NPM, npm install d3plus-legend
. Otherwise, download the latest release. The released bundle supports AMD, CommonJS, and vanilla environments. Create a custom bundle using Rollup or your preferred bundler. You can also load directly from d3plus.org:
<script src="https://d3plus.org/js/d3plus-legend.v0.4.full.min.js"></script>
API Reference
Classes
- BaseClass
- ScaleLegend ⇐
BaseLegend
- ShapeLegend ⇐
BaseLegend
BaseClass
Kind: global class
new BaseClass()
Creates an SVG scale based on an array of data. If data is specified, immediately draws based on the specified array and returns the current class instance. If data is not specified on instantiation, it can be passed/updated after instantiation using the data method.
ScaleLegend ⇐ BaseLegend
Kind: global class
Extends: BaseLegend
new ScaleLegend()
Creates an SVG scale based on an array of data. If data is specified, immediately draws based on the specified array and returns the current class instance. If data is not specified on instantiation, it can be passed/updated after instantiation using the data method.
ScaleLegend.render([callback])
Renders the current ScaleLegend to the page. If a callback is specified, it will be called once the legend is done drawing.
Kind: static method of ScaleLegend
Param | Type |
---|
[callback] | function |
ScaleLegend.align([value])
If value is specified, sets the horizontal alignment to the specified value and returns the current class instance. If value is not specified, returns the current horizontal alignment.
Kind: static method of ScaleLegend
Param | Type | Default | Description |
---|
[value] | String | "center" | Supports "left" and "center" and "right" . |
ScaleLegend.domain([value])
If value is specified, sets the scale domain of the legend and returns the current class instance. If value is not specified, returns the current scale domain.
Kind: static method of ScaleLegend
Param | Type | Default |
---|
[value] | Array | [0, 10] |
ScaleLegend.orient([orient])
If orient is specified, sets the orientation of the shape and returns the current class instance. If orient is not specified, returns the current orientation.
Kind: static method of ScaleLegend
Param | Type | Default | Description |
---|
[orient] | String | "bottom" | Supports "top" , "right" , "bottom" , and "left" orientations. |
ScaleLegend.scale([value])
If value is specified, sets the scale of the legend and returns the current class instance. If value is not specified, returns the current this._d3Scale
Kind: static method of ScaleLegend
Param | Type | Default |
---|
[value] | String | "linear" |
ScaleLegend.ticks([value])
If value is specified, sets the tick values of the legend and returns the current class instance. If value is not specified, returns the current tick values, which by default are interpreted based on the domain and the available width.
Kind: static method of ScaleLegend
ScaleLegend.tickSize([value])
If value is specified, sets the tick size of the legend and returns the current class instance. If value is not specified, returns the current tick size.
Kind: static method of ScaleLegend
Param | Type | Default |
---|
[value] | Number | 5 |
ShapeLegend ⇐ BaseLegend
Kind: global class
Extends: BaseLegend
new ShapeLegend()
Creates an SVG shape legend based on an array of data. If data is specified, immediately draws based on the specified array and returns the current class instance. If data is not specified on instantiation, it can be passed/updated after instantiation using the data method.
ShapeLegend.textBoxConfig([config])
If config is specified, sets the methods that correspond to the key/value pairs for each shape and returns the current class instance. If config is not specified, returns the current shape configuration.
Kind: static method of ShapeLegend
Param | Type | Default |
---|
[config] | Object | {} |
ShapeLegend.render([callback])
Renders the current ShapeLegend to the page. If a callback is specified, it will be called once the legend is done drawing.
Kind: static method of ShapeLegend
Param | Type |
---|
[callback] | function |
ShapeLegend.align([value])
If value is specified, sets the horizontal alignment to the specified value and returns the current class instance. If value is not specified, returns the current horizontal alignment.
Kind: static method of ShapeLegend
Param | Type | Default | Description |
---|
[value] | String | "center" | Supports "left" and "center" and "right" . |
ShapeLegend.data([data])
If data is specified, sets the data array to the specified array and returns the current class instance. If data is not specified, returns the current data array. A shape key will be drawn for each object in the array.
Kind: static method of ShapeLegend
Param | Type | Default |
---|
[data] | Array | [] |
ShapeLegend.id([value])
If value is specified, sets the id accessor to the specified function and returns the current class instance. If value is not specified, returns the current id accessor.
Kind: static method of ShapeLegend
Example
function value(d) {
return d.id;
}
ShapeLegend.label([value])
If value is specified, sets the label accessor to the specified function or string and returns the current class instance. If value is not specified, returns the current label accessor, which is the id accessor by default.
Kind: static method of ShapeLegend
Param | Type |
---|
[value] | function | String |
ShapeLegend.orient([orient])
If orient is specified, sets the orientation of the shape and returns the current class instance. If orient is not specified, returns the current orientation.
Kind: static method of ShapeLegend
Param | Type | Default | Description |
---|
[orient] | String | "horizontal" | Supports "horizontal" and "vertical" orientations. |
ShapeLegend.shape([value])
If value is specified, sets the shape accessor to the specified function or string and returns the current class instance. If value is not specified, returns the current shape accessor.
Kind: static method of ShapeLegend
Param | Type | Default |
---|
[value] | function | String | "Rect" |
ShapeLegend.shapeConfig([config])
If config is specified, sets the methods that correspond to the key/value pairs for each shape and returns the current class instance. If config is not specified, returns the current shape configuration.
Kind: static method of ShapeLegend
Param | Type | Default |
---|
[config] | Object | {} |
ShapeLegend.verticalAlign([value])
If value is specified, sets the vertical alignment to the specified value and returns the current class instance. If value is not specified, returns the current vertical alignment.
Kind: static method of ShapeLegend
Param | Type | Default | Description |
---|
[value] | String | "middle" | Supports "top" and "middle" and "bottom" . |
Documentation generated on Sat, 13 Aug 2016 14:48:17 GMT