Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@d3fc/d3fc-extent

Package Overview
Dependencies
Maintainers
3
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@d3fc/d3fc-extent - npm Package Compare versions

Comparing version 3.0.5 to 3.1.0

src/time.js

5

build/d3fc-extent.js

@@ -136,3 +136,3 @@ (function (global, factory) {

var date = function () {
var time = function () {

@@ -212,3 +212,4 @@ var accessors = [];

exports.extentLinear = linearExtent;
exports.extentDate = date;
exports.extentTime = time;
exports.extentDate = time;

@@ -215,0 +216,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

2

build/d3fc-extent.min.js

@@ -1,1 +0,1 @@

!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-array")):"function"==typeof define&&define.amd?define(["exports","d3-array"],t):t(n.fc=n.fc||{},n.d3)}(this,function(n,t){"use strict";var r=function(n){if(Array.isArray(n)){for(var t=0,r=Array(n.length);t<n.length;t++)r[t]=n[t];return r}return Array.from(n)},e=function(){var n=[function(n){return n}],e=[0,0],u="percent",a=null,i=[],o=function(o){var l=new Array(o.length),c=!0,f=!1,d=void 0;try{for(var h,v=n[Symbol.iterator]();!(c=(h=v.next()).done);c=!0)for(var s=h.value,p=0;p<o.length;p++){var y=s(o[p],p);Array.isArray(y)?l.push.apply(l,r(y)):l.push(y)}}catch(n){f=!0,d=n}finally{try{!c&&v.return&&v.return()}finally{if(f)throw d}}var g=[t.min(l),t.max(l)];if(g[0]=null==g[0]?t.min(i):t.min([g[0]].concat(r(i))),g[1]=null==g[1]?t.max(i):t.max([g[1]].concat(r(i))),null!=a){var m=Math.max(Math.abs(g[1]-a),Math.abs(g[0]-a));g[0]=a-m,g[1]=a+m}switch(u){case"domain":g[0]-=e[0],g[1]+=e[1];break;case"percent":var A=g[1]-g[0];g[0]-=e[0]*A,g[1]+=e[1]*A;break;default:throw new Error("Unknown padUnit: "+u)}return g};return o.accessors=function(){return arguments.length?(n=arguments.length<=0?void 0:arguments[0],o):n},o.pad=function(){return arguments.length?(e=arguments.length<=0?void 0:arguments[0],o):e},o.padUnit=function(){return arguments.length?(u=arguments.length<=0?void 0:arguments[0],o):u},o.include=function(){return arguments.length?(i=arguments.length<=0?void 0:arguments[0],o):i},o.symmetricalAbout=function(){return arguments.length?(a=arguments.length<=0?void 0:arguments[0],o):a},o},u=function(){var n=[],t=[0,0],r="percent",u=null,a=[],i=e(),o=function(n){return null!=n?n.valueOf():null},l=function(e){var l=n.map(function(n){return function(){var t=n.apply(void 0,arguments);return Array.isArray(t)?t.map(o):o(t)}});return i.accessors(l).pad(t).padUnit(r).symmetricalAbout(null!=u?u.valueOf():null).include(a.map(function(n){return n.valueOf()})),i(e).map(function(n){return new Date(n)})};return l.accessors=function(){return arguments.length?(n=arguments.length<=0?void 0:arguments[0],l):n},l.pad=function(){return arguments.length?(t=arguments.length<=0?void 0:arguments[0],l):t},l.padUnit=function(){return arguments.length?(r=arguments.length<=0?void 0:arguments[0],l):r},l.include=function(){return arguments.length?(a=arguments.length<=0?void 0:arguments[0],l):a},l.symmetricalAbout=function(){return arguments.length?(u=arguments.length<=0?void 0:arguments[0],l):u},l};n.extentLinear=e,n.extentDate=u,Object.defineProperty(n,"__esModule",{value:!0})});
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-array")):"function"==typeof define&&define.amd?define(["exports","d3-array"],t):t(n.fc=n.fc||{},n.d3)}(this,function(n,t){"use strict";var r=function(n){if(Array.isArray(n)){for(var t=0,r=Array(n.length);t<n.length;t++)r[t]=n[t];return r}return Array.from(n)},e=function(){var n=[function(n){return n}],e=[0,0],u="percent",a=null,i=[],o=function(o){var l=new Array(o.length),c=!0,f=!1,d=void 0;try{for(var h,v=n[Symbol.iterator]();!(c=(h=v.next()).done);c=!0)for(var s=h.value,p=0;p<o.length;p++){var y=s(o[p],p);Array.isArray(y)?l.push.apply(l,r(y)):l.push(y)}}catch(n){f=!0,d=n}finally{try{!c&&v.return&&v.return()}finally{if(f)throw d}}var g=[t.min(l),t.max(l)];if(g[0]=null==g[0]?t.min(i):t.min([g[0]].concat(r(i))),g[1]=null==g[1]?t.max(i):t.max([g[1]].concat(r(i))),null!=a){var m=Math.max(Math.abs(g[1]-a),Math.abs(g[0]-a));g[0]=a-m,g[1]=a+m}switch(u){case"domain":g[0]-=e[0],g[1]+=e[1];break;case"percent":var A=g[1]-g[0];g[0]-=e[0]*A,g[1]+=e[1]*A;break;default:throw new Error("Unknown padUnit: "+u)}return g};return o.accessors=function(){return arguments.length?(n=arguments.length<=0?void 0:arguments[0],o):n},o.pad=function(){return arguments.length?(e=arguments.length<=0?void 0:arguments[0],o):e},o.padUnit=function(){return arguments.length?(u=arguments.length<=0?void 0:arguments[0],o):u},o.include=function(){return arguments.length?(i=arguments.length<=0?void 0:arguments[0],o):i},o.symmetricalAbout=function(){return arguments.length?(a=arguments.length<=0?void 0:arguments[0],o):a},o},u=function(){var n=[],t=[0,0],r="percent",u=null,a=[],i=e(),o=function(n){return null!=n?n.valueOf():null},l=function(e){var l=n.map(function(n){return function(){var t=n.apply(void 0,arguments);return Array.isArray(t)?t.map(o):o(t)}});return i.accessors(l).pad(t).padUnit(r).symmetricalAbout(null!=u?u.valueOf():null).include(a.map(function(n){return n.valueOf()})),i(e).map(function(n){return new Date(n)})};return l.accessors=function(){return arguments.length?(n=arguments.length<=0?void 0:arguments[0],l):n},l.pad=function(){return arguments.length?(t=arguments.length<=0?void 0:arguments[0],l):t},l.padUnit=function(){return arguments.length?(r=arguments.length<=0?void 0:arguments[0],l):r},l.include=function(){return arguments.length?(a=arguments.length<=0?void 0:arguments[0],l):a},l.symmetricalAbout=function(){return arguments.length?(u=arguments.length<=0?void 0:arguments[0],l):u},l};n.extentLinear=e,n.extentTime=u,n.extentDate=u,Object.defineProperty(n,"__esModule",{value:!0})});

@@ -6,2 +6,13 @@ # Change Log

<a name="3.1.0"></a>
# [3.1.0](https://github.com/d3fc/d3fc/compare/@d3fc/d3fc-extent@3.0.5...@d3fc/d3fc-extent@3.1.0) (2018-08-22)
### Features
* rename dateExtent to timeExtent to match d3 ([3dd84ed](https://github.com/d3fc/d3fc/commit/3dd84ed)), closes [#1111](https://github.com/d3fc/d3fc/issues/1111)
<a name="3.0.5"></a>

@@ -8,0 +19,0 @@ ## [3.0.5](https://github.com/d3fc/d3fc/compare/@d3fc/d3fc-extent@3.0.4...@d3fc/d3fc-extent@3.0.5) (2018-08-21)

export { default as extentLinear } from './src/linear';
export { default as extentTime } from './src/time';
export { default as extentDate } from './src/date';
{
"name": "@d3fc/d3fc-extent",
"version": "3.0.5",
"version": "3.1.0",
"description": "Extends the d3 extent functionality to allow multiple accessors, padding and date support",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -16,2 +16,3 @@ # d3fc-extent

* [Linear](#linear)
* [Time](#time)
* [Date](#date)

@@ -73,3 +74,3 @@

### Date
### Time

@@ -80,7 +81,7 @@ 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](#linear) but for `Date` values.

import extentDate from 'd3fc-extent';
import extentTime from 'd3fc-extent';
const data = [{ x: new Date(2016, 0, 1) }, { x: new Date(2016, 0, 11) }];
const extent = extentDate()
const extent = extentTime()
.accessors([d => d.x])

@@ -95,7 +96,7 @@ .pad([0, 0.2]);

<a name="date_padUnit" href="#date"></a> fc.**extentDate**()
<a name="time_padUnit" href="#time"></a> fc.**extentTime**()
Constructs a new date extent calculator.
Constructs a new time extent calculator.
<a name="date_accessors" href="#date_accessors"></a> *date*.**accessors**([*accessors*])
<a name="time_accessors" href="#time_accessors"></a> *time*.**accessors**([*accessors*])

@@ -105,10 +106,10 @@ 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 `Date`s. Defaults to an identity function (i.e. `d => d`).

<a name="date_pad" href="#date_pad"></a> *date*.**pad**([*values*])
<a name="time_pad" href="#time_pad"></a> *time*.**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](#date_padUnit).
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](#time_padUnit).
If *values* is not specified, returns the current array of padding values, which defaults `[0, 0]`.
<a name="date_padUnit" href="#date_padUnit"></a> *date*.**padUnit**([*value*])
<a name="time_padUnit" href="#time_padUnit"></a> *time*.**padUnit**([*value*])
If *value* is specified, sets the unit of the [pad](#date_pad) values applied to minimum and maximum values and returns this extent instance. Possible values are -
If *value* is specified, sets the unit of the [pad](#time_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.

@@ -118,3 +119,3 @@ * 'domain' - the padding values specified in milliseconds are applied directly to the calculated extent.

<a name="date_symmetricalAbout" href="#date_symmetricalAbout"></a> *date*.**symmetricalAbout**([*value*])
<a name="time_symmetricalAbout" href="#time_symmetricalAbout"></a> *time*.**symmetricalAbout**([*value*])

@@ -124,5 +125,9 @@ 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.

<a name="date_include" href="#date_include"></a> *date*.**include**([*values*])
<a name="time_include" href="#time_include"></a> *time*.**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 `[]`.
### Date
**Deprecated - use [time](#time) instead.**

@@ -1,72 +0,1 @@

import { default as linearExtent } from './linear';
export default function() {
let accessors = [];
let pad = [0, 0];
let padUnit = 'percent';
let symmetricalAbout = null;
let include = [];
const extent = linearExtent();
const valueOf = date => date != null ? date.valueOf() : null;
const instance = (data) => {
const adaptedAccessors = accessors.map(accessor => (...args) => {
const value = accessor(...args);
return Array.isArray(value) ? value.map(valueOf) : valueOf(value);
});
extent.accessors(adaptedAccessors)
.pad(pad)
.padUnit(padUnit)
.symmetricalAbout(symmetricalAbout != null ? symmetricalAbout.valueOf() : null)
.include(include.map(date => date.valueOf()));
return extent(data)
.map(value => new Date(value));
};
instance.accessors = (...args) => {
if (!args.length) {
return accessors;
}
accessors = args[0];
return instance;
};
instance.pad = (...args) => {
if (!args.length) {
return pad;
}
pad = args[0];
return instance;
};
instance.padUnit = (...args) => {
if (!args.length) {
return padUnit;
}
padUnit = args[0];
return instance;
};
instance.include = (...args) => {
if (!args.length) {
return include;
}
include = args[0];
return instance;
};
instance.symmetricalAbout = (...args) => {
if (!args.length) {
return symmetricalAbout;
}
symmetricalAbout = args[0];
return instance;
};
return instance;
}
export { default } from './time';
import dateExtent from '../src/date';
import ms from 'ms';
describe('linear', () => {
describe('date', () => {
it('should pad dates with domain padding', function() {

@@ -6,0 +6,0 @@ var date1 = new Date(2014, 0, 10);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc