Giter Site home page Giter Site logo

chrisprice / d3fc-extent Goto Github PK

View Code? Open in Web Editor NEW

This project forked from colineberhardt/d3fc-extent

0.0 1.0 0.0 15 KB

Extends the D3 extent functionality to allow padding, multiple accessors and date support

License: MIT License

JavaScript 100.00%

d3fc-extent's Introduction

d3fc-extent

Extends the D3 extent functionality (found in d3-array) to allow padding, multiple accessors and date support

Main d3fc package

Installation

npm install d3fc-extent

Linear

Calculates the extent of an array of data which can be used to set the range on a scale. Can also optionally pad the data in various ways as described below. Internally makes use of d3-array's min and max methods.

Example usage

import extentLinear from 'd3fc-extent';

const data = [{ x: 1 }, { x: 2 }, { x: 4 }, { x: 8 }, { x: 16 }];

const extent = extentLinear()
  .accessors([d => d.x])
  .pad([1, 4])
  .padUnit('domain');

extent(data);

// [0, 20]

API

fc.extentLinear()

Constructs a new linear extent calculator.

linear.accessors([accessors])

If accessors is specified, sets the array of value accessors to the specified array and returns this extent instance. The accessors are applied to each data value before computing the extent. The value returned be the accessors must be a scalar value or an array of scalar values. Defaults to an identity function (i.e. d => d). If accessors is not specified, returns the current array of value accessors, which defaults [].

linear.pad([values])

If values is specified, sets the amount of padding applied to the minimum and maximum values of the extent, to the specified array [minPad, maxPad] and returns this extent instance. The unit of these values is set by padUnit. If values is not specified, returns the current array of padding values, which defaults [0, 0].

linear.padUnit([value])

If value is specified, sets the unit of the pad values applied to minimum and maximum values and returns this extent instance. Possible values are -

  • 'percent' - the default behavior of applying the values as a percentage of the extent e.g. pad values of [0.5, 0.5] would double the calculated extent.
  • 'domain' - the padding values specified are applied directly to the calculated extent. If value is not specified, returns the current array of padding unit, which defaults percent.

linear.symmetricalAbout([value])

If value is specified, sets the value around which the extent will be centered around and returns this extent instance. Can also be set to null to disable centering. Note this is applied before padding. If value is not specified, returns the current center value, which defaults null.

linear.include([values])

If values is specified, sets the array of additional values to include within the calculated extent to the specified array and returns this extent instance. This allows for always including an origin (e.g. [0]) or specifying a minimum extent to always be displayed (e.g. [10, 20]). Note included values are applied before symmetricalAbout. If values is not specified, returns the current array of included values, which defaults [].

Date

Calculates the extent of an array of data which can be used to set the range on a scale. Can also optionally pad the data in various ways as described below. Equivalent in functionality to linear but for Date values.

Example usage

import extentDate from 'd3fc-extent';

const data = [{ x: new Date(2016, 0, 1) }, { x: new Date(2016, 0, 11) }];

const extent = extentDate()
  .accessors([d => d.x])
  .pad([0, 0.2]);

extent(data);

// [ 2016-01-01T00:00:00.000Z, 2016-01-13T00:00:00.000Z ]

API

fc.extentDate()

Constructs a new date extent calculator.

date.accessors([accessors])

If accessors is specified, sets the array of value accessors to the specified array and returns this extent instance. The accessors are applied to each data value before computing the extent. The value returned be the accessors must be a Date or an array of Dates. Defaults to an identity function (i.e. d => d). If accessors is not specified, returns the current array of value accessors, which defaults [].

date.pad([values])

If values is specified, sets the amount of padding applied to the minimum and maximum values of the extent, to the specified array [minPad, maxPad] and returns this extent instance. The unit of these values is set by padUnit. If values is not specified, returns the current array of padding values, which defaults [0, 0].

date.padUnit([value])

If value is specified, sets the unit of the pad values applied to minimum and maximum values and returns this extent instance. Possible values are -

  • 'percent' - the default behavior of applying the values as a percentage of the extent e.g. pad values of [0.5, 0.5] would double the calculated extent.
  • 'domain' - the padding values specified in milliseconds are applied directly to the calculated extent. If value is not specified, returns the current array of padding unit, which defaults percent.

date.symmetricalAbout([value])

If value is specified, sets the value around which the extent will be centered around and returns this extent instance. Can also be set to null to disable centering. Note this is applied before padding. If value is not specified, returns the current center value, which defaults null.

date.include([values])

If values is specified, sets the array of additional values to include within the calculated extent to the specified array and returns this extent instance. If values is not specified, returns the current array of included values, which defaults [].

d3fc-extent's People

Contributors

chrisprice avatar colineberhardt avatar greenkeeperio-bot avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.