d3plus-common
A starter environment for D3plus modules.
Installation Options
NPM
npm install d3plus-common
Browser
In a vanilla environment, a d3plus_common
global is exported. To use a compiled version hosted on d3plus.org that includes all dependencies:
<script src="https://d3plus.org/js/d3plus-common.v0.1.min.js"></script>
Otherwise, click here to download the latest release.
AMD and CommonJS
The released bundle natively supports both AMD and CommonJS, and vanilla environments.
Custom Builds
The source code is written using standard import
and export
statements. Create a custom build using Rollup or your preferred bundler. Take a look at the index.js file to see the modules exported.
API Reference
Functions
- accessor(key)
Wraps an object key in a simple accessor function.
- colorNest(raw, fill, [groupBy])
Returns an Array of data objects based on a given color accessor and groupBy levels.
- constant(value)
Wraps non-function variables in a simple return function.
- 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.
- merge(objects)
Combines an Array of Objects together and returns a new Object.
accessor(key)
Wraps an object key in a simple accessor function.
Kind: global function
Param | Type | Description |
---|
key | String | The key to be returned from each Object passed to the function. |
Example (this)
accessor("id");
Example (returns this)
function(d) {
return d["id"];
}
colorNest(raw, fill, [groupBy])
Returns an Array of data objects based on a given color accessor and groupBy levels.
Kind: global function
Param | Type | Default | Description |
---|
raw | Array | | The raw data Array to be grouped by color. |
fill | function | | The color accessor for each data object. |
[groupBy] | Array | [] | An optional array of grouping accessors. Will autodetect if a certain group by level is assigning the colors, and will return the appropriate accessor. |
constant(value)
Wraps non-function variables in a simple return function.
Kind: global function
Param | Type | Description |
---|
value | Array | Number | Object | String | The value to be returned from the function. |
Example (this)
constant(42);
Example (returns this)
function() {
return 42;
}
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. |
merge(objects)
Combines an Array of Objects together and returns a new Object.
Kind: global function
Param | Type | Description |
---|
objects | Array | The Array of objects to be merged together. |
Example (this)
merge([
{"id": "foo", "group": "A", "value": 10},
{"id": "bar", "group": "A", "value": 20}
]);
Example (returns this)
{"id": ["bar", "foo"], "group": "A", "value": 30}