d3plus-viz
Abstract ES6 class that drives d3plus visualizations.
Installing
If you use NPM, npm install d3plus-viz
. 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-viz.v0.1.full.min.js"></script>
API Reference
Classes
- Viz
Functions
- getSize(elem)
Finds the available width and height for a specified HTMLElement, traversing it's parents until it finds something with constrained dimensions. Falls back to the inner dimensions of the browser window if none is found.
Viz
Kind: global class
new Viz()
Creates an x/y plot based on an array of data. If data is specified, immediately draws the tree map 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. See this example for help getting started using the treemap generator.
Viz.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.
Kind: static method of Viz
Param | Type | Default |
---|
[data] | Array | [] |
Viz.depth([value])
If value is specified, sets the depth to the specified number and returns the current class instance. The value should correspond with an index in the groupBy array. If value is not specified, returns the current depth.
Kind: static method of Viz
Viz.duration([ms])
If ms is specified, sets the animation duration to the specified number and returns the current class instance. If ms is not specified, returns the current animation duration.
Kind: static method of Viz
Param | Type | Default |
---|
[ms] | Number | 600 |
Viz.filter([value])
If value is specified, sets the filter to the specified function and returns the current class instance. If value is not specified, returns the current filter.
Kind: static method of Viz
Viz.groupBy([value])
If value is specified, sets the group accessor(s) to the specified string, function, or array of values and returns the current class instance. If value is not specified, returns the current group accessor.
Kind: static method of Viz
Param | Type |
---|
[value] | String | function | Array |
Example
function value(d) {
return d.id;
}
Viz.height([value])
If value is specified, sets the overallheight to the specified number and returns the current class instance. If value is not specified, returns the current overall height.
Kind: static method of Viz
Param | Type | Default |
---|
[value] | Number | window.innerHeight |
Viz.highlight([value])
If value is specified, sets the highlight filter to the specified function and returns the current class instance. If value is not specified, returns the current highlight filter. When the highlight function returns true given a data point, the highlight styles will be used.
Kind: static method of Viz
Param | Type | Default |
---|
[value] | function | false |
Viz.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 text accessor, which is undefined
by default.
Kind: static method of Viz
Param | Type |
---|
[value] | function | String |
Viz.legend([value])
If value is specified, toggles the legend based on the specified boolean and returns the current class instance. If value is an object, then it is passed to the legend's config method. If value is not specified, returns the current value.
Kind: static method of Viz
Param | Type | Default |
---|
[value] | Boolean | Object | true |
Viz.on([typenames], [listener])
Adds or removes a listener to each shape for the specified event typenames. If a listener is not specified, returns the currently-assigned listener for the specified event typename. Mirrors the core d3-selection behavior.
Kind: static method of Viz
Param | Type |
---|
[typenames] | String |
[listener] | function |
Example (By default, listeners apply to both the shapes and the legend. Passing a namespace with the typename gives control over specific elements:)
new Plot
.on("click.shape", function(d) {
console.log("data for shape clicked:", d);
})
.on("click.legend", function(d) {
console.log("data for legend clicked:", d);
})
Viz.select([selector])
If selector is specified, sets the SVG container element to the specified d3 selector or DOM element and returns the current class instance. If selector is not specified, returns the current SVG container element, which is undefined
by default.
Kind: static method of Viz
Param | Type |
---|
[selector] | String | HTMLElement |
Viz.shape([value])
If value is specified, sets the shape accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current shape accessor.
Kind: static method of Viz
Param | Type |
---|
[value] | function | String |
Viz.shapeConfig([value])
If value is specified, sets the config method for each shape and returns the current class instance. If value is not specified, returns the current shape configuration.
Kind: static method of Viz
Viz.tooltip([value])
If value is specified, toggles the tooltip based on the specified boolean and returns the current class instance. If value is an object, then it is passed to the tooltip's config method. If value is not specified, returns the current tooltip visibility.
Kind: static method of Viz
Param | Type | Default |
---|
[value] | Boolean | Object | true |
Viz.update([ms])
If ms is specified, all shapes will redraw using the specified duration and return this generator. If ms is not specified, shapes will redraw instantly. This method is useful when only needing to change visual styles (and not data), like when setting custom mouse events.
Kind: static method of Viz
Param | Type | Default |
---|
[ms] | Number | 0 |
Viz.width([value])
If value is specified, sets the overallwidth to the specified number and returns the current class instance. If value is not specified, returns the current overall width.
Kind: static method of Viz
Param | Type | Default |
---|
[value] | Number | window.innerWidth |
getSize(elem)
Finds the available width and height for a specified HTMLElement, traversing it's parents until it finds something with constrained dimensions. Falls back to the inner dimensions of the browser window if none is found.
Kind: global function
Param | Type | Description |
---|
elem | HTMLElement | The HTMLElement to find dimensions for. |
Documentation generated on Fri, 19 Aug 2016 02:02:13 GMT