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

@nivo/scales

Package Overview
Dependencies
Maintainers
2
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nivo/scales - npm Package Compare versions

Comparing version 0.74.0 to 0.75.0

746

dist/nivo-scales.cjs.js

@@ -1,746 +0,2 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var uniq = _interopDefault(require('lodash/uniq'));
var uniqBy = _interopDefault(require('lodash/uniqBy'));
var sortBy = _interopDefault(require('lodash/sortBy'));
var last = _interopDefault(require('lodash/last'));
var isDate = _interopDefault(require('lodash/isDate'));
var d3TimeFormat = require('d3-time-format');
var d3Scale = require('d3-scale');
var d3Time = require('d3-time');
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) {
arr2[i] = arr[i];
}
return arr2;
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
}
return target;
}
var timePrecisions = ['millisecond', 'second', 'minute', 'hour', 'day', 'month', 'year'];
var precisionCutOffs = [function (date) {
return date.setMilliseconds(0);
}, function (date) {
return date.setSeconds(0);
}, function (date) {
return date.setMinutes(0);
}, function (date) {
return date.setHours(0);
}, function (date) {
return date.setDate(1);
}, function (date) {
return date.setMonth(0);
}];
var precisionCutOffsByType = {
millisecond: [],
second: precisionCutOffs.slice(0, 1),
minute: precisionCutOffs.slice(0, 2),
hour: precisionCutOffs.slice(0, 3),
day: precisionCutOffs.slice(0, 4),
month: precisionCutOffs.slice(0, 5),
year: precisionCutOffs.slice(0, 6)
};
var createPrecisionMethod = function createPrecisionMethod(precision) {
return function (date) {
precisionCutOffsByType[precision].forEach(function (cutOff) {
cutOff(date);
});
return date;
};
};
var createDateNormalizer = function createDateNormalizer(_ref) {
var _ref$format = _ref.format,
format = _ref$format === void 0 ? 'native' : _ref$format,
_ref$precision = _ref.precision,
precision = _ref$precision === void 0 ? 'millisecond' : _ref$precision,
_ref$useUTC = _ref.useUTC,
useUTC = _ref$useUTC === void 0 ? true : _ref$useUTC;
var precisionFn = createPrecisionMethod(precision);
return function (value) {
if (value === undefined) {
return value;
}
if (format === 'native' || value instanceof Date) {
return precisionFn(value);
}
var parseTime = useUTC ? d3TimeFormat.utcParse(format) : d3TimeFormat.timeParse(format);
return precisionFn(parseTime(value));
};
};
var createLinearScale = function createLinearScale(_ref, data, size, axis) {
var _ref$min = _ref.min,
min = _ref$min === void 0 ? 0 : _ref$min,
_ref$max = _ref.max,
max = _ref$max === void 0 ? 'auto' : _ref$max,
_ref$stacked = _ref.stacked,
stacked = _ref$stacked === void 0 ? false : _ref$stacked,
_ref$reverse = _ref.reverse,
reverse = _ref$reverse === void 0 ? false : _ref$reverse,
_ref$clamp = _ref.clamp,
clamp = _ref$clamp === void 0 ? false : _ref$clamp,
_ref$nice = _ref.nice,
nice = _ref$nice === void 0 ? false : _ref$nice;
var minValue;
if (min === 'auto') {
var _data$minStacked;
minValue = stacked === true ? (_data$minStacked = data.minStacked) !== null && _data$minStacked !== void 0 ? _data$minStacked : 0 : data.min;
} else {
minValue = min;
}
var maxValue;
if (max === 'auto') {
var _data$maxStacked;
maxValue = stacked === true ? (_data$maxStacked = data.maxStacked) !== null && _data$maxStacked !== void 0 ? _data$maxStacked : 0 : data.max;
} else {
maxValue = max;
}
var scale = d3Scale.scaleLinear().rangeRound(axis === 'x' ? [0, size] : [size, 0]).domain(reverse ? [maxValue, minValue] : [minValue, maxValue]).clamp(clamp);
if (nice === true) scale.nice();else if (typeof nice === 'number') scale.nice(nice);
return castLinearScale(scale, stacked);
};
var castLinearScale = function castLinearScale(scale) {
var stacked = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var typedScale = scale;
typedScale.type = 'linear';
typedScale.stacked = stacked;
return typedScale;
};
var createPointScale = function createPointScale(_spec, data, size) {
var scale = d3Scale.scalePoint().range([0, size]).domain(data.all);
var typedScale = scale;
typedScale.type = 'point';
return typedScale;
};
var createBandScale = function createBandScale(_ref, data, size, axis) {
var _ref$round = _ref.round,
round = _ref$round === void 0 ? true : _ref$round;
var scale = d3Scale.scaleBand().range(axis === 'x' ? [0, size] : [size, 0]).domain(data.all).round(round);
return castBandScale(scale);
};
var castBandScale = function castBandScale(scale) {
var typedScale = scale;
typedScale.type = 'band';
return typedScale;
};
var createTimeScale = function createTimeScale(_ref, data, size) {
var _ref$format = _ref.format,
format = _ref$format === void 0 ? 'native' : _ref$format,
_ref$precision = _ref.precision,
precision = _ref$precision === void 0 ? 'millisecond' : _ref$precision,
_ref$min = _ref.min,
min = _ref$min === void 0 ? 'auto' : _ref$min,
_ref$max = _ref.max,
max = _ref$max === void 0 ? 'auto' : _ref$max,
_ref$useUTC = _ref.useUTC,
useUTC = _ref$useUTC === void 0 ? true : _ref$useUTC,
_ref$nice = _ref.nice,
nice = _ref$nice === void 0 ? false : _ref$nice;
var normalize = createDateNormalizer({
format: format,
precision: precision,
useUTC: useUTC
});
var minValue;
if (min === 'auto') {
minValue = normalize(data.min);
} else if (format !== 'native') {
minValue = normalize(min);
} else {
minValue = min;
}
var maxValue;
if (max === 'auto') {
maxValue = normalize(data.max);
} else if (format !== 'native') {
maxValue = normalize(max);
} else {
maxValue = max;
}
var scale = useUTC ? d3Scale.scaleUtc() : d3Scale.scaleTime();
scale.range([0, size]);
if (minValue && maxValue) scale.domain([minValue, maxValue]);
if (nice === true) scale.nice();else if (typeof nice === 'object' || typeof nice === 'number') scale.nice(nice);
var typedScale = scale;
typedScale.type = 'time';
typedScale.useUTC = useUTC;
return typedScale;
};
var createLogScale = function createLogScale(_ref, data, size, axis) {
var _ref$base = _ref.base,
base = _ref$base === void 0 ? 10 : _ref$base,
_ref$min = _ref.min,
min = _ref$min === void 0 ? 'auto' : _ref$min,
_ref$max = _ref.max,
max = _ref$max === void 0 ? 'auto' : _ref$max;
var hasZero = data.all.some(function (v) {
return v === 0;
});
if (hasZero) {
throw new Error("a log scale domain must not include or cross zero");
}
var sign;
var hasMixedSign = false;
data.all.filter(function (v) {
return v != null;
}).forEach(function (v) {
if (hasMixedSign) return;
if (sign === undefined) {
sign = Math.sign(v);
} else if (Math.sign(v) !== sign) {
hasMixedSign = true;
}
});
if (hasMixedSign) {
throw new Error("a log scale domain must be strictly-positive or strictly-negative");
}
var minValue;
if (min === 'auto') {
minValue = data.min;
} else {
minValue = min;
}
var maxValue;
if (max === 'auto') {
maxValue = data.max;
} else {
maxValue = max;
}
var scale = d3Scale.scaleLog().domain([minValue, maxValue]).rangeRound(axis === 'x' ? [0, size] : [size, 0]).base(base).nice();
var typedScale = scale;
typedScale.type = 'log';
return scale;
};
var createSymlogScale = function createSymlogScale(_ref, data, size, axis) {
var _ref$constant = _ref.constant,
constant = _ref$constant === void 0 ? 1 : _ref$constant,
_ref$min = _ref.min,
min = _ref$min === void 0 ? 'auto' : _ref$min,
_ref$max = _ref.max,
max = _ref$max === void 0 ? 'auto' : _ref$max,
_ref$reverse = _ref.reverse,
reverse = _ref$reverse === void 0 ? false : _ref$reverse;
var minValue;
if (min === 'auto') {
minValue = data.min;
} else {
minValue = min;
}
var maxValue;
if (max === 'auto') {
maxValue = data.max;
} else {
maxValue = max;
}
var scale = d3Scale.scaleSymlog().constant(constant).rangeRound(axis === 'x' ? [0, size] : [size, 0]).nice();
if (reverse === true) scale.domain([maxValue, minValue]);else scale.domain([minValue, maxValue]);
var typedScale = scale;
typedScale.type = 'symlog';
return typedScale;
};
var getOtherAxis = function getOtherAxis(axis) {
return axis === 'x' ? 'y' : 'x';
};
var compareValues = function compareValues(a, b) {
return a === b;
};
var compareDateValues = function compareDateValues(a, b) {
return a.getTime() === b.getTime();
};
function computeScale(spec, data, size, axis) {
switch (spec.type) {
case 'linear':
return createLinearScale(spec, data, size, axis);
case 'point':
return createPointScale(spec, data, size);
case 'band':
return createBandScale(spec, data, size, axis);
case 'time':
return createTimeScale(spec, data, size);
case 'log':
return createLogScale(spec, data, size, axis);
case 'symlog':
return createSymlogScale(spec, data, size, axis);
default:
throw new Error('invalid scale spec');
}
}
var nestSerieData = function nestSerieData(serie) {
return _objectSpread2(_objectSpread2({}, serie), {}, {
data: serie.data.map(function (d) {
return {
data: _objectSpread2({}, d)
};
})
});
};
var getDatumAxisPosition = function getDatumAxisPosition(datum, axis, scale) {
var _scale;
if ('stacked' in scale && scale.stacked) {
var stackedValue = datum.data[axis === 'x' ? 'xStacked' : 'yStacked'];
if (stackedValue === null || stackedValue === undefined) {
return null;
}
return scale(stackedValue);
}
return (_scale = scale(datum.data[axis])) !== null && _scale !== void 0 ? _scale : null;
};
var computeXYScalesForSeries = function computeXYScalesForSeries(series, xScaleSpec, yScaleSpec, width, height) {
var nestedSeries = series.map(function (serie) {
return nestSerieData(serie);
});
var xy = generateSeriesXY(nestedSeries, xScaleSpec, yScaleSpec);
if ('stacked' in xScaleSpec && xScaleSpec.stacked === true) {
stackX(xy, nestedSeries);
}
if ('stacked' in yScaleSpec && yScaleSpec.stacked === true) {
stackY(xy, nestedSeries);
}
var xScale = computeScale(xScaleSpec, xy.x, width, 'x');
var yScale = computeScale(yScaleSpec, xy.y, height, 'y');
var computedSeries = nestedSeries.map(function (serie) {
return _objectSpread2(_objectSpread2({}, serie), {}, {
data: serie.data.map(function (datum) {
return _objectSpread2(_objectSpread2({}, datum), {}, {
position: {
x: getDatumAxisPosition(datum, 'x', xScale),
y: getDatumAxisPosition(datum, 'y', yScale)
}
});
})
});
});
return _objectSpread2(_objectSpread2({}, xy), {}, {
series: computedSeries,
xScale: xScale,
yScale: yScale
});
};
var generateSeriesXY = function generateSeriesXY(series, xScaleSpec, yScaleSpec) {
return {
x: generateSeriesAxis(series, 'x', xScaleSpec),
y: generateSeriesAxis(series, 'y', yScaleSpec)
};
};
var generateSeriesAxis = function generateSeriesAxis(series, axis, scaleSpec) {
var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
_ref$getValue = _ref.getValue,
getValue = _ref$getValue === void 0 ? function (d) {
return d.data[axis];
} : _ref$getValue,
_ref$setValue = _ref.setValue,
setValue = _ref$setValue === void 0 ? function (d, v) {
d.data[axis] = v;
} : _ref$setValue;
if (scaleSpec.type === 'linear') {
series.forEach(function (serie) {
serie.data.forEach(function (d) {
var value = getValue(d);
if (value) {
setValue(d, parseFloat(String(value)));
}
});
});
} else if (scaleSpec.type === 'time' && scaleSpec.format !== 'native') {
var parseTime = createDateNormalizer(scaleSpec);
series.forEach(function (serie) {
serie.data.forEach(function (d) {
var value = getValue(d);
if (value) {
setValue(d, parseTime(value));
}
});
});
}
var values = [];
series.forEach(function (serie) {
serie.data.forEach(function (d) {
values.push(getValue(d));
});
});
switch (scaleSpec.type) {
case 'linear':
{
var all = sortBy(uniq(values).filter(function (v) {
return v !== null;
}), function (v) {
return v;
});
return {
all: all,
min: Math.min.apply(Math, _toConsumableArray(all)),
max: Math.max.apply(Math, _toConsumableArray(all))
};
}
case 'time':
{
var _all = uniqBy(values, function (v) {
return v.getTime();
}).slice(0).sort(function (a, b) {
return b.getTime() - a.getTime();
}).reverse();
return {
all: _all,
min: _all[0],
max: last(_all)
};
}
default:
{
var _all2 = uniq(values);
return {
all: _all2,
min: _all2[0],
max: last(_all2)
};
}
}
};
var stackAxis = function stackAxis(axis, xy, series) {
var otherAxis = getOtherAxis(axis);
var all = [];
xy[otherAxis].all.forEach(function (v) {
var compare = isDate(v) ? compareDateValues : compareValues;
var stack = [];
series.forEach(function (serie) {
var datum = serie.data.find(function (d) {
return compare(d.data[otherAxis], v);
});
var value = null;
var stackValue = null;
if (datum !== undefined) {
value = datum.data[axis];
if (value !== null) {
var head = last(stack);
if (head === undefined) {
stackValue = value;
} else if (head !== null) {
stackValue = head + value;
}
}
datum.data[axis === 'x' ? 'xStacked' : 'yStacked'] = stackValue;
}
stack.push(stackValue);
if (stackValue !== null) {
all.push(stackValue);
}
});
});
xy[axis].minStacked = Math.min.apply(Math, all);
xy[axis].maxStacked = Math.max.apply(Math, all);
};
var stackX = function stackX(xy, series) {
return stackAxis('x', xy, series);
};
var stackY = function stackY(xy, series) {
return stackAxis('y', xy, series);
};
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(arr, i) {
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
var centerScale = function centerScale(scale) {
var bandwidth = scale.bandwidth();
if (bandwidth === 0) return scale;
var offset = bandwidth / 2;
if (scale.round()) {
offset = Math.round(offset);
}
return function (d) {
var _scale;
return ((_scale = scale(d)) !== null && _scale !== void 0 ? _scale : 0) + offset;
};
};
var timeDay = d3Time.timeInterval(function (date) {
return date.setHours(0, 0, 0, 0);
}, function (date, step) {
return date.setDate(date.getDate() + step);
}, function (start, end) {
return (end.getTime() - start.getTime()) / 864e5;
}, function (date) {
return Math.floor(date.getTime() / 864e5);
});
var utcDay = d3Time.timeInterval(function (date) {
return date.setUTCHours(0, 0, 0, 0);
}, function (date, step) {
return date.setUTCDate(date.getUTCDate() + step);
}, function (start, end) {
return (end.getTime() - start.getTime()) / 864e5;
}, function (date) {
return Math.floor(date.getTime() / 864e5);
});
var timeByType = {
millisecond: [d3Time.timeMillisecond, d3Time.utcMillisecond],
second: [d3Time.timeSecond, d3Time.utcSecond],
minute: [d3Time.timeMinute, d3Time.utcMinute],
hour: [d3Time.timeHour, d3Time.utcHour],
day: [timeDay, utcDay],
week: [d3Time.timeWeek, d3Time.utcWeek],
sunday: [d3Time.timeSunday, d3Time.utcSunday],
monday: [d3Time.timeMonday, d3Time.utcMonday],
tuesday: [d3Time.timeTuesday, d3Time.utcTuesday],
wednesday: [d3Time.timeWednesday, d3Time.utcWednesday],
thursday: [d3Time.timeThursday, d3Time.utcThursday],
friday: [d3Time.timeFriday, d3Time.utcFriday],
saturday: [d3Time.timeSaturday, d3Time.utcSaturday],
month: [d3Time.timeMonth, d3Time.utcMonth],
year: [d3Time.timeYear, d3Time.utcYear]
};
var timeTypes = Object.keys(timeByType);
var timeIntervalRegexp = new RegExp("^every\\s*(\\d+)?\\s*(".concat(timeTypes.join('|'), ")s?$"), 'i');
var isInteger = function isInteger(value) {
return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
};
var getScaleTicks = function getScaleTicks(scale, spec) {
if (Array.isArray(spec)) {
return spec;
}
if (typeof spec === 'string' && 'useUTC' in scale) {
var matches = spec.match(timeIntervalRegexp);
if (matches) {
var _matches = _slicedToArray(matches, 3),
amount = _matches[1],
type = _matches[2];
var timeType = timeByType[type][scale.useUTC ? 1 : 0];
if (type === 'day') {
var _timeType$every$range, _timeType$every;
var _scale$domain = scale.domain(),
_scale$domain2 = _slicedToArray(_scale$domain, 2),
start = _scale$domain2[0],
originalStop = _scale$domain2[1];
var stop = new Date(originalStop);
stop.setDate(stop.getDate() + 1);
return (_timeType$every$range = (_timeType$every = timeType.every(Number(amount !== null && amount !== void 0 ? amount : 1))) === null || _timeType$every === void 0 ? void 0 : _timeType$every.range(start, stop)) !== null && _timeType$every$range !== void 0 ? _timeType$every$range : [];
}
if (amount === undefined) {
return scale.ticks(timeType);
}
var interval = timeType.every(Number(amount));
if (interval) {
return scale.ticks(interval);
}
}
throw new Error("Invalid tickValues: ".concat(spec));
}
if ('ticks' in scale) {
if (spec === undefined) {
return scale.ticks();
}
if (isInteger(spec)) {
return scale.ticks(spec);
}
}
return scale.domain();
};
exports.castBandScale = castBandScale;
exports.castLinearScale = castLinearScale;
exports.centerScale = centerScale;
exports.compareDateValues = compareDateValues;
exports.compareValues = compareValues;
exports.computeScale = computeScale;
exports.computeXYScalesForSeries = computeXYScalesForSeries;
exports.createBandScale = createBandScale;
exports.createDateNormalizer = createDateNormalizer;
exports.createLinearScale = createLinearScale;
exports.createLogScale = createLogScale;
exports.createPointScale = createPointScale;
exports.createPrecisionMethod = createPrecisionMethod;
exports.createSymlogScale = createSymlogScale;
exports.createTimeScale = createTimeScale;
exports.generateSeriesAxis = generateSeriesAxis;
exports.generateSeriesXY = generateSeriesXY;
exports.getOtherAxis = getOtherAxis;
exports.getScaleTicks = getScaleTicks;
exports.precisionCutOffs = precisionCutOffs;
exports.precisionCutOffsByType = precisionCutOffsByType;
exports.stackAxis = stackAxis;
exports.timePrecisions = timePrecisions;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("lodash/uniq"),t=require("lodash/uniqBy"),n=require("lodash/sortBy"),r=require("lodash/last"),a=require("lodash/isDate"),i=require("d3-time-format"),o=require("d3-scale"),u=require("d3-time");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=c(e),d=c(t),l=c(n),f=c(r),m=c(a);function v(){return v=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},v.apply(this,arguments)}var p=[function(e){return e.setMilliseconds(0)},function(e){return e.setSeconds(0)},function(e){return e.setMinutes(0)},function(e){return e.setHours(0)},function(e){return e.setDate(1)},function(e){return e.setMonth(0)}],y={millisecond:[],second:p.slice(0,1),minute:p.slice(0,2),hour:p.slice(0,3),day:p.slice(0,4),month:p.slice(0,5),year:p.slice(0,6)},x=function(e){return function(t){return y[e].forEach((function(e){e(t)})),t}},h=function(e){var t=e.format,n=void 0===t?"native":t,r=e.precision,a=void 0===r?"millisecond":r,o=e.useUTC,u=void 0===o||o,c=x(a);return function(e){if(void 0===e)return e;if("native"===n||e instanceof Date)return c(e);var t=u?i.utcParse(n):i.timeParse(n);return c(t(e))}},g=function(e,t,n,r){var a,i,u,c,s=e.min,d=void 0===s?0:s,l=e.max,f=void 0===l?"auto":l,m=e.stacked,v=void 0!==m&&m,p=e.reverse,y=void 0!==p&&p,x=e.clamp,h=void 0!==x&&x,g=e.nice,k=void 0!==g&&g;"auto"===d?a=!0===v?null!=(i=t.minStacked)?i:0:t.min:a=d;"auto"===f?u=!0===v?null!=(c=t.maxStacked)?c:0:t.max:u=f;var T=o.scaleLinear().rangeRound("x"===r?[0,n]:[n,0]).domain(y?[u,a]:[a,u]).clamp(h);return!0===k?T.nice():"number"==typeof k&&T.nice(k),S(T,v)},S=function(e,t){void 0===t&&(t=!1);var n=e;return n.type="linear",n.stacked=t,n},k=function(e,t,n){var r=o.scalePoint().range([0,n]).domain(t.all);return r.type="point",r},T=function(e,t,n,r){var a=e.round,i=void 0===a||a,u=o.scaleBand().range("x"===r?[0,n]:[n,0]).domain(t.all).round(i);return M(u)},M=function(e){var t=e;return t.type="band",t},b=function(e,t,n){var r,a,i=e.format,u=void 0===i?"native":i,c=e.precision,s=void 0===c?"millisecond":c,d=e.min,l=void 0===d?"auto":d,f=e.max,m=void 0===f?"auto":f,v=e.useUTC,p=void 0===v||v,y=e.nice,x=void 0!==y&&y,g=h({format:u,precision:s,useUTC:p});r="auto"===l?g(t.min):"native"!==u?g(l):l,a="auto"===m?g(t.max):"native"!==u?g(m):m;var S=p?o.scaleUtc():o.scaleTime();S.range([0,n]),r&&a&&S.domain([r,a]),!0===x?S.nice():"object"!=typeof x&&"number"!=typeof x||S.nice(x);var k=S;return k.type="time",k.useUTC=p,k},w=function(e,t,n,r){var a,i=e.base,u=void 0===i?10:i,c=e.min,s=void 0===c?"auto":c,d=e.max,l=void 0===d?"auto":d;if(t.all.some((function(e){return 0===e})))throw new Error("a log scale domain must not include or cross zero");var f,m,v=!1;if(t.all.filter((function(e){return null!=e})).forEach((function(e){v||(void 0===a?a=Math.sign(e):Math.sign(e)!==a&&(v=!0))})),v)throw new Error("a log scale domain must be strictly-positive or strictly-negative");f="auto"===s?t.min:s,m="auto"===l?t.max:l;var p=o.scaleLog().domain([f,m]).rangeRound("x"===r?[0,n]:[n,0]).base(u).nice();return p.type="log",p},E=function(e,t,n,r){var a,i,u=e.constant,c=void 0===u?1:u,s=e.min,d=void 0===s?"auto":s,l=e.max,f=void 0===l?"auto":l,m=e.reverse,v=void 0!==m&&m;a="auto"===d?t.min:d,i="auto"===f?t.max:f;var p=o.scaleSymlog().constant(c).rangeRound("x"===r?[0,n]:[n,0]).nice();!0===v?p.domain([i,a]):p.domain([a,i]);var y=p;return y.type="symlog",y},D=function(e){return"x"===e?"y":"x"},C=function(e,t){return e===t},q=function(e,t){return e.getTime()===t.getTime()};function U(e,t,n,r){switch(e.type){case"linear":return g(e,t,n,r);case"point":return k(0,t,n);case"band":return T(e,t,n,r);case"time":return b(e,t,n);case"log":return w(e,t,n,r);case"symlog":return E(e,t,n,r);default:throw new Error("invalid scale spec")}}var O=function(e,t,n){var r;if("stacked"in n&&n.stacked){var a=e.data["x"===t?"xStacked":"yStacked"];return null==a?null:n(a)}return null!=(r=n(e.data[t]))?r:null},P=function(e,t,n){return{x:j(e,"x",t),y:j(e,"y",n)}},j=function(e,t,n,r){var a=void 0===r?{}:r,i=a.getValue,o=void 0===i?function(e){return e.data[t]}:i,u=a.setValue,c=void 0===u?function(e,n){e.data[t]=n}:u;if("linear"===n.type)e.forEach((function(e){e.data.forEach((function(e){var t=o(e);t&&c(e,parseFloat(String(t)))}))}));else if("time"===n.type&&"native"!==n.format){var m=h(n);e.forEach((function(e){e.data.forEach((function(e){var t=o(e);t&&c(e,m(t))}))}))}var v=[];switch(e.forEach((function(e){e.data.forEach((function(e){v.push(o(e))}))})),n.type){case"linear":var p=l.default(s.default(v).filter((function(e){return null!==e})),(function(e){return e}));return{all:p,min:Math.min.apply(Math,p),max:Math.max.apply(Math,p)};case"time":var y=d.default(v,(function(e){return e.getTime()})).slice(0).sort((function(e,t){return t.getTime()-e.getTime()})).reverse();return{all:y,min:y[0],max:f.default(y)};default:var x=s.default(v);return{all:x,min:x[0],max:f.default(x)}}},B=function(e,t,n){var r=D(e),a=[];t[r].all.forEach((function(t){var i=m.default(t)?q:C,o=[];n.forEach((function(n){var u=n.data.find((function(e){return i(e.data[r],t)})),c=null,s=null;if(void 0!==u){if(null!==(c=u.data[e])){var d=f.default(o);void 0===d?s=c:null!==d&&(s=d+c)}u.data["x"===e?"xStacked":"yStacked"]=s}o.push(s),null!==s&&a.push(s)}))})),t[e].minStacked=Math.min.apply(Math,a),t[e].maxStacked=Math.max.apply(Math,a)},A=function(e,t){return B("x",e,t)},F=function(e,t){return B("y",e,t)},H=u.timeInterval((function(e){return e.setHours(0,0,0,0)}),(function(e,t){return e.setDate(e.getDate()+t)}),(function(e,t){return(t.getTime()-e.getTime())/864e5}),(function(e){return Math.floor(e.getTime()/864e5)})),L=u.timeInterval((function(e){return e.setUTCHours(0,0,0,0)}),(function(e,t){return e.setUTCDate(e.getUTCDate()+t)}),(function(e,t){return(t.getTime()-e.getTime())/864e5}),(function(e){return Math.floor(e.getTime()/864e5)})),V={millisecond:[u.timeMillisecond,u.utcMillisecond],second:[u.timeSecond,u.utcSecond],minute:[u.timeMinute,u.utcMinute],hour:[u.timeHour,u.utcHour],day:[H,L],week:[u.timeWeek,u.utcWeek],sunday:[u.timeSunday,u.utcSunday],monday:[u.timeMonday,u.utcMonday],tuesday:[u.timeTuesday,u.utcTuesday],wednesday:[u.timeWednesday,u.utcWednesday],thursday:[u.timeThursday,u.utcThursday],friday:[u.timeFriday,u.utcFriday],saturday:[u.timeSaturday,u.utcSaturday],month:[u.timeMonth,u.utcMonth],year:[u.timeYear,u.utcYear]},R=Object.keys(V),W=new RegExp("^every\\s*(\\d+)?\\s*("+R.join("|")+")s?$","i");exports.castBandScale=M,exports.castLinearScale=S,exports.centerScale=function(e){var t=e.bandwidth();if(0===t)return e;var n=t/2;return e.round()&&(n=Math.round(n)),function(t){var r;return(null!=(r=e(t))?r:0)+n}},exports.compareDateValues=q,exports.compareValues=C,exports.computeScale=U,exports.computeXYScalesForSeries=function(e,t,n,r,a){var i=e.map((function(e){return function(e){return v({},e,{data:e.data.map((function(e){return{data:v({},e)}}))})}(e)})),o=P(i,t,n);"stacked"in t&&!0===t.stacked&&A(o,i),"stacked"in n&&!0===n.stacked&&F(o,i);var u=U(t,o.x,r,"x"),c=U(n,o.y,a,"y"),s=i.map((function(e){return v({},e,{data:e.data.map((function(e){return v({},e,{position:{x:O(e,"x",u),y:O(e,"y",c)}})}))})}));return v({},o,{series:s,xScale:u,yScale:c})},exports.createBandScale=T,exports.createDateNormalizer=h,exports.createLinearScale=g,exports.createLogScale=w,exports.createPointScale=k,exports.createPrecisionMethod=x,exports.createSymlogScale=E,exports.createTimeScale=b,exports.generateSeriesAxis=j,exports.generateSeriesXY=P,exports.getOtherAxis=D,exports.getScaleTicks=function(e,t){if(Array.isArray(t))return t;if("string"==typeof t&&"useUTC"in e){var n=t.match(W);if(n){var r=n[1],a=n[2],i=V[a][e.useUTC?1:0];if("day"===a){var o,u,c=e.domain(),s=c[0],d=c[1],l=new Date(d);return l.setDate(l.getDate()+1),null!=(o=null==(u=i.every(Number(null!=r?r:1)))?void 0:u.range(s,l))?o:[]}if(void 0===r)return e.ticks(i);var f=i.every(Number(r));if(f)return e.ticks(f)}throw new Error("Invalid tickValues: "+t)}if("ticks"in e){if(void 0===t)return e.ticks();if("number"==typeof(m=t)&&isFinite(m)&&Math.floor(m)===m)return e.ticks(t)}var m;return e.domain()},exports.precisionCutOffs=p,exports.precisionCutOffsByType=y,exports.stackAxis=B,exports.timePrecisions=["millisecond","second","minute","hour","day","month","year"];
//# sourceMappingURL=nivo-scales.cjs.js.map

