d3plus-common
Common functions and methods used across D3plus modules.
Last updated a month ago by davelandry .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install d3plus-common 
SYNC missed versions from official npm registry.

d3plus-common

NPM Release Build Status Dependency Status Gitter 1.0 progress

Common functions and methods used across D3plus modules.

Installing

If you use NPM, run npm install d3plus-common --save. Otherwise, download the latest release. The released bundle supports AMD, CommonJS, and vanilla environments. You can also load directly from d3plus.org:

<script src="https://d3plus.org/js/d3plus-common.v0.6.full.min.js"></script>

API Reference

  • BaseClass - An abstract class that contains some global methods and functionality.
  • accessor - Wraps an object key in a simple accessor function.
  • assign - A deeply recursive version of Object.assign.
  • attrize - Applies each key/value in an object as an attr.
  • closest - Finds the closest numeric value in an array.
  • configPrep - Preps a config object for d3plus data, and optionally bubbles up a specific nested type. When using this function, you must bind a d3plus class' this context.
  • constant - Wraps non-function variables in a simple return function.
  • elem - Manages the enter/update/exit pattern for a single DOM element.
  • isObject - Detects if a variable is a javascript Object.
  • merge - Combines an Array of Objects together and returns a new Object.
  • parseSides - Converts a string of directional CSS shorthand values into an object with the values expanded.
  • prefix - Returns the appropriate CSS vendor prefix, given the current browser.
  • stylize - Applies each key/value in an object as a style.
  • unique - ES5 implementation to reduce an Array of values to unique instances.
  • uuid - Returns a unique identifier.
  • RESET - String constant used to reset an individual config property.

BaseClass <>

This is a global class.

# 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.

This is a static method of BaseClass, and is chainable with other methods of this Class.

# BaseClass.locale([value]) <>

Sets the locale used for all text and number formatting. This method supports the locales defined in d3plus-format. The locale can be defined as a complex Object (like in d3plus-format), a locale code (like "en-US"), or a 2-digit language code (like "en"). If a 2-digit code is provided, the "findLocale" function is used to identify the most approximate locale from d3plus-format.

This is a static method of BaseClass, and is chainable with other methods of this Class.

{
        separator: "",
        suffixes: ["y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "B", "t", "q", "Q", "Z", "Y"],
        grouping: [3],
        delimiters: {
          thousands: ",",
          decimal: "."
        },
        currency: ["$", ""]
      }

# BaseClass.on([typenames], [listener]) <>

Adds or removes a listener to each object 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.

This is a static method of BaseClass, and is chainable with other methods of this Class.

Param Type
[typenames] String
[listener] function

By default, listeners apply globally to all objects, however, passing a namespace with the class name 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);
  })

# BaseClass.translate([value]) <>

Defines how informational text strings should be displayed. By default, this function will try to find the string in question (which is the first argument provided to this function) inside of an internally managed translation Object. If you'd like to override to use custom text, simply pass this method your own custom formatting function.

This is a static method of BaseClass, and is chainable with other methods of this Class. For example, if we wanted to only change the string "Back" and allow all other string to return in English:

.translate(function(d) {
  return d === "Back" ? "Get outta here" : d;
})

d3plus.accessor(key, [def]) <>

Wraps an object key in a simple accessor function.

This is a 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.

this

accessor("id");
    

returns this

function(d) {
  return d["id"];
}

d3plus.assign(...objects) <>

A deeply recursive version of Object.assign.

This is a global function. this

assign({id: "foo", deep: {group: "A"}}, {id: "bar", deep: {value: 20}}));
    

returns this

{id: "bar", deep: {group: "A", value: 20}}

d3plus.attrize(elem, attrs) <>

Applies each key/value in an object as an attr.

This is a global function.

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

d3plus.closest(n, arr) <>

Finds the closest numeric value in an array.

This is a global function.

Param Type Description
n Number The number value to use when searching the array.
arr Array The array of values to test against.

d3plus.configPrep([config], [type], [nest]) <>

Preps a config object for d3plus data, and optionally bubbles up a specific nested type. When using this function, you must bind a d3plus class' this context.

This is a global function.

Param Type Default Description
[config] Object this._shapeConfig The configuration object to parse.
[type] String "shape" The event classifier to user for "on" events. For example, the default event type of "shape" will apply all events in the "on" config object with that key, like "click.shape" and "mouseleave.shape", in addition to any gloval events like "click" and "mouseleave".
[nest] String An optional nested key to bubble up to the parent config level.

d3plus.constant(value) <>

Wraps non-function variables in a simple return function.

This is a global function. this

constant(42);
    

returns this

function() {
  return 42;
}

d3plus.elem(selector, params) <>

Manages the enter/update/exit pattern for a single DOM element.

This is a global function.

Param Type Default Description
selector String A D3 selector, which must include the tagname and a class and/or ID.
params Object Additional parameters.
[params.condition] Boolean true Whether or not the element should be rendered (or removed).
[params.enter] Object {} A collection of key/value pairs that map to attributes to be given on enter.
[params.exit] Object {} A collection of key/value pairs that map to attributes to be given on exit.
[params.parent] D3Selection d3.select("body") The parent element for this new element to be appended to.
[params.transition] D3Transition d3.transition().duration(0) The transition to use when animated the different life cycle stages.
[params.update] Object {} A collection of key/value pairs that map to attributes to be given on update.

d3plus.isObject(item) <>

Detects if a variable is a javascript Object.

This is a global function.


d3plus.merge(objects, aggs) <>

Combines an Array of Objects together and returns a new Object.

This is a global function.

Param Type Description
objects Array The Array of objects to be merged together.
aggs Object An object containing specific aggregation methods (functions) for each key type. By default, numbers are summed and strings are returned as an array of unique values.

