JSPM

  • Created
  • Published
  • Downloads 2921
  • Score
    100M100P100Q9359F
  • License MIT

Common functions and methods used across D3plus modules.

Package Exports

  • d3plus-common

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (d3plus-common) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

d3plus-common

NPM Release Build Status Dependency Status Slack

Common functions and methods used across D3plus modules.

Installing

If you use NPM, npm install d3plus-common. 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-common.v0.5.full.min.js"></script>

API Reference

Classes

BaseClass

Functions

accessor(key, [def])

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.

stylize(elem, styles)

Applies each key/value in an object as a style.

BaseClass

Kind: global class

new BaseClass()

An abstract class that contains some global methods and functionality.

BaseClass.config([value])

If value is specified, sets the methods that correspond to the key/value pairs and returns this class. If value is not specified, returns the current configuration.

Kind: static method of BaseClass

Param Type
[value] Object

accessor(key, [def])

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.
[def] * A default value to be returned if the key is not present.

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}

stylize(elem, styles)

Applies each key/value in an object as a style.

Kind: global function

Param Type Description
elem D3selection The D3 element to apply the styles to.
styles Object An object of key/value style pairs.
Documentation generated on Thu, 04 Aug 2016 21:33:14 GMT