Socket
Socket
Sign inDemoInstall

@nivo/scales

Package Overview
Dependencies
Maintainers
2
Versions
49
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.70.0 to 0.71.0

dist/types/symlogScale.d.ts

670

dist/nivo-scales.cjs.js

@@ -7,5 +7,2 @@ 'use strict';

var PropTypes = _interopDefault(require('prop-types'));
var d3Scale = require('d3-scale');
var d3TimeFormat = require('d3-time-format');
var uniq = _interopDefault(require('lodash/uniq'));

@@ -16,133 +13,38 @@ var uniqBy = _interopDefault(require('lodash/uniqBy'));

var isDate = _interopDefault(require('lodash/isDate'));
var d3TimeFormat = require('d3-time-format');
var d3Scale = require('d3-scale');
var linearScale = function linearScale(_ref, xy, width, height) {
var axis = _ref.axis,
_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 values = xy[axis];
var size = axis === 'x' ? width : height;
var minValue = min;
if (min === 'auto') {
minValue = stacked === true ? values.minStacked : values.min;
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];
}
var maxValue = max;
if (max === 'auto') {
maxValue = stacked === true ? values.maxStacked : values.max;
}
var scale = d3Scale.scaleLinear().rangeRound(axis === 'x' ? [0, size] : [size, 0]);
if (reverse === true) scale.domain([maxValue, minValue]);else scale.domain([minValue, maxValue]);
if (nice === true) scale.nice();else if (typeof nice === 'number') scale.nice(nice);
scale.type = 'linear';
scale.stacked = stacked;
scale.clamp(clamp);
return scale;
};
var linearScalePropTypes = {
type: PropTypes.oneOf(['linear']).isRequired,
min: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
max: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
stacked: PropTypes.bool,
reverse: PropTypes.bool,
clamp: PropTypes.bool,
nice: PropTypes.oneOfType([PropTypes.number, PropTypes.bool])
};
return arr2;
}
var logScale = function logScale(_ref, xy, width, height) {
var axis = _ref.axis,
_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 values = xy[axis];
var size = axis === 'x' ? width : height;
var hasZero = values.all.some(function (v) {
return v === 0;
});
var sign;
var hasMixedSign = false;
values.all.filter(function (v) {
return v != null;
}).forEach(function (v) {
if (hasMixedSign === true) return;
if (sign === undefined) {
sign = Math.sign(v);
} else if (Math.sign(v) !== sign) {
hasMixedSign = true;
}
});
if (hasZero || hasMixedSign) {
throw new Error(["a log scale domain must be strictly-positive or strictly-negative,", "and must not include or cross zero."].join('\n'));
}
var minValue = min;
if (min === 'auto') {
minValue = values.min;
}
var maxValue = max;
if (max === 'auto') {
maxValue = values.max;
}
var scale = d3Scale.scaleLog().domain([minValue, maxValue]).rangeRound(axis === 'x' ? [0, size] : [size, 0]).base(base).nice();
scale.type = 'log';
return scale;
};
var logScalePropTypes = {
type: PropTypes.oneOf(['log']).isRequired,
base: PropTypes.number,
min: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
max: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number])
};
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
var symlogScale = function symlogScale(_ref, xy, width, height) {
var axis = _ref.axis,
_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;
var values = xy[axis];
var size = axis === 'x' ? width : height;
var minValue = min;
if (min === 'auto') {
minValue = values.min;
}
var maxValue = max;
if (max === 'auto') {
maxValue = values.max;
}
var scale = d3Scale.scaleSymlog().domain([minValue, maxValue]).constant(constant).rangeRound(axis === 'x' ? [0, size] : [size, 0]).nice();
scale.type = 'symlog';
return scale;
};
var symLogScalePropTypes = {
type: PropTypes.oneOf(['symlog']).isRequired,
constant: PropTypes.number,
min: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
max: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number])
};
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
}
var pointScale = function pointScale(_ref, xy, width, height) {
var axis = _ref.axis;
var values = xy[axis];
var size = axis === 'x' ? width : height;
var scale = d3Scale.scalePoint().range([0, size]).domain(values.all);
scale.type = 'point';
return scale;
};
var pointScalePropTypes = {
type: PropTypes.oneOf(['point']).isRequired
};
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(n);
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) {

@@ -162,11 +64,32 @@ if (key in obj) {

var _precisionCutOffsByTy;
var TIME_PRECISION_MILLISECOND = 'millisecond';
var TIME_PRECISION_SECOND = 'second';
var TIME_PRECISION_MINUTE = 'minute';
var TIME_PRECISION_HOUR = 'hour';
var TIME_PRECISION_DAY = 'day';
var TIME_PRECISION_MONTH = 'month';
var TIME_PRECISION_YEAR = 'year';
var timePrecisions = [TIME_PRECISION_MILLISECOND, TIME_PRECISION_SECOND, TIME_PRECISION_MINUTE, TIME_PRECISION_HOUR, TIME_PRECISION_DAY, TIME_PRECISION_MONTH, TIME_PRECISION_YEAR];
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) {

@@ -185,3 +108,11 @@ return date.setMilliseconds(0);

}];
var precisionCutOffsByType = (_precisionCutOffsByTy = {}, _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_MILLISECOND, []), _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_SECOND, precisionCutOffs.slice(0, 1)), _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_MINUTE, precisionCutOffs.slice(0, 2)), _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_HOUR, precisionCutOffs.slice(0, 3)), _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_DAY, precisionCutOffs.slice(0, 4)), _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_MONTH, precisionCutOffs.slice(0, 5)), _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_YEAR, precisionCutOffs.slice(0, 6)), _precisionCutOffsByTy);
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) {

@@ -203,17 +134,74 @@ return function (date) {

var precisionFn = createPrecisionMethod(precision);
if (format === 'native') return function (v) {
return precisionFn(v);
return function (value) {
if (format === 'native' || value instanceof Date) {
return precisionFn(value);
}
var parseTime = useUTC ? d3TimeFormat.utcParse(format) : d3TimeFormat.timeParse(format);
return precisionFn(parseTime(value));
};
var parseTime = useUTC ? d3TimeFormat.utcParse(format) : d3TimeFormat.timeParse(format);
return function (v) {
return precisionFn(parseTime(v));
};
};
var timeScale = function timeScale(_ref, xy, width, height) {
var axis = _ref.axis,
_ref$format = _ref.format,
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);
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);
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 ? TIME_PRECISION_MILLISECOND : _ref$precision,
precision = _ref$precision === void 0 ? 'millisecond' : _ref$precision,
_ref$min = _ref.min,

@@ -227,4 +215,2 @@ min = _ref$min === void 0 ? 'auto' : _ref$min,

nice = _ref$nice === void 0 ? false : _ref$nice;
var values = xy[axis];
var size = axis === 'x' ? width : height;
var normalize = createDateNormalizer({

@@ -235,95 +221,118 @@ format: format,

});
var minValue = min;
var minValue;
if (min === 'auto') {
minValue = values.min;
minValue = normalize(data.min);
} else if (format !== 'native') {
minValue = normalize(min);
} else {
minValue = min;
}
var maxValue = max;
var maxValue;
if (max === 'auto') {
maxValue = values.max;
maxValue = normalize(data.max);
} else if (format !== 'native') {
maxValue = normalize(max);
} else {
maxValue = max;
}
var scale = useUTC ? d3Scale.scaleUtc() : d3Scale.scaleTime();
scale.domain([minValue, maxValue]).range([0, size]);
if (nice === true) scale.nice();else if (typeof nice === 'object' || typeof nice === 'number') scale.nice(nice);
scale.type = 'time';
scale.useUTC = useUTC;
return scale;
var typedScale = scale;
typedScale.type = 'time';
typedScale.useUTC = useUTC;
return typedScale;
};
var timeScalePropTypes = {
type: PropTypes.oneOf(['time']).isRequired,
format: PropTypes.string,
precision: PropTypes.oneOf(timePrecisions),
nice: PropTypes.oneOfType([PropTypes.bool, PropTypes.number, PropTypes.object])
};
var bandScalePropTypes = {
type: PropTypes.oneOf(['band']).isRequired,
round: PropTypes.bool
};
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;
});
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];
if (hasZero) {
throw new Error("a log scale domain must not include or cross zero");
}
return arr2;
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
var sign;
var hasMixedSign = false;
data.all.filter(function (v) {
return v != null;
}).forEach(function (v) {
if (hasMixedSign) return;
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
}
if (sign === undefined) {
sign = Math.sign(v);
} else if (Math.sign(v) !== sign) {
hasMixedSign = true;
}
});
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(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
if (hasMixedSign) {
throw new Error("a log scale domain must be strictly-positive or strictly-negative");
}
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.");
}
var minValue;
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
if (min === 'auto') {
minValue = data.min;
} else {
minValue = min;
}
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);
var maxValue;
if (max === 'auto') {
maxValue = data.max;
} else {
maxValue = max;
}
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));
});
}
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;
}
return target;
}
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) {

@@ -338,2 +347,26 @@ return axis === 'x' ? 'y' : 'x';

};
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 computeXYScalesForSeries = function computeXYScalesForSeries(_series, xScaleSpec, yScaleSpec, width, height) {

@@ -349,20 +382,22 @@ var series = _series.map(function (serie) {

});
var xy = generateSeriesXY(series, xScaleSpec, yScaleSpec);
if (xScaleSpec.stacked === true) {
stackX(yScaleSpec.type, xy, series);
if ('stacked' in xScaleSpec && xScaleSpec.stacked === true) {
stackX(xy, series);
}
if (yScaleSpec.stacked === true) {
stackY(xScaleSpec.type, xy, series);
if ('stacked' in yScaleSpec && yScaleSpec.stacked === true) {
stackY(xy, series);
}
var xScale = computeScale(_objectSpread2(_objectSpread2({}, xScaleSpec), {}, {
axis: 'x'
}), xy, width, height);
var yScale = computeScale(_objectSpread2(_objectSpread2({}, yScaleSpec), {}, {
axis: 'y'
}), xy, width, height);
var xScale = computeScale(xScaleSpec, xy.x, width, 'x');
var yScale = computeScale(yScaleSpec, xy.y, height, 'y');
series.forEach(function (serie) {
serie.data.forEach(function (d) {
var _xScale, _yScale;
d.position = {
x: xScale.stacked === true ? d.data.xStacked === null ? null : xScale(d.data.xStacked) : d.data.x === null ? null : xScale(d.data.x),
y: yScale.stacked === true ? d.data.yStacked === null ? null : yScale(d.data.yStacked) : d.data.y === null ? null : yScale(d.data.y)
x: 'stacked' in xScale && xScale.stacked === true ? d.data.xStacked === null ? null : xScale(d.data.xStacked) : d.data.x === null ? null : (_xScale = xScale(d.data.x)) !== null && _xScale !== void 0 ? _xScale : null,
y: 'stacked' in yScale && yScale.stacked === true ? d.data.yStacked === null ? null : yScale(d.data.yStacked) : d.data.y === null ? null : (_yScale = yScale(d.data.y)) !== null && _yScale !== void 0 ? _yScale : null
};

@@ -377,5 +412,2 @@ });

};
var computeScale = function computeScale(spec, xy, width, height) {
if (spec.type === 'linear') return linearScale(spec, xy, width, height);else if (spec.type === 'point') return pointScale(spec, xy, width, height);else if (spec.type === 'time') return timeScale(spec, xy, width, height);else if (spec.type === 'log') return logScale(spec, xy, width, height);else if (spec.type === 'symlog') return symlogScale(spec, xy, width, height);
};
var generateSeriesXY = function generateSeriesXY(series, xScaleSpec, yScaleSpec) {

@@ -397,6 +429,11 @@ return {

} : _ref$setValue;
if (scaleSpec.type === 'linear') {
series.forEach(function (serie) {
serie.data.forEach(function (d) {
setValue(d, getValue(d) === null ? null : parseFloat(getValue(d)));
var value = getValue(d);
if (value) {
setValue(d, parseFloat(String(value)));
}
});

@@ -408,41 +445,59 @@ });

serie.data.forEach(function (d) {
setValue(d, getValue(d) === null ? null : parseTime(getValue(d)));
var value = getValue(d);
if (value) {
setValue(d, parseTime(value));
}
});
});
}
var all = [];
var values = [];
series.forEach(function (serie) {
serie.data.forEach(function (d) {
all.push(getValue(d));
values.push(getValue(d));
});
});
var min, max;
if (scaleSpec.type === 'linear') {
all = uniq(all);
all = sortBy(all, function (v) {
return v;
});
min = Math.min.apply(Math, _toConsumableArray(all));
max = Math.max.apply(Math, _toConsumableArray(all));
} else if (scaleSpec.type === 'time') {
all = uniqBy(all, function (v) {
return v.getTime();
});
all = all.slice(0).sort(function (a, b) {
return b - a;
}).reverse();
min = all[0];
max = last(all);
} else {
all = uniq(all);
min = all[0];
max = last(all);
switch (scaleSpec.type) {
case 'linear':
{
var all = sortBy(uniq(values), 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)
};
}
}
return {
all: all,
min: min,
max: max
};
};
var stackAxis = function stackAxis(axis, otherType, xy, series) {
var stackAxis = function stackAxis(axis, xy, series) {
var otherAxis = getOtherAxis(axis);

@@ -459,6 +514,9 @@ var all = [];

var stackValue = null;
if (datum !== undefined) {
value = datum.data[axis];
if (value !== null) {
var head = last(stack);
if (head === undefined) {

@@ -470,88 +528,44 @@ stackValue = value;

}
datum.data["".concat(axis, "Stacked")] = stackValue;
}
stack.push(stackValue);
all.push(stackValue);
});
});
all = all.filter(function (v) {
return v !== null;
});
xy[axis].minStacked = Math.min.apply(Math, _toConsumableArray(all));
xy[axis].maxStacked = Math.max.apply(Math, _toConsumableArray(all));
};
var stackX = function stackX(xy, otherType, series) {
return stackAxis('x', xy, otherType, series);
};
var stackY = function stackY(xy, otherType, series) {
return stackAxis('y', xy, otherType, series);
};
var computeAxisSlices = function computeAxisSlices(axis, data) {
var otherAxis = getOtherAxis(axis);
return data[otherAxis].all.map(function (v) {
var _slice;
var slice = (_slice = {
id: v
}, _defineProperty(_slice, otherAxis, data["".concat(otherAxis, "Scale")](v)), _defineProperty(_slice, "data", []), _slice);
var compare = isDate(v) ? compareDateValues : compareValues;
data.series.forEach(function (serie) {
var datum = serie.data.find(function (d) {
return compare(d.data[otherAxis], v);
});
if (datum !== undefined) {
slice.data.push(_objectSpread2(_objectSpread2({}, datum), {}, {
serie: serie
}));
if (stackValue !== null) {
all.push(stackValue);
}
});
slice.data.reverse();
return slice;
});
xy[axis].minStacked = Math.min.apply(Math, all);
xy[axis].maxStacked = Math.max.apply(Math, all);
};
var computeXSlices = function computeXSlices(data) {
return computeAxisSlices('x', data);
var stackX = function stackX(xy, series) {
return stackAxis('x', xy, series);
};
var computeYSlices = function computeYSlices(data) {
return computeAxisSlices('y', data);
var stackY = function stackY(xy, series) {
return stackAxis('y', xy, series);
};
var scalePropType = PropTypes.oneOfType([PropTypes.shape(linearScalePropTypes), PropTypes.shape(pointScalePropTypes), PropTypes.shape(timeScalePropTypes), PropTypes.shape(logScalePropTypes), PropTypes.shape(symLogScalePropTypes), PropTypes.shape(bandScalePropTypes)]);
exports.TIME_PRECISION_DAY = TIME_PRECISION_DAY;
exports.TIME_PRECISION_HOUR = TIME_PRECISION_HOUR;
exports.TIME_PRECISION_MILLISECOND = TIME_PRECISION_MILLISECOND;
exports.TIME_PRECISION_MINUTE = TIME_PRECISION_MINUTE;
exports.TIME_PRECISION_MONTH = TIME_PRECISION_MONTH;
exports.TIME_PRECISION_SECOND = TIME_PRECISION_SECOND;
exports.TIME_PRECISION_YEAR = TIME_PRECISION_YEAR;
exports.bandScalePropTypes = bandScalePropTypes;
exports.compareDateValues = compareDateValues;
exports.compareValues = compareValues;
exports.computeAxisSlices = computeAxisSlices;
exports.computeScale = computeScale;
exports.computeXSlices = computeXSlices;
exports.computeXYScalesForSeries = computeXYScalesForSeries;
exports.computeYSlices = computeYSlices;
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.linearScale = linearScale;
exports.linearScalePropTypes = linearScalePropTypes;
exports.logScale = logScale;
exports.logScalePropTypes = logScalePropTypes;
exports.pointScale = pointScale;
exports.pointScalePropTypes = pointScalePropTypes;
exports.precisionCutOffs = precisionCutOffs;
exports.precisionCutOffsByType = precisionCutOffsByType;
exports.scalePropType = scalePropType;
exports.stackAxis = stackAxis;
exports.stackX = stackX;
exports.stackY = stackY;
exports.symLogScalePropTypes = symLogScalePropTypes;
exports.symlogScale = symlogScale;
exports.timePrecisions = timePrecisions;
exports.timeScale = timeScale;
exports.timeScalePropTypes = timeScalePropTypes;
//# sourceMappingURL=nivo-scales.cjs.js.map

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

import PropTypes from 'prop-types';
import { scaleLinear, scaleLog, scaleSymlog, scalePoint, scaleUtc, scaleTime } from 'd3-scale';
import { utcParse, timeParse } from 'd3-time-format';
import uniq from 'lodash/uniq';

@@ -9,133 +6,38 @@ import uniqBy from 'lodash/uniqBy';

import isDate from 'lodash/isDate';
import { utcParse, timeParse } from 'd3-time-format';
import { scaleLinear, scalePoint, scaleBand, scaleUtc, scaleTime, scaleLog, scaleSymlog } from 'd3-scale';
var linearScale = function linearScale(_ref, xy, width, height) {
var axis = _ref.axis,
_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 values = xy[axis];
var size = axis === 'x' ? width : height;
var minValue = min;
if (min === 'auto') {
minValue = stacked === true ? values.minStacked : values.min;
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];
}
var maxValue = max;
if (max === 'auto') {
maxValue = stacked === true ? values.maxStacked : values.max;
}
var scale = scaleLinear().rangeRound(axis === 'x' ? [0, size] : [size, 0]);
if (reverse === true) scale.domain([maxValue, minValue]);else scale.domain([minValue, maxValue]);
if (nice === true) scale.nice();else if (typeof nice === 'number') scale.nice(nice);
scale.type = 'linear';
scale.stacked = stacked;
scale.clamp(clamp);
return scale;
};
var linearScalePropTypes = {
type: PropTypes.oneOf(['linear']).isRequired,
min: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
max: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
stacked: PropTypes.bool,
reverse: PropTypes.bool,
clamp: PropTypes.bool,
nice: PropTypes.oneOfType([PropTypes.number, PropTypes.bool])
};
return arr2;
}
var logScale = function logScale(_ref, xy, width, height) {
var axis = _ref.axis,
_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 values = xy[axis];
var size = axis === 'x' ? width : height;
var hasZero = values.all.some(function (v) {
return v === 0;
});
var sign;
var hasMixedSign = false;
values.all.filter(function (v) {
return v != null;
}).forEach(function (v) {
if (hasMixedSign === true) return;
if (sign === undefined) {
sign = Math.sign(v);
} else if (Math.sign(v) !== sign) {
hasMixedSign = true;
}
});
if (hasZero || hasMixedSign) {
throw new Error(["a log scale domain must be strictly-positive or strictly-negative,", "and must not include or cross zero."].join('\n'));
}
var minValue = min;
if (min === 'auto') {
minValue = values.min;
}
var maxValue = max;
if (max === 'auto') {
maxValue = values.max;
}
var scale = scaleLog().domain([minValue, maxValue]).rangeRound(axis === 'x' ? [0, size] : [size, 0]).base(base).nice();
scale.type = 'log';
return scale;
};
var logScalePropTypes = {
type: PropTypes.oneOf(['log']).isRequired,
base: PropTypes.number,
min: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
max: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number])
};
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
var symlogScale = function symlogScale(_ref, xy, width, height) {
var axis = _ref.axis,
_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;
var values = xy[axis];
var size = axis === 'x' ? width : height;
var minValue = min;
if (min === 'auto') {
minValue = values.min;
}
var maxValue = max;
if (max === 'auto') {
maxValue = values.max;
}
var scale = scaleSymlog().domain([minValue, maxValue]).constant(constant).rangeRound(axis === 'x' ? [0, size] : [size, 0]).nice();
scale.type = 'symlog';
return scale;
};
var symLogScalePropTypes = {
type: PropTypes.oneOf(['symlog']).isRequired,
constant: PropTypes.number,
min: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
max: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number])
};
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
}
var pointScale = function pointScale(_ref, xy, width, height) {
var axis = _ref.axis;
var values = xy[axis];
var size = axis === 'x' ? width : height;
var scale = scalePoint().range([0, size]).domain(values.all);
scale.type = 'point';
return scale;
};
var pointScalePropTypes = {
type: PropTypes.oneOf(['point']).isRequired
};
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(n);
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) {

@@ -155,11 +57,32 @@ if (key in obj) {

var _precisionCutOffsByTy;
var TIME_PRECISION_MILLISECOND = 'millisecond';
var TIME_PRECISION_SECOND = 'second';
var TIME_PRECISION_MINUTE = 'minute';
var TIME_PRECISION_HOUR = 'hour';
var TIME_PRECISION_DAY = 'day';
var TIME_PRECISION_MONTH = 'month';
var TIME_PRECISION_YEAR = 'year';
var timePrecisions = [TIME_PRECISION_MILLISECOND, TIME_PRECISION_SECOND, TIME_PRECISION_MINUTE, TIME_PRECISION_HOUR, TIME_PRECISION_DAY, TIME_PRECISION_MONTH, TIME_PRECISION_YEAR];
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) {

@@ -178,3 +101,11 @@ return date.setMilliseconds(0);

}];
var precisionCutOffsByType = (_precisionCutOffsByTy = {}, _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_MILLISECOND, []), _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_SECOND, precisionCutOffs.slice(0, 1)), _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_MINUTE, precisionCutOffs.slice(0, 2)), _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_HOUR, precisionCutOffs.slice(0, 3)), _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_DAY, precisionCutOffs.slice(0, 4)), _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_MONTH, precisionCutOffs.slice(0, 5)), _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_YEAR, precisionCutOffs.slice(0, 6)), _precisionCutOffsByTy);
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) {

@@ -196,17 +127,74 @@ return function (date) {

var precisionFn = createPrecisionMethod(precision);
if (format === 'native') return function (v) {
return precisionFn(v);
return function (value) {
if (format === 'native' || value instanceof Date) {
return precisionFn(value);
}
var parseTime = useUTC ? utcParse(format) : timeParse(format);
return precisionFn(parseTime(value));
};
var parseTime = useUTC ? utcParse(format) : timeParse(format);
return function (v) {
return precisionFn(parseTime(v));
};
};
var timeScale = function timeScale(_ref, xy, width, height) {
var axis = _ref.axis,
_ref$format = _ref.format,
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);
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);
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 ? TIME_PRECISION_MILLISECOND : _ref$precision,
precision = _ref$precision === void 0 ? 'millisecond' : _ref$precision,
_ref$min = _ref.min,

@@ -220,4 +208,2 @@ min = _ref$min === void 0 ? 'auto' : _ref$min,

nice = _ref$nice === void 0 ? false : _ref$nice;
var values = xy[axis];
var size = axis === 'x' ? width : height;
var normalize = createDateNormalizer({

@@ -228,95 +214,118 @@ format: format,

});
var minValue = min;
var minValue;
if (min === 'auto') {
minValue = values.min;
minValue = normalize(data.min);
} else if (format !== 'native') {
minValue = normalize(min);
} else {
minValue = min;
}
var maxValue = max;
var maxValue;
if (max === 'auto') {
maxValue = values.max;
maxValue = normalize(data.max);
} else if (format !== 'native') {
maxValue = normalize(max);
} else {
maxValue = max;
}
var scale = useUTC ? scaleUtc() : scaleTime();
scale.domain([minValue, maxValue]).range([0, size]);
if (nice === true) scale.nice();else if (typeof nice === 'object' || typeof nice === 'number') scale.nice(nice);
scale.type = 'time';
scale.useUTC = useUTC;
return scale;
var typedScale = scale;
typedScale.type = 'time';
typedScale.useUTC = useUTC;
return typedScale;
};
var timeScalePropTypes = {
type: PropTypes.oneOf(['time']).isRequired,
format: PropTypes.string,
precision: PropTypes.oneOf(timePrecisions),
nice: PropTypes.oneOfType([PropTypes.bool, PropTypes.number, PropTypes.object])
};
var bandScalePropTypes = {
type: PropTypes.oneOf(['band']).isRequired,
round: PropTypes.bool
};
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;
});
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];
if (hasZero) {
throw new Error("a log scale domain must not include or cross zero");
}
return arr2;
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
var sign;
var hasMixedSign = false;
data.all.filter(function (v) {
return v != null;
}).forEach(function (v) {
if (hasMixedSign) return;
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
}
if (sign === undefined) {
sign = Math.sign(v);
} else if (Math.sign(v) !== sign) {
hasMixedSign = true;
}
});
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(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
if (hasMixedSign) {
throw new Error("a log scale domain must be strictly-positive or strictly-negative");
}
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.");
}
var minValue;
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
if (min === 'auto') {
minValue = data.min;
} else {
minValue = min;
}
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);
var maxValue;
if (max === 'auto') {
maxValue = data.max;
} else {
maxValue = max;
}
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));
});
}
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;
}
return target;
}
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) {

@@ -331,2 +340,26 @@ return axis === 'x' ? 'y' : 'x';

};
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 computeXYScalesForSeries = function computeXYScalesForSeries(_series, xScaleSpec, yScaleSpec, width, height) {

@@ -342,20 +375,22 @@ var series = _series.map(function (serie) {

});
var xy = generateSeriesXY(series, xScaleSpec, yScaleSpec);
if (xScaleSpec.stacked === true) {
stackX(yScaleSpec.type, xy, series);
if ('stacked' in xScaleSpec && xScaleSpec.stacked === true) {
stackX(xy, series);
}
if (yScaleSpec.stacked === true) {
stackY(xScaleSpec.type, xy, series);
if ('stacked' in yScaleSpec && yScaleSpec.stacked === true) {
stackY(xy, series);
}
var xScale = computeScale(_objectSpread2(_objectSpread2({}, xScaleSpec), {}, {
axis: 'x'
}), xy, width, height);
var yScale = computeScale(_objectSpread2(_objectSpread2({}, yScaleSpec), {}, {
axis: 'y'
}), xy, width, height);
var xScale = computeScale(xScaleSpec, xy.x, width, 'x');
var yScale = computeScale(yScaleSpec, xy.y, height, 'y');
series.forEach(function (serie) {
serie.data.forEach(function (d) {
var _xScale, _yScale;
d.position = {
x: xScale.stacked === true ? d.data.xStacked === null ? null : xScale(d.data.xStacked) : d.data.x === null ? null : xScale(d.data.x),
y: yScale.stacked === true ? d.data.yStacked === null ? null : yScale(d.data.yStacked) : d.data.y === null ? null : yScale(d.data.y)
x: 'stacked' in xScale && xScale.stacked === true ? d.data.xStacked === null ? null : xScale(d.data.xStacked) : d.data.x === null ? null : (_xScale = xScale(d.data.x)) !== null && _xScale !== void 0 ? _xScale : null,
y: 'stacked' in yScale && yScale.stacked === true ? d.data.yStacked === null ? null : yScale(d.data.yStacked) : d.data.y === null ? null : (_yScale = yScale(d.data.y)) !== null && _yScale !== void 0 ? _yScale : null
};

@@ -370,5 +405,2 @@ });

};
var computeScale = function computeScale(spec, xy, width, height) {
if (spec.type === 'linear') return linearScale(spec, xy, width, height);else if (spec.type === 'point') return pointScale(spec, xy, width, height);else if (spec.type === 'time') return timeScale(spec, xy, width, height);else if (spec.type === 'log') return logScale(spec, xy, width, height);else if (spec.type === 'symlog') return symlogScale(spec, xy, width, height);
};
var generateSeriesXY = function generateSeriesXY(series, xScaleSpec, yScaleSpec) {

@@ -390,6 +422,11 @@ return {

} : _ref$setValue;
if (scaleSpec.type === 'linear') {
series.forEach(function (serie) {
serie.data.forEach(function (d) {
setValue(d, getValue(d) === null ? null : parseFloat(getValue(d)));
var value = getValue(d);
if (value) {
setValue(d, parseFloat(String(value)));
}
});

@@ -401,41 +438,59 @@ });

serie.data.forEach(function (d) {
setValue(d, getValue(d) === null ? null : parseTime(getValue(d)));
var value = getValue(d);
if (value) {
setValue(d, parseTime(value));
}
});
});
}
var all = [];
var values = [];
series.forEach(function (serie) {
serie.data.forEach(function (d) {
all.push(getValue(d));
values.push(getValue(d));
});
});
var min, max;
if (scaleSpec.type === 'linear') {
all = uniq(all);
all = sortBy(all, function (v) {
return v;
});
min = Math.min.apply(Math, _toConsumableArray(all));
max = Math.max.apply(Math, _toConsumableArray(all));
} else if (scaleSpec.type === 'time') {
all = uniqBy(all, function (v) {
return v.getTime();
});
all = all.slice(0).sort(function (a, b) {
return b - a;
}).reverse();
min = all[0];
max = last(all);
} else {
all = uniq(all);
min = all[0];
max = last(all);
switch (scaleSpec.type) {
case 'linear':
{
var all = sortBy(uniq(values), 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)
};
}
}
return {
all: all,
min: min,
max: max
};
};
var stackAxis = function stackAxis(axis, otherType, xy, series) {
var stackAxis = function stackAxis(axis, xy, series) {
var otherAxis = getOtherAxis(axis);

@@ -452,6 +507,9 @@ var all = [];

var stackValue = null;
if (datum !== undefined) {
value = datum.data[axis];
if (value !== null) {
var head = last(stack);
if (head === undefined) {

@@ -463,52 +521,26 @@ stackValue = value;

}
datum.data["".concat(axis, "Stacked")] = stackValue;
}
stack.push(stackValue);
all.push(stackValue);
});
});
all = all.filter(function (v) {
return v !== null;
});
xy[axis].minStacked = Math.min.apply(Math, _toConsumableArray(all));
xy[axis].maxStacked = Math.max.apply(Math, _toConsumableArray(all));
};
var stackX = function stackX(xy, otherType, series) {
return stackAxis('x', xy, otherType, series);
};
var stackY = function stackY(xy, otherType, series) {
return stackAxis('y', xy, otherType, series);
};
var computeAxisSlices = function computeAxisSlices(axis, data) {
var otherAxis = getOtherAxis(axis);
return data[otherAxis].all.map(function (v) {
var _slice;
var slice = (_slice = {
id: v
}, _defineProperty(_slice, otherAxis, data["".concat(otherAxis, "Scale")](v)), _defineProperty(_slice, "data", []), _slice);
var compare = isDate(v) ? compareDateValues : compareValues;
data.series.forEach(function (serie) {
var datum = serie.data.find(function (d) {
return compare(d.data[otherAxis], v);
});
if (datum !== undefined) {
slice.data.push(_objectSpread2(_objectSpread2({}, datum), {}, {
serie: serie
}));
if (stackValue !== null) {
all.push(stackValue);
}
});
slice.data.reverse();
return slice;
});
xy[axis].minStacked = Math.min.apply(Math, all);
xy[axis].maxStacked = Math.max.apply(Math, all);
};
var computeXSlices = function computeXSlices(data) {
return computeAxisSlices('x', data);
var stackX = function stackX(xy, series) {
return stackAxis('x', xy, series);
};
var computeYSlices = function computeYSlices(data) {
return computeAxisSlices('y', data);
var stackY = function stackY(xy, series) {
return stackAxis('y', xy, series);
};
var scalePropType = PropTypes.oneOfType([PropTypes.shape(linearScalePropTypes), PropTypes.shape(pointScalePropTypes), PropTypes.shape(timeScalePropTypes), PropTypes.shape(logScalePropTypes), PropTypes.shape(symLogScalePropTypes), PropTypes.shape(bandScalePropTypes)]);
export { TIME_PRECISION_DAY, TIME_PRECISION_HOUR, TIME_PRECISION_MILLISECOND, TIME_PRECISION_MINUTE, TIME_PRECISION_MONTH, TIME_PRECISION_SECOND, TIME_PRECISION_YEAR, bandScalePropTypes, compareDateValues, compareValues, computeAxisSlices, computeScale, computeXSlices, computeXYScalesForSeries, computeYSlices, createDateNormalizer, createPrecisionMethod, generateSeriesAxis, generateSeriesXY, getOtherAxis, linearScale, linearScalePropTypes, logScale, logScalePropTypes, pointScale, pointScalePropTypes, precisionCutOffs, precisionCutOffsByType, scalePropType, stackAxis, stackX, stackY, symLogScalePropTypes, symlogScale, timePrecisions, timeScale, timeScalePropTypes };
export { compareDateValues, compareValues, computeScale, computeXYScalesForSeries, createBandScale, createDateNormalizer, createLinearScale, createLogScale, createPointScale, createPrecisionMethod, createSymlogScale, createTimeScale, generateSeriesAxis, generateSeriesXY, getOtherAxis, precisionCutOffs, precisionCutOffsByType, stackAxis, timePrecisions };
//# sourceMappingURL=nivo-scales.es.js.map
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('prop-types'), require('d3-scale'), require('d3-time-format'), require('lodash/uniq'), require('lodash/uniqBy'), require('lodash/sortBy'), require('lodash/last'), require('lodash/isDate')) :
typeof define === 'function' && define.amd ? define(['exports', 'prop-types', 'd3-scale', 'd3-time-format', 'lodash/uniq', 'lodash/uniqBy', 'lodash/sortBy', 'lodash/last', 'lodash/isDate'], factory) :
(global = global || self, factory(global.nivo = global.nivo || {}, global.PropTypes, global.d3, global.d3, global['lodash/uniq'], global['lodash/uniqBy'], global['lodash/sortBy'], global['lodash/last'], global['lodash/isDate']));
}(this, (function (exports, PropTypes, d3Scale, d3TimeFormat, uniq, uniqBy, sortBy, last, isDate) { 'use strict';
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')) :
typeof define === 'function' && define.amd ? define(['exports', 'lodash/uniq', 'lodash/uniqBy', 'lodash/sortBy', 'lodash/last', 'lodash/isDate', 'd3-time-format', 'd3-scale'], 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));
}(this, (function (exports, uniq, uniqBy, sortBy, last, isDate, d3TimeFormat, d3Scale) { 'use strict';
PropTypes = PropTypes && Object.prototype.hasOwnProperty.call(PropTypes, 'default') ? PropTypes['default'] : PropTypes;
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;
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;
var linearScale = function linearScale(_ref, xy, width, height) {
var axis = _ref.axis,
_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 values = xy[axis];
var size = axis === 'x' ? width : height;
var minValue = min;
if (min === 'auto') {
minValue = stacked === true ? values.minStacked : values.min;
}
var maxValue = max;
if (max === 'auto') {
maxValue = stacked === true ? values.maxStacked : values.max;
}
var scale = d3Scale.scaleLinear().rangeRound(axis === 'x' ? [0, size] : [size, 0]);
if (reverse === true) scale.domain([maxValue, minValue]);else scale.domain([minValue, maxValue]);
if (nice === true) scale.nice();else if (typeof nice === 'number') scale.nice(nice);
scale.type = 'linear';
scale.stacked = stacked;
scale.clamp(clamp);
return scale;
};
var linearScalePropTypes = {
type: PropTypes.oneOf(['linear']).isRequired,
min: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
max: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
stacked: PropTypes.bool,
reverse: PropTypes.bool,
clamp: PropTypes.bool,
nice: PropTypes.oneOfType([PropTypes.number, PropTypes.bool])
};
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;
}
var logScale = function logScale(_ref, xy, width, height) {
var axis = _ref.axis,
_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 values = xy[axis];
var size = axis === 'x' ? width : height;
var hasZero = values.all.some(function (v) {
return v === 0;
});
var sign;
var hasMixedSign = false;
values.all.filter(function (v) {
return v != null;
}).forEach(function (v) {
if (hasMixedSign === true) return;
if (sign === undefined) {
sign = Math.sign(v);
} else if (Math.sign(v) !== sign) {
hasMixedSign = true;
}
});
if (hasZero || hasMixedSign) {
throw new Error(["a log scale domain must be strictly-positive or strictly-negative,", "and must not include or cross zero."].join('\n'));
}
var minValue = min;
if (min === 'auto') {
minValue = values.min;
}
var maxValue = max;
if (max === 'auto') {
maxValue = values.max;
}
var scale = d3Scale.scaleLog().domain([minValue, maxValue]).rangeRound(axis === 'x' ? [0, size] : [size, 0]).base(base).nice();
scale.type = 'log';
return scale;
};
var logScalePropTypes = {
type: PropTypes.oneOf(['log']).isRequired,
base: PropTypes.number,
min: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
max: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number])
};
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
var symlogScale = function symlogScale(_ref, xy, width, height) {
var axis = _ref.axis,
_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;
var values = xy[axis];
var size = axis === 'x' ? width : height;
var minValue = min;
if (min === 'auto') {
minValue = values.min;
}
var maxValue = max;
if (max === 'auto') {
maxValue = values.max;
}
var scale = d3Scale.scaleSymlog().domain([minValue, maxValue]).constant(constant).rangeRound(axis === 'x' ? [0, size] : [size, 0]).nice();
scale.type = 'symlog';
return scale;
};
var symLogScalePropTypes = {
type: PropTypes.oneOf(['symlog']).isRequired,
constant: PropTypes.number,
min: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
max: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number])
};
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
}
var pointScale = function pointScale(_ref, xy, width, height) {
var axis = _ref.axis;
var values = xy[axis];
var size = axis === 'x' ? width : height;
var scale = d3Scale.scalePoint().range([0, size]).domain(values.all);
scale.type = 'point';
return scale;
};
var pointScalePropTypes = {
type: PropTypes.oneOf(['point']).isRequired
};
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(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
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 {
obj[key] = value;
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return obj;
}
return target;
}
var _precisionCutOffsByTy;
var TIME_PRECISION_MILLISECOND = 'millisecond';
var TIME_PRECISION_SECOND = 'second';
var TIME_PRECISION_MINUTE = 'minute';
var TIME_PRECISION_HOUR = 'hour';
var TIME_PRECISION_DAY = 'day';
var TIME_PRECISION_MONTH = 'month';
var TIME_PRECISION_YEAR = 'year';
var timePrecisions = [TIME_PRECISION_MILLISECOND, TIME_PRECISION_SECOND, TIME_PRECISION_MINUTE, TIME_PRECISION_HOUR, TIME_PRECISION_DAY, TIME_PRECISION_MONTH, TIME_PRECISION_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 = (_precisionCutOffsByTy = {}, _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_MILLISECOND, []), _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_SECOND, precisionCutOffs.slice(0, 1)), _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_MINUTE, precisionCutOffs.slice(0, 2)), _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_HOUR, precisionCutOffs.slice(0, 3)), _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_DAY, precisionCutOffs.slice(0, 4)), _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_MONTH, precisionCutOffs.slice(0, 5)), _defineProperty(_precisionCutOffsByTy, TIME_PRECISION_YEAR, precisionCutOffs.slice(0, 6)), _precisionCutOffsByTy);
var createPrecisionMethod = function createPrecisionMethod(precision) {
return function (date) {
precisionCutOffsByType[precision].forEach(function (cutOff) {
cutOff(date);
});
return date;
};
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);
if (format === 'native') return function (v) {
return precisionFn(v);
};
};
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 (format === 'native' || value instanceof Date) {
return precisionFn(value);
}
var parseTime = useUTC ? d3TimeFormat.utcParse(format) : d3TimeFormat.timeParse(format);
return function (v) {
return precisionFn(parseTime(v));
};
return precisionFn(parseTime(value));
};
};
var timeScale = function timeScale(_ref, xy, width, height) {
var axis = _ref.axis,
_ref$format = _ref.format,
format = _ref$format === void 0 ? 'native' : _ref$format,
_ref$precision = _ref.precision,
precision = _ref$precision === void 0 ? TIME_PRECISION_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 values = xy[axis];
var size = axis === 'x' ? width : height;
var normalize = createDateNormalizer({
format: format,
precision: precision,
useUTC: useUTC
});
var minValue = min;
if (min === 'auto') {
minValue = values.min;
} else if (format !== 'native') {
minValue = normalize(min);
}
var maxValue = max;
if (max === 'auto') {
maxValue = values.max;
} else if (format !== 'native') {
maxValue = normalize(max);
}
var scale = useUTC ? d3Scale.scaleUtc() : d3Scale.scaleTime();
scale.domain([minValue, maxValue]).range([0, size]);
if (nice === true) scale.nice();else if (typeof nice === 'object' || typeof nice === 'number') scale.nice(nice);
scale.type = 'time';
scale.useUTC = useUTC;
return scale;
};
var timeScalePropTypes = {
type: PropTypes.oneOf(['time']).isRequired,
format: PropTypes.string,
precision: PropTypes.oneOf(timePrecisions),
nice: PropTypes.oneOfType([PropTypes.bool, PropTypes.number, PropTypes.object])
};
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;
var bandScalePropTypes = {
type: PropTypes.oneOf(['band']).isRequired,
round: PropTypes.bool
};
if (min === 'auto') {
var _data$minStacked;
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];
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);
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);
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.domain([minValue, maxValue]).range([0, size]);
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;
}
return arr2;
});
if (hasMixedSign) {
throw new Error("a log scale domain must be strictly-positive or strictly-negative");
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
var minValue;
if (min === 'auto') {
minValue = data.min;
} else {
minValue = min;
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
var maxValue;
if (max === 'auto') {
maxValue = data.max;
} else {
maxValue = max;
}
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(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
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;
}
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.");
var maxValue;
if (max === 'auto') {
maxValue = data.max;
} else {
maxValue = max;
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
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 computeXYScalesForSeries = function computeXYScalesForSeries(_series, xScaleSpec, yScaleSpec, width, height) {
var series = _series.map(function (serie) {
return _objectSpread2(_objectSpread2({}, serie), {}, {
data: serie.data.map(function (d) {
return {
data: _objectSpread2({}, d)
};
})
});
});
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;
var xy = generateSeriesXY(series, xScaleSpec, yScaleSpec);
if ('stacked' in xScaleSpec && xScaleSpec.stacked === true) {
stackX(xy, series);
}
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;
if ('stacked' in yScaleSpec && yScaleSpec.stacked === true) {
stackY(xy, series);
}
var getOtherAxis = function getOtherAxis(axis) {
return axis === 'x' ? 'y' : 'x';
var xScale = computeScale(xScaleSpec, xy.x, width, 'x');
var yScale = computeScale(yScaleSpec, xy.y, height, 'y');
series.forEach(function (serie) {
serie.data.forEach(function (d) {
var _xScale, _yScale;
d.position = {
x: 'stacked' in xScale && xScale.stacked === true ? d.data.xStacked === null ? null : xScale(d.data.xStacked) : d.data.x === null ? null : (_xScale = xScale(d.data.x)) !== null && _xScale !== void 0 ? _xScale : null,
y: 'stacked' in yScale && yScale.stacked === true ? d.data.yStacked === null ? null : yScale(d.data.yStacked) : d.data.y === null ? null : (_yScale = yScale(d.data.y)) !== null && _yScale !== void 0 ? _yScale : null
};
});
});
return _objectSpread2(_objectSpread2({}, xy), {}, {
series: series,
xScale: xScale,
yScale: yScale
});
};
var generateSeriesXY = function generateSeriesXY(series, xScaleSpec, yScaleSpec) {
return {
x: generateSeriesAxis(series, 'x', xScaleSpec),
y: generateSeriesAxis(series, 'y', yScaleSpec)
};
var compareValues = function compareValues(a, b) {
return a === b;
};
var compareDateValues = function compareDateValues(a, b) {
return a.getTime() === b.getTime();
};
var computeXYScalesForSeries = function computeXYScalesForSeries(_series, xScaleSpec, yScaleSpec, width, height) {
var series = _series.map(function (serie) {
return _objectSpread2(_objectSpread2({}, serie), {}, {
data: serie.data.map(function (d) {
return {
data: _objectSpread2({}, d)
};
})
};
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)));
}
});
});
var xy = generateSeriesXY(series, xScaleSpec, yScaleSpec);
if (xScaleSpec.stacked === true) {
stackX(yScaleSpec.type, xy, series);
}
if (yScaleSpec.stacked === true) {
stackY(xScaleSpec.type, xy, series);
}
var xScale = computeScale(_objectSpread2(_objectSpread2({}, xScaleSpec), {}, {
axis: 'x'
}), xy, width, height);
var yScale = computeScale(_objectSpread2(_objectSpread2({}, yScaleSpec), {}, {
axis: 'y'
}), xy, width, height);
} else if (scaleSpec.type === 'time' && scaleSpec.format !== 'native') {
var parseTime = createDateNormalizer(scaleSpec);
series.forEach(function (serie) {
serie.data.forEach(function (d) {
d.position = {
x: xScale.stacked === true ? d.data.xStacked === null ? null : xScale(d.data.xStacked) : d.data.x === null ? null : xScale(d.data.x),
y: yScale.stacked === true ? d.data.yStacked === null ? null : yScale(d.data.yStacked) : d.data.y === null ? null : yScale(d.data.y)
};
var value = getValue(d);
if (value) {
setValue(d, parseTime(value));
}
});
});
return _objectSpread2(_objectSpread2({}, xy), {}, {
series: series,
xScale: xScale,
yScale: yScale
}
var values = [];
series.forEach(function (serie) {
serie.data.forEach(function (d) {
values.push(getValue(d));
});
};
var computeScale = function computeScale(spec, xy, width, height) {
if (spec.type === 'linear') return linearScale(spec, xy, width, height);else if (spec.type === 'point') return pointScale(spec, xy, width, height);else if (spec.type === 'time') return timeScale(spec, xy, width, height);else if (spec.type === 'log') return logScale(spec, xy, width, height);else if (spec.type === 'symlog') return symlogScale(spec, xy, width, height);
};
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) {
setValue(d, getValue(d) === null ? null : parseFloat(getValue(d)));
});
switch (scaleSpec.type) {
case 'linear':
{
var all = sortBy(uniq(values), function (v) {
return v;
});
});
} else if (scaleSpec.type === 'time' && scaleSpec.format !== 'native') {
var parseTime = createDateNormalizer(scaleSpec);
series.forEach(function (serie) {
serie.data.forEach(function (d) {
setValue(d, getValue(d) === null ? null : parseTime(getValue(d)));
});
});
}
var all = [];
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) {
serie.data.forEach(function (d) {
all.push(getValue(d));
var datum = serie.data.find(function (d) {
return compare(d.data[otherAxis], v);
});
});
var min, max;
if (scaleSpec.type === 'linear') {
all = uniq(all);
all = sortBy(all, function (v) {
return v;
});
min = Math.min.apply(Math, _toConsumableArray(all));
max = Math.max.apply(Math, _toConsumableArray(all));
} else if (scaleSpec.type === 'time') {
all = uniqBy(all, function (v) {
return v.getTime();
});
all = all.slice(0).sort(function (a, b) {
return b - a;
}).reverse();
min = all[0];
max = last(all);
} else {
all = uniq(all);
min = all[0];
max = last(all);
}
return {
all: all,
min: min,
max: max
};
};
var stackAxis = function stackAxis(axis, otherType, 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;
}
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["".concat(axis, "Stacked")] = stackValue;
}
stack.push(stackValue);
datum.data["".concat(axis, "Stacked")] = stackValue;
}
stack.push(stackValue);
if (stackValue !== null) {
all.push(stackValue);
});
}
});
all = all.filter(function (v) {
return v !== null;
});
xy[axis].minStacked = Math.min.apply(Math, _toConsumableArray(all));
xy[axis].maxStacked = Math.max.apply(Math, _toConsumableArray(all));
};
var stackX = function stackX(xy, otherType, series) {
return stackAxis('x', xy, otherType, series);
};
var stackY = function stackY(xy, otherType, series) {
return stackAxis('y', xy, otherType, series);
};
var computeAxisSlices = function computeAxisSlices(axis, data) {
var otherAxis = getOtherAxis(axis);
return data[otherAxis].all.map(function (v) {
var _slice;
var slice = (_slice = {
id: v
}, _defineProperty(_slice, otherAxis, data["".concat(otherAxis, "Scale")](v)), _defineProperty(_slice, "data", []), _slice);
var compare = isDate(v) ? compareDateValues : compareValues;
data.series.forEach(function (serie) {
var datum = serie.data.find(function (d) {
return compare(d.data[otherAxis], v);
});
if (datum !== undefined) {
slice.data.push(_objectSpread2(_objectSpread2({}, datum), {}, {
serie: serie
}));
}
});
slice.data.reverse();
return slice;
});
};
var computeXSlices = function computeXSlices(data) {
return computeAxisSlices('x', data);
};
var computeYSlices = function computeYSlices(data) {
return computeAxisSlices('y', data);
};
});
xy[axis].minStacked = Math.min.apply(Math, all);
xy[axis].maxStacked = Math.max.apply(Math, all);
};
var scalePropType = PropTypes.oneOfType([PropTypes.shape(linearScalePropTypes), PropTypes.shape(pointScalePropTypes), PropTypes.shape(timeScalePropTypes), PropTypes.shape(logScalePropTypes), PropTypes.shape(symLogScalePropTypes), PropTypes.shape(bandScalePropTypes)]);
var stackX = function stackX(xy, series) {
return stackAxis('x', xy, series);
};
exports.TIME_PRECISION_DAY = TIME_PRECISION_DAY;
exports.TIME_PRECISION_HOUR = TIME_PRECISION_HOUR;
exports.TIME_PRECISION_MILLISECOND = TIME_PRECISION_MILLISECOND;
exports.TIME_PRECISION_MINUTE = TIME_PRECISION_MINUTE;
exports.TIME_PRECISION_MONTH = TIME_PRECISION_MONTH;
exports.TIME_PRECISION_SECOND = TIME_PRECISION_SECOND;
exports.TIME_PRECISION_YEAR = TIME_PRECISION_YEAR;
exports.bandScalePropTypes = bandScalePropTypes;
exports.compareDateValues = compareDateValues;
exports.compareValues = compareValues;
exports.computeAxisSlices = computeAxisSlices;
exports.computeScale = computeScale;
exports.computeXSlices = computeXSlices;
exports.computeXYScalesForSeries = computeXYScalesForSeries;
exports.computeYSlices = computeYSlices;
exports.createDateNormalizer = createDateNormalizer;
exports.createPrecisionMethod = createPrecisionMethod;
exports.generateSeriesAxis = generateSeriesAxis;
exports.generateSeriesXY = generateSeriesXY;
exports.getOtherAxis = getOtherAxis;
exports.linearScale = linearScale;
exports.linearScalePropTypes = linearScalePropTypes;
exports.logScale = logScale;
exports.logScalePropTypes = logScalePropTypes;
exports.pointScale = pointScale;
exports.pointScalePropTypes = pointScalePropTypes;
exports.precisionCutOffs = precisionCutOffs;
exports.precisionCutOffsByType = precisionCutOffsByType;
exports.scalePropType = scalePropType;
exports.stackAxis = stackAxis;
exports.stackX = stackX;
exports.stackY = stackY;
exports.symLogScalePropTypes = symLogScalePropTypes;
exports.symlogScale = symlogScale;
exports.timePrecisions = timePrecisions;
exports.timeScale = timeScale;
exports.timeScalePropTypes = timeScalePropTypes;
var stackY = function stackY(xy, series) {
return stackAxis('y', xy, series);
};
Object.defineProperty(exports, '__esModule', { value: true });
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.precisionCutOffs = precisionCutOffs;
exports.precisionCutOffsByType = precisionCutOffsByType;
exports.stackAxis = stackAxis;
exports.timePrecisions = timePrecisions;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=nivo-scales.umd.js.map

