JSPM

  • Created
  • Published
  • Downloads 2868
  • Score
    100M100P100Q9340F
  • 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

Common functions and methods used across D3plus modules.

Installation Options

NPM

npm install d3plus-common

Browser

In a vanilla environment, a d3plus 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.4.full.min.js"></script>

Otherwise, click here to download the latest release.

AMD and CommonJS

The released bundle natively supports both AMD and CommonJS, in addition to 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, [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(The, An)

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

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(The, An)

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

Kind: global function

Param Type Description
The D3selection D3 element to apply the styles to.
An Object object of key/value style pairs.