@@ -1,718 +0,2 @@

import uniq from 'lodash/uniq';
import uniqBy from 'lodash/uniqBy';
import sortBy from 'lodash/sortBy';
import last from 'lodash/last';
import isDate from 'lodash/isDate';
import { utcParse, timeParse } from 'd3-time-format';
import { scaleLinear, scalePoint, scaleBand, scaleUtc, scaleTime, scaleLog, scaleSymlog } from 'd3-scale';
import { timeInterval, timeMillisecond, utcMillisecond, timeSecond, utcSecond, timeMinute, utcMinute, timeHour, utcHour, timeWeek, utcWeek, timeSunday, utcSunday, timeMonday, utcMonday, timeTuesday, utcTuesday, timeWednesday, utcWednesday, timeThursday, utcThursday, timeFriday, utcFriday, timeSaturday, utcSaturday, timeMonth, utcMonth, timeYear, utcYear } from 'd3-time';
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) {
arr2[i] = arr[i];
}
return arr2;
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
}
return target;
}
var timePrecisions = ['millisecond', 'second', 'minute', 'hour', 'day', 'month', 'year'];
var precisionCutOffs = [function (date) {
return date.setMilliseconds(0);
}, function (date) {
return date.setSeconds(0);
}, function (date) {
return date.setMinutes(0);
}, function (date) {
return date.setHours(0);
}, function (date) {
return date.setDate(1);
}, function (date) {
return date.setMonth(0);
}];
var precisionCutOffsByType = {
millisecond: [],
second: precisionCutOffs.slice(0, 1),
minute: precisionCutOffs.slice(0, 2),
hour: precisionCutOffs.slice(0, 3),
day: precisionCutOffs.slice(0, 4),
month: precisionCutOffs.slice(0, 5),
year: precisionCutOffs.slice(0, 6)
};
var createPrecisionMethod = function createPrecisionMethod(precision) {
return function (date) {
precisionCutOffsByType[precision].forEach(function (cutOff) {
cutOff(date);
});
return date;
};
};
var createDateNormalizer = function createDateNormalizer(_ref) {
var _ref$format = _ref.format,
format = _ref$format === void 0 ? 'native' : _ref$format,
_ref$precision = _ref.precision,
precision = _ref$precision === void 0 ? 'millisecond' : _ref$precision,
_ref$useUTC = _ref.useUTC,
useUTC = _ref$useUTC === void 0 ? true : _ref$useUTC;
var precisionFn = createPrecisionMethod(precision);
return function (value) {
if (value === undefined) {
return value;
}
if (format === 'native' || value instanceof Date) {
return precisionFn(value);
}
var parseTime = useUTC ? utcParse(format) : timeParse(format);
return precisionFn(parseTime(value));
};
};
var createLinearScale = function createLinearScale(_ref, data, size, axis) {
var _ref$min = _ref.min,
min = _ref$min === void 0 ? 0 : _ref$min,
_ref$max = _ref.max,
max = _ref$max === void 0 ? 'auto' : _ref$max,
_ref$stacked = _ref.stacked,
stacked = _ref$stacked === void 0 ? false : _ref$stacked,
_ref$reverse = _ref.reverse,
reverse = _ref$reverse === void 0 ? false : _ref$reverse,
_ref$clamp = _ref.clamp,
clamp = _ref$clamp === void 0 ? false : _ref$clamp,
_ref$nice = _ref.nice,
nice = _ref$nice === void 0 ? false : _ref$nice;
var minValue;
if (min === 'auto') {
var _data$minStacked;
minValue = stacked === true ? (_data$minStacked = data.minStacked) !== null && _data$minStacked !== void 0 ? _data$minStacked : 0 : data.min;
} else {
minValue = min;
}
var maxValue;
if (max === 'auto') {
var _data$maxStacked;
maxValue = stacked === true ? (_data$maxStacked = data.maxStacked) !== null && _data$maxStacked !== void 0 ? _data$maxStacked : 0 : data.max;
} else {
maxValue = max;
}
var scale = scaleLinear().rangeRound(axis === 'x' ? [0, size] : [size, 0]).domain(reverse ? [maxValue, minValue] : [minValue, maxValue]).clamp(clamp);
if (nice === true) scale.nice();else if (typeof nice === 'number') scale.nice(nice);
return castLinearScale(scale, stacked);
};
var castLinearScale = function castLinearScale(scale) {
var stacked = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var typedScale = scale;
typedScale.type = 'linear';
typedScale.stacked = stacked;
return typedScale;
};
var createPointScale = function createPointScale(_spec, data, size) {
var scale = scalePoint().range([0, size]).domain(data.all);
var typedScale = scale;
typedScale.type = 'point';
return typedScale;
};
var createBandScale = function createBandScale(_ref, data, size, axis) {
var _ref$round = _ref.round,
round = _ref$round === void 0 ? true : _ref$round;
var scale = scaleBand().range(axis === 'x' ? [0, size] : [size, 0]).domain(data.all).round(round);
return castBandScale(scale);
};
var castBandScale = function castBandScale(scale) {
var typedScale = scale;
typedScale.type = 'band';
return typedScale;
};
var createTimeScale = function createTimeScale(_ref, data, size) {
var _ref$format = _ref.format,
format = _ref$format === void 0 ? 'native' : _ref$format,
_ref$precision = _ref.precision,
precision = _ref$precision === void 0 ? 'millisecond' : _ref$precision,
_ref$min = _ref.min,
min = _ref$min === void 0 ? 'auto' : _ref$min,
_ref$max = _ref.max,
max = _ref$max === void 0 ? 'auto' : _ref$max,
_ref$useUTC = _ref.useUTC,
useUTC = _ref$useUTC === void 0 ? true : _ref$useUTC,
_ref$nice = _ref.nice,
nice = _ref$nice === void 0 ? false : _ref$nice;
var normalize = createDateNormalizer({
format: format,
precision: precision,
useUTC: useUTC
});
var minValue;
if (min === 'auto') {
minValue = normalize(data.min);
} else if (format !== 'native') {
minValue = normalize(min);
} else {
minValue = min;
}
var maxValue;
if (max === 'auto') {
maxValue = normalize(data.max);
} else if (format !== 'native') {
maxValue = normalize(max);
} else {
maxValue = max;
}
var scale = useUTC ? scaleUtc() : scaleTime();
scale.range([0, size]);
if (minValue && maxValue) scale.domain([minValue, maxValue]);
if (nice === true) scale.nice();else if (typeof nice === 'object' || typeof nice === 'number') scale.nice(nice);
var typedScale = scale;
typedScale.type = 'time';
typedScale.useUTC = useUTC;
return typedScale;
};
var createLogScale = function createLogScale(_ref, data, size, axis) {
var _ref$base = _ref.base,
base = _ref$base === void 0 ? 10 : _ref$base,
_ref$min = _ref.min,
min = _ref$min === void 0 ? 'auto' : _ref$min,
_ref$max = _ref.max,
max = _ref$max === void 0 ? 'auto' : _ref$max;
var hasZero = data.all.some(function (v) {
return v === 0;
});
if (hasZero) {
throw new Error("a log scale domain must not include or cross zero");
}
var sign;
var hasMixedSign = false;
data.all.filter(function (v) {
return v != null;
}).forEach(function (v) {
if (hasMixedSign) return;
if (sign === undefined) {
sign = Math.sign(v);
} else if (Math.sign(v) !== sign) {
hasMixedSign = true;
}
});
if (hasMixedSign) {
throw new Error("a log scale domain must be strictly-positive or strictly-negative");
}
var minValue;
if (min === 'auto') {
minValue = data.min;
} else {
minValue = min;
}
var maxValue;
if (max === 'auto') {
maxValue = data.max;
} else {
maxValue = max;
}
var scale = scaleLog().domain([minValue, maxValue]).rangeRound(axis === 'x' ? [0, size] : [size, 0]).base(base).nice();
var typedScale = scale;
typedScale.type = 'log';
return scale;
};
var createSymlogScale = function createSymlogScale(_ref, data, size, axis) {
var _ref$constant = _ref.constant,
constant = _ref$constant === void 0 ? 1 : _ref$constant,
_ref$min = _ref.min,
min = _ref$min === void 0 ? 'auto' : _ref$min,
_ref$max = _ref.max,
max = _ref$max === void 0 ? 'auto' : _ref$max,
_ref$reverse = _ref.reverse,
reverse = _ref$reverse === void 0 ? false : _ref$reverse;
var minValue;
if (min === 'auto') {
minValue = data.min;
} else {
minValue = min;
}
var maxValue;
if (max === 'auto') {
maxValue = data.max;
} else {
maxValue = max;
}
var scale = scaleSymlog().constant(constant).rangeRound(axis === 'x' ? [0, size] : [size, 0]).nice();
if (reverse === true) scale.domain([maxValue, minValue]);else scale.domain([minValue, maxValue]);
var typedScale = scale;
typedScale.type = 'symlog';
return typedScale;
};
var getOtherAxis = function getOtherAxis(axis) {
return axis === 'x' ? 'y' : 'x';
};
var compareValues = function compareValues(a, b) {
return a === b;
};
var compareDateValues = function compareDateValues(a, b) {
return a.getTime() === b.getTime();
};
function computeScale(spec, data, size, axis) {
switch (spec.type) {
case 'linear':
return createLinearScale(spec, data, size, axis);
case 'point':
return createPointScale(spec, data, size);
case 'band':
return createBandScale(spec, data, size, axis);
case 'time':
return createTimeScale(spec, data, size);
case 'log':
return createLogScale(spec, data, size, axis);
case 'symlog':
return createSymlogScale(spec, data, size, axis);
default:
throw new Error('invalid scale spec');
}
}
var nestSerieData = function nestSerieData(serie) {
return _objectSpread2(_objectSpread2({}, serie), {}, {
data: serie.data.map(function (d) {
return {
data: _objectSpread2({}, d)
};
})
});
};
var getDatumAxisPosition = function getDatumAxisPosition(datum, axis, scale) {
var _scale;
if ('stacked' in scale && scale.stacked) {
var stackedValue = datum.data[axis === 'x' ? 'xStacked' : 'yStacked'];
if (stackedValue === null || stackedValue === undefined) {
return null;
}
return scale(stackedValue);
}
return (_scale = scale(datum.data[axis])) !== null && _scale !== void 0 ? _scale : null;
};
var computeXYScalesForSeries = function computeXYScalesForSeries(series, xScaleSpec, yScaleSpec, width, height) {
var nestedSeries = series.map(function (serie) {
return nestSerieData(serie);
});
var xy = generateSeriesXY(nestedSeries, xScaleSpec, yScaleSpec);
if ('stacked' in xScaleSpec && xScaleSpec.stacked === true) {
stackX(xy, nestedSeries);
}
if ('stacked' in yScaleSpec && yScaleSpec.stacked === true) {
stackY(xy, nestedSeries);
}
var xScale = computeScale(xScaleSpec, xy.x, width, 'x');
var yScale = computeScale(yScaleSpec, xy.y, height, 'y');
var computedSeries = nestedSeries.map(function (serie) {
return _objectSpread2(_objectSpread2({}, serie), {}, {
data: serie.data.map(function (datum) {
return _objectSpread2(_objectSpread2({}, datum), {}, {
position: {
x: getDatumAxisPosition(datum, 'x', xScale),
y: getDatumAxisPosition(datum, 'y', yScale)
}
});
})
});
});
return _objectSpread2(_objectSpread2({}, xy), {}, {
series: computedSeries,
xScale: xScale,
yScale: yScale
});
};
var generateSeriesXY = function generateSeriesXY(series, xScaleSpec, yScaleSpec) {
return {
x: generateSeriesAxis(series, 'x', xScaleSpec),
y: generateSeriesAxis(series, 'y', yScaleSpec)
};
};
var generateSeriesAxis = function generateSeriesAxis(series, axis, scaleSpec) {
var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
_ref$getValue = _ref.getValue,
getValue = _ref$getValue === void 0 ? function (d) {
return d.data[axis];
} : _ref$getValue,
_ref$setValue = _ref.setValue,
setValue = _ref$setValue === void 0 ? function (d, v) {
d.data[axis] = v;
} : _ref$setValue;
if (scaleSpec.type === 'linear') {
series.forEach(function (serie) {
serie.data.forEach(function (d) {
var value = getValue(d);
if (value) {
setValue(d, parseFloat(String(value)));
}
});
});
} else if (scaleSpec.type === 'time' && scaleSpec.format !== 'native') {
var parseTime = createDateNormalizer(scaleSpec);
series.forEach(function (serie) {
serie.data.forEach(function (d) {
var value = getValue(d);
if (value) {
setValue(d, parseTime(value));
}
});
});
}
var values = [];
series.forEach(function (serie) {
serie.data.forEach(function (d) {
values.push(getValue(d));
});
});
switch (scaleSpec.type) {
case 'linear':
{
var all = sortBy(uniq(values).filter(function (v) {
return v !== null;
}), function (v) {
return v;
});
return {
all: all,
min: Math.min.apply(Math, _toConsumableArray(all)),
max: Math.max.apply(Math, _toConsumableArray(all))
};
}
case 'time':
{
var _all = uniqBy(values, function (v) {
return v.getTime();
}).slice(0).sort(function (a, b) {
return b.getTime() - a.getTime();
}).reverse();
return {
all: _all,
min: _all[0],
max: last(_all)
};
}
default:
{
var _all2 = uniq(values);
return {
all: _all2,
min: _all2[0],
max: last(_all2)
};
}
}
};
var stackAxis = function stackAxis(axis, xy, series) {
var otherAxis = getOtherAxis(axis);
var all = [];
xy[otherAxis].all.forEach(function (v) {
var compare = isDate(v) ? compareDateValues : compareValues;
var stack = [];
series.forEach(function (serie) {
var datum = serie.data.find(function (d) {
return compare(d.data[otherAxis], v);
});
var value = null;
var stackValue = null;
if (datum !== undefined) {
value = datum.data[axis];
if (value !== null) {
var head = last(stack);
if (head === undefined) {
stackValue = value;
} else if (head !== null) {
stackValue = head + value;
}
}
datum.data[axis === 'x' ? 'xStacked' : 'yStacked'] = stackValue;
}
stack.push(stackValue);
if (stackValue !== null) {
all.push(stackValue);
}
});
});
xy[axis].minStacked = Math.min.apply(Math, all);
xy[axis].maxStacked = Math.max.apply(Math, all);
};
var stackX = function stackX(xy, series) {
return stackAxis('x', xy, series);
};
var stackY = function stackY(xy, series) {
return stackAxis('y', xy, series);
};
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(arr, i) {
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
var centerScale = function centerScale(scale) {
var bandwidth = scale.bandwidth();
if (bandwidth === 0) return scale;
var offset = bandwidth / 2;
if (scale.round()) {
offset = Math.round(offset);
}
return function (d) {
var _scale;
return ((_scale = scale(d)) !== null && _scale !== void 0 ? _scale : 0) + offset;
};
};
var timeDay = timeInterval(function (date) {
return date.setHours(0, 0, 0, 0);
}, function (date, step) {
return date.setDate(date.getDate() + step);
}, function (start, end) {
return (end.getTime() - start.getTime()) / 864e5;
}, function (date) {
return Math.floor(date.getTime() / 864e5);
});
var utcDay = timeInterval(function (date) {
return date.setUTCHours(0, 0, 0, 0);
}, function (date, step) {
return date.setUTCDate(date.getUTCDate() + step);
}, function (start, end) {
return (end.getTime() - start.getTime()) / 864e5;
}, function (date) {
return Math.floor(date.getTime() / 864e5);
});
var timeByType = {
millisecond: [timeMillisecond, utcMillisecond],
second: [timeSecond, utcSecond],
minute: [timeMinute, utcMinute],
hour: [timeHour, utcHour],
day: [timeDay, utcDay],
week: [timeWeek, utcWeek],
sunday: [timeSunday, utcSunday],
monday: [timeMonday, utcMonday],
tuesday: [timeTuesday, utcTuesday],
wednesday: [timeWednesday, utcWednesday],
thursday: [timeThursday, utcThursday],
friday: [timeFriday, utcFriday],
saturday: [timeSaturday, utcSaturday],
month: [timeMonth, utcMonth],
year: [timeYear, utcYear]
};
var timeTypes = Object.keys(timeByType);
var timeIntervalRegexp = new RegExp("^every\\s*(\\d+)?\\s*(".concat(timeTypes.join('|'), ")s?$"), 'i');
var isInteger = function isInteger(value) {
return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
};
var getScaleTicks = function getScaleTicks(scale, spec) {
if (Array.isArray(spec)) {
return spec;
}
if (typeof spec === 'string' && 'useUTC' in scale) {
var matches = spec.match(timeIntervalRegexp);
if (matches) {
var _matches = _slicedToArray(matches, 3),
amount = _matches[1],
type = _matches[2];
var timeType = timeByType[type][scale.useUTC ? 1 : 0];
if (type === 'day') {
var _timeType$every$range, _timeType$every;
var _scale$domain = scale.domain(),
_scale$domain2 = _slicedToArray(_scale$domain, 2),
start = _scale$domain2[0],
originalStop = _scale$domain2[1];
var stop = new Date(originalStop);
stop.setDate(stop.getDate() + 1);
return (_timeType$every$range = (_timeType$every = timeType.every(Number(amount !== null && amount !== void 0 ? amount : 1))) === null || _timeType$every === void 0 ? void 0 : _timeType$every.range(start, stop)) !== null && _timeType$every$range !== void 0 ? _timeType$every$range : [];
}
if (amount === undefined) {
return scale.ticks(timeType);
}
var interval = timeType.every(Number(amount));
if (interval) {
return scale.ticks(interval);
}
}
throw new Error("Invalid tickValues: ".concat(spec));
}
if ('ticks' in scale) {
if (spec === undefined) {
return scale.ticks();
}
if (isInteger(spec)) {
return scale.ticks(spec);
}
}
return scale.domain();
};
export { castBandScale, castLinearScale, centerScale, compareDateValues, compareValues, computeScale, computeXYScalesForSeries, createBandScale, createDateNormalizer, createLinearScale, createLogScale, createPointScale, createPrecisionMethod, createSymlogScale, createTimeScale, generateSeriesAxis, generateSeriesXY, getOtherAxis, getScaleTicks, precisionCutOffs, precisionCutOffsByType, stackAxis, timePrecisions };
import n from"lodash/uniq";import t from"lodash/uniqBy";import r from"lodash/sortBy";import e from"lodash/last";import a from"lodash/isDate";import{utcParse as i,timeParse as o}from"d3-time-format";import{scaleLinear as u,scalePoint as c,scaleBand as d,scaleUtc as f,scaleTime as s,scaleLog as l,scaleSymlog as m}from"d3-scale";import{timeInterval as v,timeMillisecond as y,utcMillisecond as p,timeSecond as h,utcSecond as g,timeMinute as x,utcMinute as k,timeHour as T,utcHour as M,timeWeek as w,utcWeek as b,timeSunday as E,utcSunday as S,timeMonday as D,utcMonday as C,timeTuesday as U,utcTuesday as j,timeWednesday as O,utcWednesday as R,timeThursday as H,utcThursday as V,timeFriday as q,utcFriday as A,timeSaturday as B,utcSaturday as F,timeMonth as N,utcMonth as z,timeYear as I,utcYear as P}from"d3-time";function $(){return $=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(n[e]=r[e])}return n},$.apply(this,arguments)}var G=["millisecond","second","minute","hour","day","month","year"],J=[function(n){return n.setMilliseconds(0)},function(n){return n.setSeconds(0)},function(n){return n.setMinutes(0)},function(n){return n.setHours(0)},function(n){return n.setDate(1)},function(n){return n.setMonth(0)}],K={millisecond:[],second:J.slice(0,1),minute:J.slice(0,2),hour:J.slice(0,3),day:J.slice(0,4),month:J.slice(0,5),year:J.slice(0,6)},L=function(n){return function(t){return K[n].forEach((function(n){n(t)})),t}},Q=function(n){var t=n.format,r=void 0===t?"native":t,e=n.precision,a=void 0===e?"millisecond":e,u=n.useUTC,c=void 0===u||u,d=L(a);return function(n){if(void 0===n)return n;if("native"===r||n instanceof Date)return d(n);var t=c?i(r):o(r);return d(t(n))}},W=function(n,t,r,e){var a,i,o,c,d=n.min,f=void 0===d?0:d,s=n.max,l=void 0===s?"auto":s,m=n.stacked,v=void 0!==m&&m,y=n.reverse,p=void 0!==y&&y,h=n.clamp,g=void 0!==h&&h,x=n.nice,k=void 0!==x&&x;"auto"===f?a=!0===v?null!=(i=t.minStacked)?i:0:t.min:a=f;"auto"===l?o=!0===v?null!=(c=t.maxStacked)?c:0:t.max:o=l;var T=u().rangeRound("x"===e?[0,r]:[r,0]).domain(p?[o,a]:[a,o]).clamp(g);return!0===k?T.nice():"number"==typeof k&&T.nice(k),X(T,v)},X=function(n,t){void 0===t&&(t=!1);var r=n;return r.type="linear",r.stacked=t,r},Y=function(n,t,r){var e=c().range([0,r]).domain(t.all);return e.type="point",e},Z=function(n,t,r,e){var a=n.round,i=void 0===a||a,o=d().range("x"===e?[0,r]:[r,0]).domain(t.all).round(i);return _(o)},_=function(n){var t=n;return t.type="band",t},nn=function(n,t,r){var e,a,i=n.format,o=void 0===i?"native":i,u=n.precision,c=void 0===u?"millisecond":u,d=n.min,l=void 0===d?"auto":d,m=n.max,v=void 0===m?"auto":m,y=n.useUTC,p=void 0===y||y,h=n.nice,g=void 0!==h&&h,x=Q({format:o,precision:c,useUTC:p});e="auto"===l?x(t.min):"native"!==o?x(l):l,a="auto"===v?x(t.max):"native"!==o?x(v):v;var k=p?f():s();k.range([0,r]),e&&a&&k.domain([e,a]),!0===g?k.nice():"object"!=typeof g&&"number"!=typeof g||k.nice(g);var T=k;return T.type="time",T.useUTC=p,T},tn=function(n,t,r,e){var a,i=n.base,o=void 0===i?10:i,u=n.min,c=void 0===u?"auto":u,d=n.max,f=void 0===d?"auto":d;if(t.all.some((function(n){return 0===n})))throw new Error("a log scale domain must not include or cross zero");var s,m,v=!1;if(t.all.filter((function(n){return null!=n})).forEach((function(n){v||(void 0===a?a=Math.sign(n):Math.sign(n)!==a&&(v=!0))})),v)throw new Error("a log scale domain must be strictly-positive or strictly-negative");s="auto"===c?t.min:c,m="auto"===f?t.max:f;var y=l().domain([s,m]).rangeRound("x"===e?[0,r]:[r,0]).base(o).nice();return y.type="log",y},rn=function(n,t,r,e){var a,i,o=n.constant,u=void 0===o?1:o,c=n.min,d=void 0===c?"auto":c,f=n.max,s=void 0===f?"auto":f,l=n.reverse,v=void 0!==l&&l;a="auto"===d?t.min:d,i="auto"===s?t.max:s;var y=m().constant(u).rangeRound("x"===e?[0,r]:[r,0]).nice();!0===v?y.domain([i,a]):y.domain([a,i]);var p=y;return p.type="symlog",p},en=function(n){return"x"===n?"y":"x"},an=function(n,t){return n===t},on=function(n,t){return n.getTime()===t.getTime()};function un(n,t,r,e){switch(n.type){case"linear":return W(n,t,r,e);case"point":return Y(0,t,r);case"band":return Z(n,t,r,e);case"time":return nn(n,t,r);case"log":return tn(n,t,r,e);case"symlog":return rn(n,t,r,e);default:throw new Error("invalid scale spec")}}var cn=function(n,t,r){var e;if("stacked"in r&&r.stacked){var a=n.data["x"===t?"xStacked":"yStacked"];return null==a?null:r(a)}return null!=(e=r(n.data[t]))?e:null},dn=function(n,t,r,e,a){var i=n.map((function(n){return function(n){return $({},n,{data:n.data.map((function(n){return{data:$({},n)}}))})}(n)})),o=fn(i,t,r);"stacked"in t&&!0===t.stacked&&mn(o,i),"stacked"in r&&!0===r.stacked&&vn(o,i);var u=un(t,o.x,e,"x"),c=un(r,o.y,a,"y"),d=i.map((function(n){return $({},n,{data:n.data.map((function(n){return $({},n,{position:{x:cn(n,"x",u),y:cn(n,"y",c)}})}))})}));return $({},o,{series:d,xScale:u,yScale:c})},fn=function(n,t,r){return{x:sn(n,"x",t),y:sn(n,"y",r)}},sn=function(a,i,o,u){var c=void 0===u?{}:u,d=c.getValue,f=void 0===d?function(n){return n.data[i]}:d,s=c.setValue,l=void 0===s?function(n,t){n.data[i]=t}:s;if("linear"===o.type)a.forEach((function(n){n.data.forEach((function(n){var t=f(n);t&&l(n,parseFloat(String(t)))}))}));else if("time"===o.type&&"native"!==o.format){var m=Q(o);a.forEach((function(n){n.data.forEach((function(n){var t=f(n);t&&l(n,m(t))}))}))}var v=[];switch(a.forEach((function(n){n.data.forEach((function(n){v.push(f(n))}))})),o.type){case"linear":var y=r(n(v).filter((function(n){return null!==n})),(function(n){return n}));return{all:y,min:Math.min.apply(Math,y),max:Math.max.apply(Math,y)};case"time":var p=t(v,(function(n){return n.getTime()})).slice(0).sort((function(n,t){return t.getTime()-n.getTime()})).reverse();return{all:p,min:p[0],max:e(p)};default:var h=n(v);return{all:h,min:h[0],max:e(h)}}},ln=function(n,t,r){var i=en(n),o=[];t[i].all.forEach((function(t){var u=a(t)?on:an,c=[];r.forEach((function(r){var a=r.data.find((function(n){return u(n.data[i],t)})),d=null,f=null;if(void 0!==a){if(null!==(d=a.data[n])){var s=e(c);void 0===s?f=d:null!==s&&(f=s+d)}a.data["x"===n?"xStacked":"yStacked"]=f}c.push(f),null!==f&&o.push(f)}))})),t[n].minStacked=Math.min.apply(Math,o),t[n].maxStacked=Math.max.apply(Math,o)},mn=function(n,t){return ln("x",n,t)},vn=function(n,t){return ln("y",n,t)},yn=function(n){var t=n.bandwidth();if(0===t)return n;var r=t/2;return n.round()&&(r=Math.round(r)),function(t){var e;return(null!=(e=n(t))?e:0)+r}},pn={millisecond:[y,p],second:[h,g],minute:[x,k],hour:[T,M],day:[v((function(n){return n.setHours(0,0,0,0)}),(function(n,t){return n.setDate(n.getDate()+t)}),(function(n,t){return(t.getTime()-n.getTime())/864e5}),(function(n){return Math.floor(n.getTime()/864e5)})),v((function(n){return n.setUTCHours(0,0,0,0)}),(function(n,t){return n.setUTCDate(n.getUTCDate()+t)}),(function(n,t){return(t.getTime()-n.getTime())/864e5}),(function(n){return Math.floor(n.getTime()/864e5)}))],week:[w,b],sunday:[E,S],monday:[D,C],tuesday:[U,j],wednesday:[O,R],thursday:[H,V],friday:[q,A],saturday:[B,F],month:[N,z],year:[I,P]},hn=Object.keys(pn),gn=new RegExp("^every\\s*(\\d+)?\\s*("+hn.join("|")+")s?$","i"),xn=function(n,t){if(Array.isArray(t))return t;if("string"==typeof t&&"useUTC"in n){var r=t.match(gn);if(r){var e=r[1],a=r[2],i=pn[a][n.useUTC?1:0];if("day"===a){var o,u,c=n.domain(),d=c[0],f=c[1],s=new Date(f);return s.setDate(s.getDate()+1),null!=(o=null==(u=i.every(Number(null!=e?e:1)))?void 0:u.range(d,s))?o:[]}if(void 0===e)return n.ticks(i);var l=i.every(Number(e));if(l)return n.ticks(l)}throw new Error("Invalid tickValues: "+t)}if("ticks"in n){if(void 0===t)return n.ticks();if("number"==typeof(m=t)&&isFinite(m)&&Math.floor(m)===m)return n.ticks(t)}var m;return n.domain()};export{_ as castBandScale,X as castLinearScale,yn as centerScale,on as compareDateValues,an as compareValues,un as computeScale,dn as computeXYScalesForSeries,Z as createBandScale,Q as createDateNormalizer,W as createLinearScale,tn as createLogScale,Y as createPointScale,L as createPrecisionMethod,rn as createSymlogScale,nn as createTimeScale,sn as generateSeriesAxis,fn as generateSeriesXY,en as getOtherAxis,xn as getScaleTicks,J as precisionCutOffs,K as precisionCutOffsByType,ln as stackAxis,G as timePrecisions};
//# sourceMappingURL=nivo-scales.es.js.map