@@ -32,3 +32,3 @@ import { ScaleAxis, ScaleSpec, Series, ScaleValue, SerieAxis, ComputedSerieAxis } from './types';

export declare const compareDateValues: (a: Date, b: Date) => boolean;
export declare function computeScale<Input extends ScaleValue>(spec: ScaleSpec, data: ComputedSerieAxis<any>, size: number, axis: ScaleAxis): import("./types").ScaleSymLog | import("d3-scale").ScaleLogarithmic<number, number, never> | import("./types").ScaleLinear<number> | import("./types").ScalePoint<Input> | import("./types").ScaleBand<Input> | import("./types").ScaleTime<number | Date | {
export declare function computeScale<Input extends ScaleValue>(spec: ScaleSpec, data: ComputedSerieAxis<any>, size: number, axis: ScaleAxis): import("./types").ScaleSymlog | import("d3-scale").ScaleLogarithmic<number, number, never> | import("./types").ScaleLinear<number> | import("./types").ScalePoint<Input> | import("./types").ScaleBand<Input> | import("./types").ScaleTime<number | Date | {
valueOf(): number;

@@ -38,6 +38,6 @@ }>;

series: ComputedXYSeries[];
xScale: import("./types").ScaleSymLog | import("d3-scale").ScaleLogarithmic<number, number, never> | import("./types").ScaleLinear<number> | import("./types").ScaleTime<number | Date | {
xScale: import("./types").ScaleSymlog | import("d3-scale").ScaleLogarithmic<number, number, never> | import("./types").ScaleLinear<number> | import("./types").ScaleTime<number | Date | {
valueOf(): number;
}> | import("./types").ScalePoint<ScaleValue> | import("./types").ScaleBand<ScaleValue>;
yScale: import("./types").ScaleSymLog | import("d3-scale").ScaleLogarithmic<number, number, never> | import("./types").ScaleLinear<number> | import("./types").ScaleTime<number | Date | {
yScale: import("./types").ScaleSymlog | import("d3-scale").ScaleLogarithmic<number, number, never> | import("./types").ScaleLinear<number> | import("./types").ScaleTime<number | Date | {
valueOf(): number;

@@ -44,0 +44,0 @@ }> | import("./types").ScalePoint<ScaleValue> | import("./types").ScaleBand<ScaleValue>;

export * from './compute';
export * from './linearScale';
export * from './logScale';
export * from './symLogScale';
export * from './symlogScale';
export * from './pointScale';

@@ -6,0 +6,0 @@ export * from './timeScale';

@@ -15,3 +15,3 @@ import { ScaleLinear as D3ScaleLinear, ScalePoint as D3ScalePoint, ScaleBand as D3ScaleBand, ScaleLogarithmic as D3ScaleLogarithmic, ScaleSymLog as D3ScaleSymLog, ScaleTime as D3ScaleTime } from 'd3-scale';

log: ScaleLogSpec;
symlog: ScaleSymLogSpec;
symlog: ScaleSymlogSpec;
point: ScalePointSpec;

@@ -26,3 +26,3 @@ band: ScaleBandSpec;

log: ScaleLog;
symlog: ScaleSymLog;
symlog: ScaleSymlog;
point: ScalePoint<Input>;

@@ -46,3 +46,2 @@ band: ScaleBand<Input>;

}
export declare const isScaleLinearSpec: (spec: ScaleSpec) => spec is ScaleLinearSpec;
export interface ScaleLogSpec {

@@ -57,4 +56,3 @@ type: 'log';

}
export declare const isScaleLogSpec: (spec: ScaleSpec) => spec is ScaleLogSpec;
export interface ScaleSymLogSpec {
export interface ScaleSymlogSpec {
type: 'symlog';

@@ -64,7 +62,7 @@ constant?: number;

max?: 'auto' | number;
reverse?: boolean;
}
export interface ScaleSymLog extends D3ScaleSymLog<number, number> {
export interface ScaleSymlog extends D3ScaleSymLog<number, number> {
type: 'symlog';
}
export declare const isScaleSymLogSpec: (spec: ScaleSpec) => spec is ScaleSymLogSpec;
export declare type ScalePointSpec = {

@@ -76,3 +74,2 @@ type: 'point';

}
export declare const isScalePointSpec: (spec: ScaleSpec) => spec is ScalePointSpec;
export declare type ScaleBandSpec = {

@@ -85,3 +82,2 @@ type: 'band';

}
export declare const isScaleBandSpec: (spec: ScaleSpec) => spec is ScaleBandSpec;
export declare type ScaleTimeSpec = {

@@ -88,0 +84,0 @@ type: 'time';

{
"name": "@nivo/scales",
"version": "0.70.0",
"version": "0.71.0",
"license": "MIT",

@@ -16,7 +16,8 @@ "author": {

"module": "./dist/nivo-scales.es.js",
"typings": "./dist/types/index.d.ts",
"files": [
"README.md",
"LICENSE.md",
"index.d.ts",
"dist/"
"dist/",
"!dist/tsconfig.tsbuildinfo"
],

@@ -26,7 +27,8 @@ "dependencies": {

"d3-time": "^1.0.11",
"d3-time-format": "^2.1.3",
"lodash": "^4.17.11"
"d3-time-format": "^3.0.0",
"lodash": "^4.17.21"
},
"peerDependencies": {
"prop-types": ">= 15.5.10 < 16.0.0"
"devDependencies": {
"@types/d3-scale": "^3.2.2",
"@types/d3-time-format": "^3.0.0"
},

@@ -36,3 +38,3 @@ "publishConfig": {

},
"gitHead": "77cbd6a909c2b2d53ba94e2ee873f3d95b5aae3b"
"gitHead": "232b613bd61d2b8e5c783f4181b2d14580e2fd27"
}

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

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