this

merge([
  {id: "foo", group: "A", value: 10, links: [1, 2]},
  {id: "bar", group: "A", value: 20, links: [1, 3]}
]);
    

returns this

{id: ["bar", "foo"], group: "A", value: 30, links: [1, 2, 3]}

d3plus.parseSides(sides) <>

Converts a string of directional CSS shorthand values into an object with the values expanded.

This is a global function.


d3plus.prefix() <>

Returns the appropriate CSS vendor prefix, given the current browser.

This is a global function.


d3plus.stylize(elem, styles) <>

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

This is a global function.

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

d3plus.unique(objects) <>

ES5 implementation to reduce an Array of values to unique instances.

This is a global function. this

unique(["apple", "banana", "apple"]);
    

returns this

["apple", "banana"]

d3plus.uuid() <>

This is a global function.


RESET <>

String constant used to reset an individual config property.

This is a global constant.


Documentation generated on Thu, 22 Aug 2019 19:21:19 GMT

Current Tags

  • 0.6.57                                ...           latest (a month ago)

97 Versions

  • 0.6.57                                ...           a month ago
  • 0.6.56                                ...           a month ago
  • 0.6.55                                ...           a month ago
  • 0.6.54                                ...           2 months ago
  • 0.6.53                                ...           2 months ago
  • 0.6.52                                ...           2 months ago
  • 0.6.51                                ...           2 months ago
  • 0.6.50                                ...           3 months ago
  • 0.6.49                                ...           4 months ago
  • 0.6.48                                ...           4 months ago
  • 0.6.47                                ...           4 months ago
  • 0.6.46                                ...           4 months ago
  • 0.6.45                                ...           7 months ago
  • 0.6.44                                ...           10 months ago
  • 0.6.43                                ...           a year ago
  • 0.6.42                                ...           a year ago
  • 0.6.41                                ...           a year ago
  • 0.6.40                                ...           a year ago
  • 0.6.39                                ...           a year ago
  • 0.6.38                                ...           a year ago
  • 0.6.37                                ...           a year ago
  • 0.6.36                                ...           a year ago
  • 0.6.35                                ...           a year ago
  • 0.6.34                                ...           a year ago
  • 0.6.33                                ...           2 years ago
  • 0.6.32                                ...           2 years ago
  • 0.6.31                                ...           2 years ago
  • 0.6.30                                ...           2 years ago
  • 0.6.29                                ...           2 years ago
  • 0.6.28                                ...           2 years ago
  • 0.6.27                                ...           2 years ago
  • 0.6.26                                ...           2 years ago
  • 0.6.25                                ...           2 years ago
  • 0.6.24                                ...           2 years ago
  • 0.6.23                                ...           2 years ago
  • 0.6.22                                ...           2 years ago
  • 0.6.21                                ...           2 years ago
  • 0.6.20                                ...           2 years ago
  • 0.6.19                                ...           2 years ago
  • 0.6.18                                ...           2 years ago
  • 0.6.17                                ...           2 years ago
  • 0.6.16                                ...           2 years ago
  • 0.6.15                                ...           3 years ago
  • 0.6.14                                ...           3 years ago
  • 0.6.13                                ...           3 years ago
  • 0.6.12                                ...           3 years ago
  • 0.6.11                                ...           3 years ago
  • 0.6.10                                ...           3 years ago
  • 0.6.9                                ...           3 years ago
  • 0.6.8                                ...           3 years ago
  • 0.6.7                                ...           3 years ago
  • 0.6.6                                ...           3 years ago
  • 0.6.5                                ...           3 years ago
  • 0.6.4                                ...           3 years ago
  • 0.6.3                                ...           3 years ago
  • 0.6.2                                ...           3 years ago
  • 0.6.1                                ...           3 years ago
  • 0.6.0                                ...           3 years ago
  • 0.5.25                                ...           3 years ago
  • 0.5.24                                ...           3 years ago
  • 0.5.23                                ...           3 years ago
  • 0.5.22                                ...           3 years ago
  • 0.5.21                                ...           3 years ago
  • 0.5.20                                ...           3 years ago
  • 0.5.19                                ...           3 years ago
  • 0.5.18                                ...           3 years ago
  • 0.5.17                                ...           3 years ago
  • 0.5.16                                ...           3 years ago
  • 0.5.15                                ...           3 years ago
  • 0.5.14                                ...           3 years ago
  • 0.5.13                                ...           3 years ago
  • 0.5.12                                ...           3 years ago
  • 0.5.11                                ...           3 years ago
  • 0.5.10                                ...           3 years ago
  • 0.5.9                                ...           3 years ago
  • 0.5.8                                ...           3 years ago
  • 0.5.7                                ...           3 years ago
  • 0.5.6                                ...           3 years ago
  • 0.5.5                                ...           3 years ago
  • 0.5.4                                ...           3 years ago
  • 0.5.3                                ...           3 years ago
  • 0.5.2                                ...           3 years ago
  • 0.5.1                                ...           3 years ago
  • 0.5.0                                ...           3 years ago
  • 0.4.2                                ...           3 years ago
  • 0.4.1                                ...           3 years ago
  • 0.4.0                                ...           3 years ago
  • 0.3.7                                ...           3 years ago
  • 0.3.6                                ...           3 years ago
  • 0.3.5                                ...           3 years ago
  • 0.3.4                                ...           3 years ago
  • 0.3.3                                ...           3 years ago
  • 0.3.2                                ...           3 years ago
  • 0.3.1                                ...           3 years ago
  • 0.3.0                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.0                                ...           3 years ago

Copyright 2014 - 2016 © taobao.org |