@@ -1,747 +0,2 @@

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash/uniq'), require('lodash/uniqBy'), require('lodash/sortBy'), require('lodash/last'), require('lodash/isDate'), require('d3-time-format'), require('d3-scale'), require('d3-time')) :
typeof define === 'function' && define.amd ? define(['exports', 'lodash/uniq', 'lodash/uniqBy', 'lodash/sortBy', 'lodash/last', 'lodash/isDate', 'd3-time-format', 'd3-scale', 'd3-time'], factory) :
(global = global || self, factory(global.nivo = global.nivo || {}, global['lodash/uniq'], global['lodash/uniqBy'], global['lodash/sortBy'], global['lodash/last'], global['lodash/isDate'], global.d3, global.d3, global.d3));
}(this, (function (exports, uniq, uniqBy, sortBy, last, isDate, d3TimeFormat, d3Scale, d3Time) { 'use strict';
uniq = uniq && Object.prototype.hasOwnProperty.call(uniq, 'default') ? uniq['default'] : uniq;
uniqBy = uniqBy && Object.prototype.hasOwnProperty.call(uniqBy, 'default') ? uniqBy['default'] : uniqBy;
sortBy = sortBy && Object.prototype.hasOwnProperty.call(sortBy, 'default') ? sortBy['default'] : sortBy;
last = last && Object.prototype.hasOwnProperty.call(last, 'default') ? last['default'] : last;
isDate = isDate && Object.prototype.hasOwnProperty.call(isDate, 'default') ? isDate['default'] : isDate;
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) {
arr2[i] = arr[i];
}
return arr2;
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
}
return target;
}
var timePrecisions = ['millisecond', 'second', 'minute', 'hour', 'day', 'month', 'year'];
var precisionCutOffs = [function (date) {
return date.setMilliseconds(0);
}, function (date) {
return date.setSeconds(0);
}, function (date) {
return date.setMinutes(0);
}, function (date) {
return date.setHours(0);
}, function (date) {
return date.setDate(1);
}, function (date) {
return date.setMonth(0);
}];
var precisionCutOffsByType = {
millisecond: [],
second: precisionCutOffs.slice(0, 1),
minute: precisionCutOffs.slice(0, 2),
hour: precisionCutOffs.slice(0, 3),
day: precisionCutOffs.slice(0, 4),
month: precisionCutOffs.slice(0, 5),
year: precisionCutOffs.slice(0, 6)
};
var createPrecisionMethod = function createPrecisionMethod(precision) {
return function (date) {
precisionCutOffsByType[precision].forEach(function (cutOff) {
cutOff(date);
});
return date;
};
};
var createDateNormalizer = function createDateNormalizer(_ref) {
var _ref$format = _ref.format,
format = _ref$format === void 0 ? 'native' : _ref$format,
_ref$precision = _ref.precision,
precision = _ref$precision === void 0 ? 'millisecond' : _ref$precision,
_ref$useUTC = _ref.useUTC,
useUTC = _ref$useUTC === void 0 ? true : _ref$useUTC;
var precisionFn = createPrecisionMethod(precision);
return function (value) {
if (value === undefined) {
return value;
}
if (format === 'native' || value instanceof Date) {
return precisionFn(value);
}
var parseTime = useUTC ? d3TimeFormat.utcParse(format) : d3TimeFormat.timeParse(format);
return precisionFn(parseTime(value));
};
};
var createLinearScale = function createLinearScale(_ref, data, size, axis) {
var _ref$min = _ref.min,
min = _ref$min === void 0 ? 0 : _ref$min,
_ref$max = _ref.max,
max = _ref$max === void 0 ? 'auto' : _ref$max,
_ref$stacked = _ref.stacked,
stacked = _ref$stacked === void 0 ? false : _ref$stacked,
_ref$reverse = _ref.reverse,
reverse = _ref$reverse === void 0 ? false : _ref$reverse,
_ref$clamp = _ref.clamp,
clamp = _ref$clamp === void 0 ? false : _ref$clamp,
_ref$nice = _ref.nice,
nice = _ref$nice === void 0 ? false : _ref$nice;
var minValue;
if (min === 'auto') {
var _data$minStacked;
minValue = stacked === true ? (_data$minStacked = data.minStacked) !== null && _data$minStacked !== void 0 ? _data$minStacked : 0 : data.min;
} else {
minValue = min;
}
var maxValue;
if (max === 'auto') {
var _data$maxStacked;
maxValue = stacked === true ? (_data$maxStacked = data.maxStacked) !== null && _data$maxStacked !== void 0 ? _data$maxStacked : 0 : data.max;
} else {
maxValue = max;
}
var scale = d3Scale.scaleLinear().rangeRound(axis === 'x' ? [0, size] : [size, 0]).domain(reverse ? [maxValue, minValue] : [minValue, maxValue]).clamp(clamp);
if (nice === true) scale.nice();else if (typeof nice === 'number') scale.nice(nice);
return castLinearScale(scale, stacked);
};
var castLinearScale = function castLinearScale(scale) {
var stacked = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var typedScale = scale;
typedScale.type = 'linear';
typedScale.stacked = stacked;
return typedScale;
};
var createPointScale = function createPointScale(_spec, data, size) {
var scale = d3Scale.scalePoint().range([0, size]).domain(data.all);
var typedScale = scale;
typedScale.type = 'point';
return typedScale;
};
var createBandScale = function createBandScale(_ref, data, size, axis) {
var _ref$round = _ref.round,
round = _ref$round === void 0 ? true : _ref$round;
var scale = d3Scale.scaleBand().range(axis === 'x' ? [0, size] : [size, 0]).domain(data.all).round(round);
return castBandScale(scale);
};
var castBandScale = function castBandScale(scale) {
var typedScale = scale;
typedScale.type = 'band';
return typedScale;
};
var createTimeScale = function createTimeScale(_ref, data, size) {
var _ref$format = _ref.format,
format = _ref$format === void 0 ? 'native' : _ref$format,
_ref$precision = _ref.precision,
precision = _ref$precision === void 0 ? 'millisecond' : _ref$precision,
_ref$min = _ref.min,
min = _ref$min === void 0 ? 'auto' : _ref$min,
_ref$max = _ref.max,
max = _ref$max === void 0 ? 'auto' : _ref$max,
_ref$useUTC = _ref.useUTC,
useUTC = _ref$useUTC === void 0 ? true : _ref$useUTC,
_ref$nice = _ref.nice,
nice = _ref$nice === void 0 ? false : _ref$nice;
var normalize = createDateNormalizer({
format: format,
precision: precision,
useUTC: useUTC
});
var minValue;
if (min === 'auto') {
minValue = normalize(data.min);
} else if (format !== 'native') {
minValue = normalize(min);
} else {
minValue = min;
}
var maxValue;
if (max === 'auto') {
maxValue = normalize(data.max);
} else if (format !== 'native') {
maxValue = normalize(max);
} else {
maxValue = max;
}
var scale = useUTC ? d3Scale.scaleUtc() : d3Scale.scaleTime();
scale.range([0, size]);
if (minValue && maxValue) scale.domain([minValue, maxValue]);
if (nice === true) scale.nice();else if (typeof nice === 'object' || typeof nice === 'number') scale.nice(nice);
var typedScale = scale;
typedScale.type = 'time';
typedScale.useUTC = useUTC;
return typedScale;
};
var createLogScale = function createLogScale(_ref, data, size, axis) {
var _ref$base = _ref.base,
base = _ref$base === void 0 ? 10 : _ref$base,
_ref$min = _ref.min,
min = _ref$min === void 0 ? 'auto' : _ref$min,
_ref$max = _ref.max,
max = _ref$max === void 0 ? 'auto' : _ref$max;
var hasZero = data.all.some(function (v) {
return v === 0;
});
if (hasZero) {
throw new Error("a log scale domain must not include or cross zero");
}
var sign;
var hasMixedSign = false;
data.all.filter(function (v) {
return v != null;
}).forEach(function (v) {
if (hasMixedSign) return;
if (sign === undefined) {
sign = Math.sign(v);
} else if (Math.sign(v) !== sign) {
hasMixedSign = true;
}
});
if (hasMixedSign) {
throw new Error("a log scale domain must be strictly-positive or strictly-negative");
}
var minValue;
if (min === 'auto') {
minValue = data.min;
} else {
minValue = min;
}
var maxValue;
if (max === 'auto') {
maxValue = data.max;
} else {
maxValue = max;
}
var scale = d3Scale.scaleLog().domain([minValue, maxValue]).rangeRound(axis === 'x' ? [0, size] : [size, 0]).base(base).nice();
var typedScale = scale;
typedScale.type = 'log';
return scale;
};
var createSymlogScale = function createSymlogScale(_ref, data, size, axis) {
var _ref$constant = _ref.constant,
constant = _ref$constant === void 0 ? 1 : _ref$constant,
_ref$min = _ref.min,
min = _ref$min === void 0 ? 'auto' : _ref$min,
_ref$max = _ref.max,
max = _ref$max === void 0 ? 'auto' : _ref$max,
_ref$reverse = _ref.reverse,
reverse = _ref$reverse === void 0 ? false : _ref$reverse;
var minValue;
if (min === 'auto') {
minValue = data.min;
} else {
minValue = min;
}
var maxValue;
if (max === 'auto') {
maxValue = data.max;
} else {
maxValue = max;
}
var scale = d3Scale.scaleSymlog().constant(constant).rangeRound(axis === 'x' ? [0, size] : [size, 0]).nice();
if (reverse === true) scale.domain([maxValue, minValue]);else scale.domain([minValue, maxValue]);
var typedScale = scale;
typedScale.type = 'symlog';
return typedScale;
};
var getOtherAxis = function getOtherAxis(axis) {
return axis === 'x' ? 'y' : 'x';
};
var compareValues = function compareValues(a, b) {
return a === b;
};
var compareDateValues = function compareDateValues(a, b) {
return a.getTime() === b.getTime();
};
function computeScale(spec, data, size, axis) {
switch (spec.type) {
case 'linear':
return createLinearScale(spec, data, size, axis);
case 'point':
return createPointScale(spec, data, size);
case 'band':
return createBandScale(spec, data, size, axis);
case 'time':
return createTimeScale(spec, data, size);
case 'log':
return createLogScale(spec, data, size, axis);
case 'symlog':
return createSymlogScale(spec, data, size, axis);
default:
throw new Error('invalid scale spec');
}
}
var nestSerieData = function nestSerieData(serie) {
return _objectSpread2(_objectSpread2({}, serie), {}, {
data: serie.data.map(function (d) {
return {
data: _objectSpread2({}, d)
};
})
});
};
var getDatumAxisPosition = function getDatumAxisPosition(datum, axis, scale) {
var _scale;
if ('stacked' in scale && scale.stacked) {
var stackedValue = datum.data[axis === 'x' ? 'xStacked' : 'yStacked'];
if (stackedValue === null || stackedValue === undefined) {
return null;
}
return scale(stackedValue);
}
return (_scale = scale(datum.data[axis])) !== null && _scale !== void 0 ? _scale : null;
};
var computeXYScalesForSeries = function computeXYScalesForSeries(series, xScaleSpec, yScaleSpec, width, height) {
var nestedSeries = series.map(function (serie) {
return nestSerieData(serie);
});
var xy = generateSeriesXY(nestedSeries, xScaleSpec, yScaleSpec);
if ('stacked' in xScaleSpec && xScaleSpec.stacked === true) {
stackX(xy, nestedSeries);
}
if ('stacked' in yScaleSpec && yScaleSpec.stacked === true) {
stackY(xy, nestedSeries);
}
var xScale = computeScale(xScaleSpec, xy.x, width, 'x');
var yScale = computeScale(yScaleSpec, xy.y, height, 'y');
var computedSeries = nestedSeries.map(function (serie) {
return _objectSpread2(_objectSpread2({}, serie), {}, {
data: serie.data.map(function (datum) {
return _objectSpread2(_objectSpread2({}, datum), {}, {
position: {
x: getDatumAxisPosition(datum, 'x', xScale),
y: getDatumAxisPosition(datum, 'y', yScale)
}
});
})
});
});
return _objectSpread2(_objectSpread2({}, xy), {}, {
series: computedSeries,
xScale: xScale,
yScale: yScale
});
};
var generateSeriesXY = function generateSeriesXY(series, xScaleSpec, yScaleSpec) {
return {
x: generateSeriesAxis(series, 'x', xScaleSpec),
y: generateSeriesAxis(series, 'y', yScaleSpec)
};
};
var generateSeriesAxis = function generateSeriesAxis(series, axis, scaleSpec) {
var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
_ref$getValue = _ref.getValue,
getValue = _ref$getValue === void 0 ? function (d) {
return d.data[axis];
} : _ref$getValue,
_ref$setValue = _ref.setValue,
setValue = _ref$setValue === void 0 ? function (d, v) {
d.data[axis] = v;
} : _ref$setValue;
if (scaleSpec.type === 'linear') {
series.forEach(function (serie) {
serie.data.forEach(function (d) {
var value = getValue(d);
if (value) {
setValue(d, parseFloat(String(value)));
}
});
});
} else if (scaleSpec.type === 'time' && scaleSpec.format !== 'native') {
var parseTime = createDateNormalizer(scaleSpec);
series.forEach(function (serie) {
serie.data.forEach(function (d) {
var value = getValue(d);
if (value) {
setValue(d, parseTime(value));
}
});
});
}
var values = [];
series.forEach(function (serie) {
serie.data.forEach(function (d) {
values.push(getValue(d));
});
});
switch (scaleSpec.type) {
case 'linear':
{
var all = sortBy(uniq(values).filter(function (v) {
return v !== null;
}), function (v) {
return v;
});
return {
all: all,
min: Math.min.apply(Math, _toConsumableArray(all)),
max: Math.max.apply(Math, _toConsumableArray(all))
};
}
case 'time':
{
var _all = uniqBy(values, function (v) {
return v.getTime();
}).slice(0).sort(function (a, b) {
return b.getTime() - a.getTime();
}).reverse();
return {
all: _all,
min: _all[0],
max: last(_all)
};
}
default:
{
var _all2 = uniq(values);
return {
all: _all2,
min: _all2[0],
max: last(_all2)
};
}
}
};
var stackAxis = function stackAxis(axis, xy, series) {
var otherAxis = getOtherAxis(axis);
var all = [];
xy[otherAxis].all.forEach(function (v) {
var compare = isDate(v) ? compareDateValues : compareValues;
var stack = [];
series.forEach(function (serie) {
var datum = serie.data.find(function (d) {
return compare(d.data[otherAxis], v);
});
var value = null;
var stackValue = null;
if (datum !== undefined) {
value = datum.data[axis];
if (value !== null) {
var head = last(stack);
if (head === undefined) {
stackValue = value;
} else if (head !== null) {
stackValue = head + value;
}
}
datum.data[axis === 'x' ? 'xStacked' : 'yStacked'] = stackValue;
}
stack.push(stackValue);
if (stackValue !== null) {
all.push(stackValue);
}
});
});
xy[axis].minStacked = Math.min.apply(Math, all);
xy[axis].maxStacked = Math.max.apply(Math, all);
};
var stackX = function stackX(xy, series) {
return stackAxis('x', xy, series);
};
var stackY = function stackY(xy, series) {
return stackAxis('y', xy, series);
};
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(arr, i) {
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
var centerScale = function centerScale(scale) {
var bandwidth = scale.bandwidth();
if (bandwidth === 0) return scale;
var offset = bandwidth / 2;
if (scale.round()) {
offset = Math.round(offset);
}
return function (d) {
var _scale;
return ((_scale = scale(d)) !== null && _scale !== void 0 ? _scale : 0) + offset;
};
};
var timeDay = d3Time.timeInterval(function (date) {
return date.setHours(0, 0, 0, 0);
}, function (date, step) {
return date.setDate(date.getDate() + step);
}, function (start, end) {
return (end.getTime() - start.getTime()) / 864e5;
}, function (date) {
return Math.floor(date.getTime() / 864e5);
});
var utcDay = d3Time.timeInterval(function (date) {
return date.setUTCHours(0, 0, 0, 0);
}, function (date, step) {
return date.setUTCDate(date.getUTCDate() + step);
}, function (start, end) {
return (end.getTime() - start.getTime()) / 864e5;
}, function (date) {
return Math.floor(date.getTime() / 864e5);
});
var timeByType = {
millisecond: [d3Time.timeMillisecond, d3Time.utcMillisecond],
second: [d3Time.timeSecond, d3Time.utcSecond],
minute: [d3Time.timeMinute, d3Time.utcMinute],
hour: [d3Time.timeHour, d3Time.utcHour],
day: [timeDay, utcDay],
week: [d3Time.timeWeek, d3Time.utcWeek],
sunday: [d3Time.timeSunday, d3Time.utcSunday],
monday: [d3Time.timeMonday, d3Time.utcMonday],
tuesday: [d3Time.timeTuesday, d3Time.utcTuesday],
wednesday: [d3Time.timeWednesday, d3Time.utcWednesday],
thursday: [d3Time.timeThursday, d3Time.utcThursday],
friday: [d3Time.timeFriday, d3Time.utcFriday],
saturday: [d3Time.timeSaturday, d3Time.utcSaturday],
month: [d3Time.timeMonth, d3Time.utcMonth],
year: [d3Time.timeYear, d3Time.utcYear]
};
var timeTypes = Object.keys(timeByType);
var timeIntervalRegexp = new RegExp("^every\\s*(\\d+)?\\s*(".concat(timeTypes.join('|'), ")s?$"), 'i');
var isInteger = function isInteger(value) {
return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
};
var getScaleTicks = function getScaleTicks(scale, spec) {
if (Array.isArray(spec)) {
return spec;
}
if (typeof spec === 'string' && 'useUTC' in scale) {
var matches = spec.match(timeIntervalRegexp);
if (matches) {
var _matches = _slicedToArray(matches, 3),
amount = _matches[1],
type = _matches[2];
var timeType = timeByType[type][scale.useUTC ? 1 : 0];
if (type === 'day') {
var _timeType$every$range, _timeType$every;
var _scale$domain = scale.domain(),
_scale$domain2 = _slicedToArray(_scale$domain, 2),
start = _scale$domain2[0],
originalStop = _scale$domain2[1];
var stop = new Date(originalStop);
stop.setDate(stop.getDate() + 1);
return (_timeType$every$range = (_timeType$every = timeType.every(Number(amount !== null && amount !== void 0 ? amount : 1))) === null || _timeType$every === void 0 ? void 0 : _timeType$every.range(start, stop)) !== null && _timeType$every$range !== void 0 ? _timeType$every$range : [];
}
if (amount === undefined) {
return scale.ticks(timeType);
}
var interval = timeType.every(Number(amount));
if (interval) {
return scale.ticks(interval);
}
}
throw new Error("Invalid tickValues: ".concat(spec));
}
if ('ticks' in scale) {
if (spec === undefined) {
return scale.ticks();
}
if (isInteger(spec)) {
return scale.ticks(spec);
}
}
return scale.domain();
};
exports.castBandScale = castBandScale;
exports.castLinearScale = castLinearScale;
exports.centerScale = centerScale;
exports.compareDateValues = compareDateValues;
exports.compareValues = compareValues;
exports.computeScale = computeScale;
exports.computeXYScalesForSeries = computeXYScalesForSeries;
exports.createBandScale = createBandScale;
exports.createDateNormalizer = createDateNormalizer;
exports.createLinearScale = createLinearScale;
exports.createLogScale = createLogScale;
exports.createPointScale = createPointScale;
exports.createPrecisionMethod = createPrecisionMethod;
exports.createSymlogScale = createSymlogScale;
exports.createTimeScale = createTimeScale;
exports.generateSeriesAxis = generateSeriesAxis;
exports.generateSeriesXY = generateSeriesXY;
exports.getOtherAxis = getOtherAxis;
exports.getScaleTicks = getScaleTicks;
exports.precisionCutOffs = precisionCutOffs;
exports.precisionCutOffsByType = precisionCutOffsByType;
exports.stackAxis = stackAxis;
exports.timePrecisions = timePrecisions;
Object.defineProperty(exports, '__esModule', { value: true });
})));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("lodash/uniq"),require("lodash/uniqBy"),require("lodash/sortBy"),require("lodash/last"),require("lodash/isDate"),require("d3-time-format"),require("d3-scale"),require("d3-time")):"function"==typeof define&&define.amd?define(["exports","lodash/uniq","lodash/uniqBy","lodash/sortBy","lodash/last","lodash/isDate","d3-time-format","d3-scale","d3-time"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).nivo=e.nivo||{},e["lodash/uniq"],e["lodash/uniqBy"],e["lodash/sortBy"],e["lodash/last"],e["lodash/isDate"],e.d3,e.d3,e.d3)}(this,(function(e,t,n,a,r,i,o,u,c){"use strict";function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d=s(t),l=s(n),f=s(a),m=s(r),v=s(i);function y(){return y=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e},y.apply(this,arguments)}var h=[function(e){return e.setMilliseconds(0)},function(e){return e.setSeconds(0)},function(e){return e.setMinutes(0)},function(e){return e.setHours(0)},function(e){return e.setDate(1)},function(e){return e.setMonth(0)}],p={millisecond:[],second:h.slice(0,1),minute:h.slice(0,2),hour:h.slice(0,3),day:h.slice(0,4),month:h.slice(0,5),year:h.slice(0,6)},g=function(e){return function(t){return p[e].forEach((function(e){e(t)})),t}},x=function(e){var t=e.format,n=void 0===t?"native":t,a=e.precision,r=void 0===a?"millisecond":a,i=e.useUTC,u=void 0===i||i,c=g(r);return function(e){if(void 0===e)return e;if("native"===n||e instanceof Date)return c(e);var t=u?o.utcParse(n):o.timeParse(n);return c(t(e))}},S=function(e,t,n,a){var r,i,o,c,s=e.min,d=void 0===s?0:s,l=e.max,f=void 0===l?"auto":l,m=e.stacked,v=void 0!==m&&m,y=e.reverse,h=void 0!==y&&y,p=e.clamp,g=void 0!==p&&p,x=e.nice,S=void 0!==x&&x;"auto"===d?r=!0===v?null!=(i=t.minStacked)?i:0:t.min:r=d;"auto"===f?o=!0===v?null!=(c=t.maxStacked)?c:0:t.max:o=f;var k=u.scaleLinear().rangeRound("x"===a?[0,n]:[n,0]).domain(h?[o,r]:[r,o]).clamp(g);return!0===S?k.nice():"number"==typeof S&&k.nice(S),T(k,v)},T=function(e,t){void 0===t&&(t=!1);var n=e;return n.type="linear",n.stacked=t,n},k=function(e,t,n){var a=u.scalePoint().range([0,n]).domain(t.all);return a.type="point",a},M=function(e,t,n,a){var r=e.round,i=void 0===r||r,o=u.scaleBand().range("x"===a?[0,n]:[n,0]).domain(t.all).round(i);return b(o)},b=function(e){var t=e;return t.type="band",t},w=function(e,t,n){var a,r,i=e.format,o=void 0===i?"native":i,c=e.precision,s=void 0===c?"millisecond":c,d=e.min,l=void 0===d?"auto":d,f=e.max,m=void 0===f?"auto":f,v=e.useUTC,y=void 0===v||v,h=e.nice,p=void 0!==h&&h,g=x({format:o,precision:s,useUTC:y});a="auto"===l?g(t.min):"native"!==o?g(l):l,r="auto"===m?g(t.max):"native"!==o?g(m):m;var S=y?u.scaleUtc():u.scaleTime();S.range([0,n]),a&&r&&S.domain([a,r]),!0===p?S.nice():"object"!=typeof p&&"number"!=typeof p||S.nice(p);var T=S;return T.type="time",T.useUTC=y,T},E=function(e,t,n,a){var r,i=e.base,o=void 0===i?10:i,c=e.min,s=void 0===c?"auto":c,d=e.max,l=void 0===d?"auto":d;if(t.all.some((function(e){return 0===e})))throw new Error("a log scale domain must not include or cross zero");var f,m,v=!1;if(t.all.filter((function(e){return null!=e})).forEach((function(e){v||(void 0===r?r=Math.sign(e):Math.sign(e)!==r&&(v=!0))})),v)throw new Error("a log scale domain must be strictly-positive or strictly-negative");f="auto"===s?t.min:s,m="auto"===l?t.max:l;var y=u.scaleLog().domain([f,m]).rangeRound("x"===a?[0,n]:[n,0]).base(o).nice();return y.type="log",y},q=function(e,t,n,a){var r,i,o=e.constant,c=void 0===o?1:o,s=e.min,d=void 0===s?"auto":s,l=e.max,f=void 0===l?"auto":l,m=e.reverse,v=void 0!==m&&m;r="auto"===d?t.min:d,i="auto"===f?t.max:f;var y=u.scaleSymlog().constant(c).rangeRound("x"===a?[0,n]:[n,0]).nice();!0===v?y.domain([i,r]):y.domain([r,i]);var h=y;return h.type="symlog",h},D=function(e){return"x"===e?"y":"x"},C=function(e,t){return e===t},B=function(e,t){return e.getTime()===t.getTime()};function U(e,t,n,a){switch(e.type){case"linear":return S(e,t,n,a);case"point":return k(0,t,n);case"band":return M(e,t,n,a);case"time":return w(e,t,n);case"log":return E(e,t,n,a);case"symlog":return q(e,t,n,a);default:throw new Error("invalid scale spec")}}var j=function(e,t,n){var a;if("stacked"in n&&n.stacked){var r=e.data["x"===t?"xStacked":"yStacked"];return null==r?null:n(r)}return null!=(a=n(e.data[t]))?a:null},O=function(e,t,n){return{x:P(e,"x",t),y:P(e,"y",n)}},P=function(e,t,n,a){var r=void 0===a?{}:a,i=r.getValue,o=void 0===i?function(e){return e.data[t]}:i,u=r.setValue,c=void 0===u?function(e,n){e.data[t]=n}:u;if("linear"===n.type)e.forEach((function(e){e.data.forEach((function(e){var t=o(e);t&&c(e,parseFloat(String(t)))}))}));else if("time"===n.type&&"native"!==n.format){var s=x(n);e.forEach((function(e){e.data.forEach((function(e){var t=o(e);t&&c(e,s(t))}))}))}var v=[];switch(e.forEach((function(e){e.data.forEach((function(e){v.push(o(e))}))})),n.type){case"linear":var y=f.default(d.default(v).filter((function(e){return null!==e})),(function(e){return e}));return{all:y,min:Math.min.apply(Math,y),max:Math.max.apply(Math,y)};case"time":var h=l.default(v,(function(e){return e.getTime()})).slice(0).sort((function(e,t){return t.getTime()-e.getTime()})).reverse();return{all:h,min:h[0],max:m.default(h)};default:var p=d.default(v);return{all:p,min:p[0],max:m.default(p)}}},A=function(e,t,n){var a=D(e),r=[];t[a].all.forEach((function(t){var i=v.default(t)?B:C,o=[];n.forEach((function(n){var u=n.data.find((function(e){return i(e.data[a],t)})),c=null,s=null;if(void 0!==u){if(null!==(c=u.data[e])){var d=m.default(o);void 0===d?s=c:null!==d&&(s=d+c)}u.data["x"===e?"xStacked":"yStacked"]=s}o.push(s),null!==s&&r.push(s)}))})),t[e].minStacked=Math.min.apply(Math,r),t[e].maxStacked=Math.max.apply(Math,r)},F=function(e,t){return A("x",e,t)},H=function(e,t){return A("y",e,t)},L=c.timeInterval((function(e){return e.setHours(0,0,0,0)}),(function(e,t){return e.setDate(e.getDate()+t)}),(function(e,t){return(t.getTime()-e.getTime())/864e5}),(function(e){return Math.floor(e.getTime()/864e5)})),V=c.timeInterval((function(e){return e.setUTCHours(0,0,0,0)}),(function(e,t){return e.setUTCDate(e.getUTCDate()+t)}),(function(e,t){return(t.getTime()-e.getTime())/864e5}),(function(e){return Math.floor(e.getTime()/864e5)})),R={millisecond:[c.timeMillisecond,c.utcMillisecond],second:[c.timeSecond,c.utcSecond],minute:[c.timeMinute,c.utcMinute],hour:[c.timeHour,c.utcHour],day:[L,V],week:[c.timeWeek,c.utcWeek],sunday:[c.timeSunday,c.utcSunday],monday:[c.timeMonday,c.utcMonday],tuesday:[c.timeTuesday,c.utcTuesday],wednesday:[c.timeWednesday,c.utcWednesday],thursday:[c.timeThursday,c.utcThursday],friday:[c.timeFriday,c.utcFriday],saturday:[c.timeSaturday,c.utcSaturday],month:[c.timeMonth,c.utcMonth],year:[c.timeYear,c.utcYear]},W=Object.keys(R),Y=new RegExp("^every\\s*(\\d+)?\\s*("+W.join("|")+")s?$","i");e.castBandScale=b,e.castLinearScale=T,e.centerScale=function(e){var t=e.bandwidth();if(0===t)return e;var n=t/2;return e.round()&&(n=Math.round(n)),function(t){var a;return(null!=(a=e(t))?a:0)+n}},e.compareDateValues=B,e.compareValues=C,e.computeScale=U,e.computeXYScalesForSeries=function(e,t,n,a,r){var i=e.map((function(e){return function(e){return y({},e,{data:e.data.map((function(e){return{data:y({},e)}}))})}(e)})),o=O(i,t,n);"stacked"in t&&!0===t.stacked&&F(o,i),"stacked"in n&&!0===n.stacked&&H(o,i);var u=U(t,o.x,a,"x"),c=U(n,o.y,r,"y"),s=i.map((function(e){return y({},e,{data:e.data.map((function(e){return y({},e,{position:{x:j(e,"x",u),y:j(e,"y",c)}})}))})}));return y({},o,{series:s,xScale:u,yScale:c})},e.createBandScale=M,e.createDateNormalizer=x,e.createLinearScale=S,e.createLogScale=E,e.createPointScale=k,e.createPrecisionMethod=g,e.createSymlogScale=q,e.createTimeScale=w,e.generateSeriesAxis=P,e.generateSeriesXY=O,e.getOtherAxis=D,e.getScaleTicks=function(e,t){if(Array.isArray(t))return t;if("string"==typeof t&&"useUTC"in e){var n=t.match(Y);if(n){var a=n[1],r=n[2],i=R[r][e.useUTC?1:0];if("day"===r){var o,u,c=e.domain(),s=c[0],d=c[1],l=new Date(d);return l.setDate(l.getDate()+1),null!=(o=null==(u=i.every(Number(null!=a?a:1)))?void 0:u.range(s,l))?o:[]}if(void 0===a)return e.ticks(i);var f=i.every(Number(a));if(f)return e.ticks(f)}throw new Error("Invalid tickValues: "+t)}if("ticks"in e){if(void 0===t)return e.ticks();if("number"==typeof(m=t)&&isFinite(m)&&Math.floor(m)===m)return e.ticks(t)}var m;return e.domain()},e.precisionCutOffs=h,e.precisionCutOffsByType=p,e.stackAxis=A,e.timePrecisions=["millisecond","second","minute","hour","day","month","year"],Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=nivo-scales.umd.js.map

2

dist/types/timeHelpers.d.ts

@@ -8,5 +8,5 @@ export declare const timePrecisions: readonly ["millisecond", "second", "minute", "hour", "day", "month", "year"];

format?: string | undefined;
precision?: "millisecond" | "second" | "minute" | "hour" | "day" | "month" | "year" | undefined;
precision?: "month" | "millisecond" | "second" | "minute" | "hour" | "day" | "year" | undefined;
useUTC?: boolean | undefined;
}) => (value: Date | string | undefined) => Date | undefined;
//# sourceMappingURL=timeHelpers.d.ts.map
{
"name": "@nivo/scales",
"version": "0.74.0",
"version": "0.75.0",
"license": "MIT",

@@ -37,3 +37,3 @@ "author": {

},
"gitHead": "5d387c6723bb384f276d2b6ce15ca49c0e49948a"
"gitHead": "bfe8126876bf0e46ad82251935ab78178e901bcf"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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