@nivo/colors
Advanced tools
Comparing version 0.74.1 to 0.75.0
@@ -1,531 +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 d3ScaleChromatic = require('d3-scale-chromatic'); | ||
var _isPlainObject = _interopDefault(require('lodash/isPlainObject')); | ||
var _get = _interopDefault(require('lodash/get')); | ||
var react = require('react'); | ||
var d3Color = require('d3-color'); | ||
var reactMotion = require('react-motion'); | ||
var d3Scale = require('d3-scale'); | ||
var PropTypes = _interopDefault(require('prop-types')); | ||
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 categoricalColorSchemes = { | ||
nivo: ['#e8c1a0', '#f47560', '#f1e15b', '#e8a838', '#61cdbb', '#97e3d5'], | ||
category10: d3ScaleChromatic.schemeCategory10, | ||
accent: d3ScaleChromatic.schemeAccent, | ||
dark2: d3ScaleChromatic.schemeDark2, | ||
paired: d3ScaleChromatic.schemePaired, | ||
pastel1: d3ScaleChromatic.schemePastel1, | ||
pastel2: d3ScaleChromatic.schemePastel2, | ||
set1: d3ScaleChromatic.schemeSet1, | ||
set2: d3ScaleChromatic.schemeSet2, | ||
set3: d3ScaleChromatic.schemeSet3 | ||
}; | ||
var categoricalColorSchemeIds = Object.keys(categoricalColorSchemes); | ||
var divergingColorSchemes = { | ||
brown_blueGreen: d3ScaleChromatic.schemeBrBG, | ||
purpleRed_green: d3ScaleChromatic.schemePRGn, | ||
pink_yellowGreen: d3ScaleChromatic.schemePiYG, | ||
purple_orange: d3ScaleChromatic.schemePuOr, | ||
red_blue: d3ScaleChromatic.schemeRdBu, | ||
red_grey: d3ScaleChromatic.schemeRdGy, | ||
red_yellow_blue: d3ScaleChromatic.schemeRdYlBu, | ||
red_yellow_green: d3ScaleChromatic.schemeRdYlGn, | ||
spectral: d3ScaleChromatic.schemeSpectral | ||
}; | ||
var divergingColorSchemeIds = Object.keys(divergingColorSchemes); | ||
var divergingColorInterpolators = { | ||
brown_blueGreen: d3ScaleChromatic.interpolateBrBG, | ||
purpleRed_green: d3ScaleChromatic.interpolatePRGn, | ||
pink_yellowGreen: d3ScaleChromatic.interpolatePiYG, | ||
purple_orange: d3ScaleChromatic.interpolatePuOr, | ||
red_blue: d3ScaleChromatic.interpolateRdBu, | ||
red_grey: d3ScaleChromatic.interpolateRdGy, | ||
red_yellow_blue: d3ScaleChromatic.interpolateRdYlBu, | ||
red_yellow_green: d3ScaleChromatic.interpolateRdYlGn, | ||
spectral: d3ScaleChromatic.interpolateSpectral | ||
}; | ||
var sequentialColorSchemes = { | ||
blues: d3ScaleChromatic.schemeBlues, | ||
greens: d3ScaleChromatic.schemeGreens, | ||
greys: d3ScaleChromatic.schemeGreys, | ||
oranges: d3ScaleChromatic.schemeOranges, | ||
purples: d3ScaleChromatic.schemePurples, | ||
reds: d3ScaleChromatic.schemeReds, | ||
blue_green: d3ScaleChromatic.schemeBuGn, | ||
blue_purple: d3ScaleChromatic.schemeBuPu, | ||
green_blue: d3ScaleChromatic.schemeGnBu, | ||
orange_red: d3ScaleChromatic.schemeOrRd, | ||
purple_blue_green: d3ScaleChromatic.schemePuBuGn, | ||
purple_blue: d3ScaleChromatic.schemePuBu, | ||
purple_red: d3ScaleChromatic.schemePuRd, | ||
red_purple: d3ScaleChromatic.schemeRdPu, | ||
yellow_green_blue: d3ScaleChromatic.schemeYlGnBu, | ||
yellow_green: d3ScaleChromatic.schemeYlGn, | ||
yellow_orange_brown: d3ScaleChromatic.schemeYlOrBr, | ||
yellow_orange_red: d3ScaleChromatic.schemeYlOrRd | ||
}; | ||
var sequentialColorSchemeIds = Object.keys(sequentialColorSchemes); | ||
var sequentialColorInterpolators = { | ||
blues: d3ScaleChromatic.interpolateBlues, | ||
greens: d3ScaleChromatic.interpolateGreens, | ||
greys: d3ScaleChromatic.interpolateGreys, | ||
oranges: d3ScaleChromatic.interpolateOranges, | ||
purples: d3ScaleChromatic.interpolatePurples, | ||
reds: d3ScaleChromatic.interpolateReds, | ||
turbo: d3ScaleChromatic.interpolateTurbo, | ||
viridis: d3ScaleChromatic.interpolateViridis, | ||
inferno: d3ScaleChromatic.interpolateInferno, | ||
magma: d3ScaleChromatic.interpolateMagma, | ||
plasma: d3ScaleChromatic.interpolatePlasma, | ||
cividis: d3ScaleChromatic.interpolateCividis, | ||
warm: d3ScaleChromatic.interpolateWarm, | ||
cool: d3ScaleChromatic.interpolateCool, | ||
cubehelixDefault: d3ScaleChromatic.interpolateCubehelixDefault, | ||
blue_green: d3ScaleChromatic.interpolateBuGn, | ||
blue_purple: d3ScaleChromatic.interpolateBuPu, | ||
green_blue: d3ScaleChromatic.interpolateGnBu, | ||
orange_red: d3ScaleChromatic.interpolateOrRd, | ||
purple_blue_green: d3ScaleChromatic.interpolatePuBuGn, | ||
purple_blue: d3ScaleChromatic.interpolatePuBu, | ||
purple_red: d3ScaleChromatic.interpolatePuRd, | ||
red_purple: d3ScaleChromatic.interpolateRdPu, | ||
yellow_green_blue: d3ScaleChromatic.interpolateYlGnBu, | ||
yellow_green: d3ScaleChromatic.interpolateYlGn, | ||
yellow_orange_brown: d3ScaleChromatic.interpolateYlOrBr, | ||
yellow_orange_red: d3ScaleChromatic.interpolateYlOrRd | ||
}; | ||
var colorSchemes = _objectSpread2(_objectSpread2(_objectSpread2({}, categoricalColorSchemes), divergingColorSchemes), sequentialColorSchemes); | ||
var colorSchemeIds = Object.keys(colorSchemes); | ||
var isCategoricalColorScheme = function isCategoricalColorScheme(scheme) { | ||
return categoricalColorSchemeIds.includes(scheme); | ||
}; | ||
var isDivergingColorScheme = function isDivergingColorScheme(scheme) { | ||
return divergingColorSchemeIds.includes(scheme); | ||
}; | ||
var isSequentialColorScheme = function isSequentialColorScheme(scheme) { | ||
return sequentialColorSchemeIds.includes(scheme); | ||
}; | ||
var cyclicalColorInterpolators = { | ||
rainbow: d3ScaleChromatic.interpolateRainbow, | ||
sinebow: d3ScaleChromatic.interpolateSinebow | ||
}; | ||
var colorInterpolators = _objectSpread2(_objectSpread2(_objectSpread2({}, divergingColorInterpolators), sequentialColorInterpolators), cyclicalColorInterpolators); | ||
var colorInterpolatorIds = Object.keys(colorInterpolators); | ||
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 _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 _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 _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(); | ||
} | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
var it; | ||
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
var F = function F() {}; | ||
return { | ||
s: F, | ||
n: function n() { | ||
if (i >= o.length) return { | ||
done: true | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}, | ||
e: function e(_e) { | ||
throw _e; | ||
}, | ||
f: F | ||
}; | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var normalCompletion = true, | ||
didErr = false, | ||
err; | ||
return { | ||
s: function s() { | ||
it = o[Symbol.iterator](); | ||
}, | ||
n: function n() { | ||
var step = it.next(); | ||
normalCompletion = step.done; | ||
return step; | ||
}, | ||
e: function e(_e2) { | ||
didErr = true; | ||
err = _e2; | ||
}, | ||
f: function f() { | ||
try { | ||
if (!normalCompletion && it["return"] != null) it["return"](); | ||
} finally { | ||
if (didErr) throw err; | ||
} | ||
} | ||
}; | ||
} | ||
var isInheritedColorConfigFromTheme = function isInheritedColorConfigFromTheme(config) { | ||
return config.theme !== undefined; | ||
}; | ||
var isInheritedColorConfigFromContext = function isInheritedColorConfigFromContext(config) { | ||
return config.from !== undefined; | ||
}; | ||
var getInheritedColorGenerator = function getInheritedColorGenerator(config, theme) { | ||
if (typeof config === 'function') { | ||
return config; | ||
} | ||
if (_isPlainObject(config)) { | ||
if (isInheritedColorConfigFromTheme(config)) { | ||
if (theme === undefined) { | ||
throw new Error("Unable to use color from theme as no theme was provided"); | ||
} | ||
var themeColor = _get(theme, config.theme); | ||
if (themeColor === undefined) { | ||
throw new Error("Color from theme is undefined at path: '".concat(config.theme, "'")); | ||
} | ||
return function () { | ||
return themeColor; | ||
}; | ||
} | ||
if (isInheritedColorConfigFromContext(config)) { | ||
var getColor = function getColor(d) { | ||
return _get(d, config.from); | ||
}; | ||
if (Array.isArray(config.modifiers)) { | ||
var modifiers = []; | ||
var _iterator = _createForOfIteratorHelper(config.modifiers), | ||
_step; | ||
try { | ||
var _loop = function _loop() { | ||
var modifier = _step.value; | ||
var _modifier = _slicedToArray(modifier, 2), | ||
modifierType = _modifier[0], | ||
amount = _modifier[1]; | ||
if (modifierType === 'brighter') { | ||
modifiers.push(function (color) { | ||
return color.brighter(amount); | ||
}); | ||
} else if (modifierType === 'darker') { | ||
modifiers.push(function (color) { | ||
return color.darker(amount); | ||
}); | ||
} else if (modifierType === 'opacity') { | ||
modifiers.push(function (color) { | ||
color.opacity = amount; | ||
return color; | ||
}); | ||
} else { | ||
throw new Error("Invalid color modifier: '".concat(modifierType, "', must be one of: 'brighter', 'darker', 'opacity'")); | ||
} | ||
}; | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
_loop(); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
if (modifiers.length === 0) return getColor; | ||
return function (datum) { | ||
return modifiers.reduce(function (color, modify) { | ||
return modify(color); | ||
}, d3Color.rgb(getColor(datum))).toString(); | ||
}; | ||
} | ||
return getColor; | ||
} | ||
throw new Error("Invalid color spec, you should either specify 'theme' or 'from' when using a config object"); | ||
} | ||
return function () { | ||
return config; | ||
}; | ||
}; | ||
var useInheritedColor = function useInheritedColor(config, theme) { | ||
return react.useMemo(function () { | ||
return getInheritedColorGenerator(config, theme); | ||
}, [config, theme]); | ||
}; | ||
var interpolateColor = function interpolateColor(color, springConfig) { | ||
var colorComponents = d3Color.rgb(color); | ||
if (!springConfig) { | ||
return { | ||
colorR: colorComponents.r, | ||
colorG: colorComponents.g, | ||
colorB: colorComponents.b | ||
}; | ||
} | ||
var configWithPrecision = _objectSpread2(_objectSpread2({}, springConfig), {}, { | ||
precision: 1 | ||
}); | ||
return { | ||
colorR: reactMotion.spring(colorComponents.r, configWithPrecision), | ||
colorG: reactMotion.spring(colorComponents.g, configWithPrecision), | ||
colorB: reactMotion.spring(colorComponents.b, configWithPrecision) | ||
}; | ||
}; | ||
var getInterpolatedColor = function getInterpolatedColor(_ref) { | ||
var colorR = _ref.colorR, | ||
colorG = _ref.colorG, | ||
colorB = _ref.colorB; | ||
return "rgb(".concat(Math.round(Math.max(colorR, 0)), ",").concat(Math.round(Math.max(colorG, 0)), ",").concat(Math.round(Math.max(colorB, 0)), ")"); | ||
}; | ||
var isOrdinalColorScaleConfigScheme = function isOrdinalColorScaleConfigScheme(config) { | ||
return config.scheme !== undefined; | ||
}; | ||
var isOrdinalColorScaleConfigDatumProperty = function isOrdinalColorScaleConfigDatumProperty(config) { | ||
return config.datum !== undefined; | ||
}; | ||
var getOrdinalColorScale = function getOrdinalColorScale(config, identity) { | ||
if (typeof config === 'function') { | ||
return config; | ||
} | ||
var getIdentity = typeof identity === 'function' ? identity : function (datum) { | ||
return _get(datum, identity); | ||
}; | ||
if (Array.isArray(config)) { | ||
var scale = d3Scale.scaleOrdinal(config); | ||
var generator = function generator(datum) { | ||
return scale(getIdentity(datum)); | ||
}; | ||
generator.scale = scale; | ||
return generator; | ||
} | ||
if (_isPlainObject(config)) { | ||
if (isOrdinalColorScaleConfigDatumProperty(config)) { | ||
return function (datum) { | ||
return _get(datum, config.datum); | ||
}; | ||
} | ||
if (isOrdinalColorScaleConfigScheme(config)) { | ||
if (isCategoricalColorScheme(config.scheme)) { | ||
var _scale = d3Scale.scaleOrdinal(colorSchemes[config.scheme]); | ||
var _generator = function _generator(datum) { | ||
return _scale(getIdentity(datum)); | ||
}; | ||
_generator.scale = _scale; | ||
return _generator; | ||
} | ||
if (isDivergingColorScheme(config.scheme)) { | ||
if (config.size !== undefined && (config.size < 3 || config.size > 11)) { | ||
throw new Error("Invalid size '".concat(config.size, "' for diverging color scheme '").concat(config.scheme, "', must be between 3~11")); | ||
} | ||
var _scale2 = d3Scale.scaleOrdinal(colorSchemes[config.scheme][config.size || 11]); | ||
var _generator2 = function _generator2(d) { | ||
return _scale2(getIdentity(d)); | ||
}; | ||
_generator2.scale = _scale2; | ||
return _generator2; | ||
} | ||
if (isSequentialColorScheme(config.scheme)) { | ||
if (config.size !== undefined && (config.size < 3 || config.size > 9)) { | ||
throw new Error("Invalid size '".concat(config.size, "' for sequential color scheme '").concat(config.scheme, "', must be between 3~9")); | ||
} | ||
var _scale3 = d3Scale.scaleOrdinal(colorSchemes[config.scheme][config.size || 9]); | ||
var _generator3 = function _generator3(d) { | ||
return _scale3(getIdentity(d)); | ||
}; | ||
_generator3.scale = _scale3; | ||
return _generator3; | ||
} | ||
} | ||
throw new Error("Invalid colors, when using an object, you should either pass a 'datum' or a 'scheme' property"); | ||
} | ||
return function () { | ||
return config; | ||
}; | ||
}; | ||
var useOrdinalColorScale = function useOrdinalColorScale(config, identity) { | ||
return react.useMemo(function () { | ||
return getOrdinalColorScale(config, identity); | ||
}, [config, identity]); | ||
}; | ||
var ordinalColorsPropType = PropTypes.oneOfType([PropTypes.func, PropTypes.arrayOf(PropTypes.string), PropTypes.shape({ | ||
scheme: PropTypes.oneOf(colorSchemeIds).isRequired, | ||
size: PropTypes.number | ||
}), PropTypes.shape({ | ||
datum: PropTypes.string.isRequired | ||
}), PropTypes.string]); | ||
var colorPropertyAccessorPropType = PropTypes.oneOfType([PropTypes.func, PropTypes.string]); | ||
var inheritedColorPropType = PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.shape({ | ||
theme: PropTypes.string.isRequired | ||
}), PropTypes.shape({ | ||
from: PropTypes.string.isRequired, | ||
modifiers: PropTypes.arrayOf(PropTypes.array) | ||
})]); | ||
exports.categoricalColorSchemeIds = categoricalColorSchemeIds; | ||
exports.categoricalColorSchemes = categoricalColorSchemes; | ||
exports.colorInterpolatorIds = colorInterpolatorIds; | ||
exports.colorInterpolators = colorInterpolators; | ||
exports.colorPropertyAccessorPropType = colorPropertyAccessorPropType; | ||
exports.colorSchemeIds = colorSchemeIds; | ||
exports.colorSchemes = colorSchemes; | ||
exports.cyclicalColorInterpolators = cyclicalColorInterpolators; | ||
exports.divergingColorInterpolators = divergingColorInterpolators; | ||
exports.divergingColorSchemeIds = divergingColorSchemeIds; | ||
exports.divergingColorSchemes = divergingColorSchemes; | ||
exports.getInheritedColorGenerator = getInheritedColorGenerator; | ||
exports.getInterpolatedColor = getInterpolatedColor; | ||
exports.getOrdinalColorScale = getOrdinalColorScale; | ||
exports.inheritedColorPropType = inheritedColorPropType; | ||
exports.interpolateColor = interpolateColor; | ||
exports.isCategoricalColorScheme = isCategoricalColorScheme; | ||
exports.isDivergingColorScheme = isDivergingColorScheme; | ||
exports.isSequentialColorScheme = isSequentialColorScheme; | ||
exports.ordinalColorsPropType = ordinalColorsPropType; | ||
exports.sequentialColorInterpolators = sequentialColorInterpolators; | ||
exports.sequentialColorSchemeIds = sequentialColorSchemeIds; | ||
exports.sequentialColorSchemes = sequentialColorSchemes; | ||
exports.useInheritedColor = useInheritedColor; | ||
exports.useOrdinalColorScale = useOrdinalColorScale; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("d3-scale-chromatic"),r=require("lodash/isPlainObject"),t=require("lodash/get"),o=require("react"),n=require("d3-color"),l=require("react-motion"),i=require("d3-scale"),u=require("prop-types");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=a(r),c=a(t),p=a(u);function d(){return d=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},d.apply(this,arguments)}function f(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,o=new Array(r);t<r;t++)o[t]=e[t];return o}function h(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return f(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?f(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var m={nivo:["#e8c1a0","#f47560","#f1e15b","#e8a838","#61cdbb","#97e3d5"],category10:e.schemeCategory10,accent:e.schemeAccent,dark2:e.schemeDark2,paired:e.schemePaired,pastel1:e.schemePastel1,pastel2:e.schemePastel2,set1:e.schemeSet1,set2:e.schemeSet2,set3:e.schemeSet3},g=Object.keys(m),y={brown_blueGreen:e.schemeBrBG,purpleRed_green:e.schemePRGn,pink_yellowGreen:e.schemePiYG,purple_orange:e.schemePuOr,red_blue:e.schemeRdBu,red_grey:e.schemeRdGy,red_yellow_blue:e.schemeRdYlBu,red_yellow_green:e.schemeRdYlGn,spectral:e.schemeSpectral},b=Object.keys(y),_={brown_blueGreen:e.interpolateBrBG,purpleRed_green:e.interpolatePRGn,pink_yellowGreen:e.interpolatePiYG,purple_orange:e.interpolatePuOr,red_blue:e.interpolateRdBu,red_grey:e.interpolateRdGy,red_yellow_blue:e.interpolateRdYlBu,red_yellow_green:e.interpolateRdYlGn,spectral:e.interpolateSpectral},v={blues:e.schemeBlues,greens:e.schemeGreens,greys:e.schemeGreys,oranges:e.schemeOranges,purples:e.schemePurples,reds:e.schemeReds,blue_green:e.schemeBuGn,blue_purple:e.schemeBuPu,green_blue:e.schemeGnBu,orange_red:e.schemeOrRd,purple_blue_green:e.schemePuBuGn,purple_blue:e.schemePuBu,purple_red:e.schemePuRd,red_purple:e.schemeRdPu,yellow_green_blue:e.schemeYlGnBu,yellow_green:e.schemeYlGn,yellow_orange_brown:e.schemeYlOrBr,yellow_orange_red:e.schemeYlOrRd},w=Object.keys(v),O={blues:e.interpolateBlues,greens:e.interpolateGreens,greys:e.interpolateGreys,oranges:e.interpolateOranges,purples:e.interpolatePurples,reds:e.interpolateReds,turbo:e.interpolateTurbo,viridis:e.interpolateViridis,inferno:e.interpolateInferno,magma:e.interpolateMagma,plasma:e.interpolatePlasma,cividis:e.interpolateCividis,warm:e.interpolateWarm,cool:e.interpolateCool,cubehelixDefault:e.interpolateCubehelixDefault,blue_green:e.interpolateBuGn,blue_purple:e.interpolateBuPu,green_blue:e.interpolateGnBu,orange_red:e.interpolateOrRd,purple_blue_green:e.interpolatePuBuGn,purple_blue:e.interpolatePuBu,purple_red:e.interpolatePuRd,red_purple:e.interpolateRdPu,yellow_green_blue:e.interpolateYlGnBu,yellow_green:e.interpolateYlGn,yellow_orange_brown:e.interpolateYlOrBr,yellow_orange_red:e.interpolateYlOrRd},x=d({},m,y,v),G=Object.keys(x),R=function(e){return g.includes(e)},P=function(e){return b.includes(e)},B=function(e){return w.includes(e)},C={rainbow:e.interpolateRainbow,sinebow:e.interpolateSinebow},S=d({},_,O,C),I=Object.keys(S),q=function(e,r){if("function"==typeof e)return e;if(s.default(e)){if(function(e){return void 0!==e.theme}(e)){if(void 0===r)throw new Error("Unable to use color from theme as no theme was provided");var t=c.default(r,e.theme);if(void 0===t)throw new Error("Color from theme is undefined at path: '"+e.theme+"'");return function(){return t}}if(function(e){return void 0!==e.from}(e)){var o=function(r){return c.default(r,e.from)};if(Array.isArray(e.modifiers)){for(var l,i=[],u=function(){var e=l.value,r=e[0],t=e[1];if("brighter"===r)i.push((function(e){return e.brighter(t)}));else if("darker"===r)i.push((function(e){return e.darker(t)}));else{if("opacity"!==r)throw new Error("Invalid color modifier: '"+r+"', must be one of: 'brighter', 'darker', 'opacity'");i.push((function(e){return e.opacity=t,e}))}},a=h(e.modifiers);!(l=a()).done;)u();return 0===i.length?o:function(e){return i.reduce((function(e,r){return r(e)}),n.rgb(o(e))).toString()}}return o}throw new Error("Invalid color spec, you should either specify 'theme' or 'from' when using a config object")}return function(){return e}},j=function(e,r){if("function"==typeof e)return e;var t="function"==typeof r?r:function(e){return c.default(e,r)};if(Array.isArray(e)){var o=i.scaleOrdinal(e),n=function(e){return o(t(e))};return n.scale=o,n}if(s.default(e)){if(function(e){return void 0!==e.datum}(e))return function(r){return c.default(r,e.datum)};if(function(e){return void 0!==e.scheme}(e)){if(R(e.scheme)){var l=i.scaleOrdinal(x[e.scheme]),u=function(e){return l(t(e))};return u.scale=l,u}if(P(e.scheme)){if(void 0!==e.size&&(e.size<3||e.size>11))throw new Error("Invalid size '"+e.size+"' for diverging color scheme '"+e.scheme+"', must be between 3~11");var a=i.scaleOrdinal(x[e.scheme][e.size||11]),p=function(e){return a(t(e))};return p.scale=a,p}if(B(e.scheme)){if(void 0!==e.size&&(e.size<3||e.size>9))throw new Error("Invalid size '"+e.size+"' for sequential color scheme '"+e.scheme+"', must be between 3~9");var d=i.scaleOrdinal(x[e.scheme][e.size||9]),f=function(e){return d(t(e))};return f.scale=d,f}}throw new Error("Invalid colors, when using an object, you should either pass a 'datum' or a 'scheme' property")}return function(){return e}},Y=p.default.oneOfType([p.default.func,p.default.arrayOf(p.default.string),p.default.shape({scheme:p.default.oneOf(G).isRequired,size:p.default.number}),p.default.shape({datum:p.default.string.isRequired}),p.default.string]),z=p.default.oneOfType([p.default.func,p.default.string]),k=p.default.oneOfType([p.default.string,p.default.func,p.default.shape({theme:p.default.string.isRequired}),p.default.shape({from:p.default.string.isRequired,modifiers:p.default.arrayOf(p.default.array)})]);exports.categoricalColorSchemeIds=g,exports.categoricalColorSchemes=m,exports.colorInterpolatorIds=I,exports.colorInterpolators=S,exports.colorPropertyAccessorPropType=z,exports.colorSchemeIds=G,exports.colorSchemes=x,exports.cyclicalColorInterpolators=C,exports.divergingColorInterpolators=_,exports.divergingColorSchemeIds=b,exports.divergingColorSchemes=y,exports.getInheritedColorGenerator=q,exports.getInterpolatedColor=function(e){var r=e.colorR,t=e.colorG,o=e.colorB;return"rgb("+Math.round(Math.max(r,0))+","+Math.round(Math.max(t,0))+","+Math.round(Math.max(o,0))+")"},exports.getOrdinalColorScale=j,exports.inheritedColorPropType=k,exports.interpolateColor=function(e,r){var t=n.rgb(e);if(!r)return{colorR:t.r,colorG:t.g,colorB:t.b};var o=d({},r,{precision:1});return{colorR:l.spring(t.r,o),colorG:l.spring(t.g,o),colorB:l.spring(t.b,o)}},exports.isCategoricalColorScheme=R,exports.isDivergingColorScheme=P,exports.isSequentialColorScheme=B,exports.ordinalColorsPropType=Y,exports.sequentialColorInterpolators=O,exports.sequentialColorSchemeIds=w,exports.sequentialColorSchemes=v,exports.useInheritedColor=function(e,r){return o.useMemo((function(){return q(e,r)}),[e,r])},exports.useOrdinalColorScale=function(e,r){return o.useMemo((function(){return j(e,r)}),[e,r])}; | ||
//# sourceMappingURL=nivo-colors.cjs.js.map |
@@ -1,501 +0,2 @@ | ||
import { schemeCategory10, schemeAccent, schemeDark2, schemePaired, schemePastel1, schemePastel2, schemeSet1, schemeSet2, schemeSet3, schemeBrBG, schemePRGn, schemePiYG, schemePuOr, schemeRdBu, schemeRdGy, schemeRdYlBu, schemeRdYlGn, schemeSpectral, interpolateBrBG, interpolatePRGn, interpolatePiYG, interpolatePuOr, interpolateRdBu, interpolateRdGy, interpolateRdYlBu, interpolateRdYlGn, interpolateSpectral, schemeBlues, schemeGreens, schemeGreys, schemeOranges, schemePurples, schemeReds, schemeBuGn, schemeBuPu, schemeGnBu, schemeOrRd, schemePuBuGn, schemePuBu, schemePuRd, schemeRdPu, schemeYlGnBu, schemeYlGn, schemeYlOrBr, schemeYlOrRd, interpolateBlues, interpolateGreens, interpolateGreys, interpolateOranges, interpolatePurples, interpolateReds, interpolateTurbo, interpolateViridis, interpolateInferno, interpolateMagma, interpolatePlasma, interpolateCividis, interpolateWarm, interpolateCool, interpolateCubehelixDefault, interpolateBuGn, interpolateBuPu, interpolateGnBu, interpolateOrRd, interpolatePuBuGn, interpolatePuBu, interpolatePuRd, interpolateRdPu, interpolateYlGnBu, interpolateYlGn, interpolateYlOrBr, interpolateYlOrRd, interpolateRainbow, interpolateSinebow } from 'd3-scale-chromatic'; | ||
import _isPlainObject from 'lodash/isPlainObject'; | ||
import _get from 'lodash/get'; | ||
import { useMemo } from 'react'; | ||
import { rgb } from 'd3-color'; | ||
import { spring } from 'react-motion'; | ||
import { scaleOrdinal } from 'd3-scale'; | ||
import PropTypes from 'prop-types'; | ||
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 categoricalColorSchemes = { | ||
nivo: ['#e8c1a0', '#f47560', '#f1e15b', '#e8a838', '#61cdbb', '#97e3d5'], | ||
category10: schemeCategory10, | ||
accent: schemeAccent, | ||
dark2: schemeDark2, | ||
paired: schemePaired, | ||
pastel1: schemePastel1, | ||
pastel2: schemePastel2, | ||
set1: schemeSet1, | ||
set2: schemeSet2, | ||
set3: schemeSet3 | ||
}; | ||
var categoricalColorSchemeIds = Object.keys(categoricalColorSchemes); | ||
var divergingColorSchemes = { | ||
brown_blueGreen: schemeBrBG, | ||
purpleRed_green: schemePRGn, | ||
pink_yellowGreen: schemePiYG, | ||
purple_orange: schemePuOr, | ||
red_blue: schemeRdBu, | ||
red_grey: schemeRdGy, | ||
red_yellow_blue: schemeRdYlBu, | ||
red_yellow_green: schemeRdYlGn, | ||
spectral: schemeSpectral | ||
}; | ||
var divergingColorSchemeIds = Object.keys(divergingColorSchemes); | ||
var divergingColorInterpolators = { | ||
brown_blueGreen: interpolateBrBG, | ||
purpleRed_green: interpolatePRGn, | ||
pink_yellowGreen: interpolatePiYG, | ||
purple_orange: interpolatePuOr, | ||
red_blue: interpolateRdBu, | ||
red_grey: interpolateRdGy, | ||
red_yellow_blue: interpolateRdYlBu, | ||
red_yellow_green: interpolateRdYlGn, | ||
spectral: interpolateSpectral | ||
}; | ||
var sequentialColorSchemes = { | ||
blues: schemeBlues, | ||
greens: schemeGreens, | ||
greys: schemeGreys, | ||
oranges: schemeOranges, | ||
purples: schemePurples, | ||
reds: schemeReds, | ||
blue_green: schemeBuGn, | ||
blue_purple: schemeBuPu, | ||
green_blue: schemeGnBu, | ||
orange_red: schemeOrRd, | ||
purple_blue_green: schemePuBuGn, | ||
purple_blue: schemePuBu, | ||
purple_red: schemePuRd, | ||
red_purple: schemeRdPu, | ||
yellow_green_blue: schemeYlGnBu, | ||
yellow_green: schemeYlGn, | ||
yellow_orange_brown: schemeYlOrBr, | ||
yellow_orange_red: schemeYlOrRd | ||
}; | ||
var sequentialColorSchemeIds = Object.keys(sequentialColorSchemes); | ||
var sequentialColorInterpolators = { | ||
blues: interpolateBlues, | ||
greens: interpolateGreens, | ||
greys: interpolateGreys, | ||
oranges: interpolateOranges, | ||
purples: interpolatePurples, | ||
reds: interpolateReds, | ||
turbo: interpolateTurbo, | ||
viridis: interpolateViridis, | ||
inferno: interpolateInferno, | ||
magma: interpolateMagma, | ||
plasma: interpolatePlasma, | ||
cividis: interpolateCividis, | ||
warm: interpolateWarm, | ||
cool: interpolateCool, | ||
cubehelixDefault: interpolateCubehelixDefault, | ||
blue_green: interpolateBuGn, | ||
blue_purple: interpolateBuPu, | ||
green_blue: interpolateGnBu, | ||
orange_red: interpolateOrRd, | ||
purple_blue_green: interpolatePuBuGn, | ||
purple_blue: interpolatePuBu, | ||
purple_red: interpolatePuRd, | ||
red_purple: interpolateRdPu, | ||
yellow_green_blue: interpolateYlGnBu, | ||
yellow_green: interpolateYlGn, | ||
yellow_orange_brown: interpolateYlOrBr, | ||
yellow_orange_red: interpolateYlOrRd | ||
}; | ||
var colorSchemes = _objectSpread2(_objectSpread2(_objectSpread2({}, categoricalColorSchemes), divergingColorSchemes), sequentialColorSchemes); | ||
var colorSchemeIds = Object.keys(colorSchemes); | ||
var isCategoricalColorScheme = function isCategoricalColorScheme(scheme) { | ||
return categoricalColorSchemeIds.includes(scheme); | ||
}; | ||
var isDivergingColorScheme = function isDivergingColorScheme(scheme) { | ||
return divergingColorSchemeIds.includes(scheme); | ||
}; | ||
var isSequentialColorScheme = function isSequentialColorScheme(scheme) { | ||
return sequentialColorSchemeIds.includes(scheme); | ||
}; | ||
var cyclicalColorInterpolators = { | ||
rainbow: interpolateRainbow, | ||
sinebow: interpolateSinebow | ||
}; | ||
var colorInterpolators = _objectSpread2(_objectSpread2(_objectSpread2({}, divergingColorInterpolators), sequentialColorInterpolators), cyclicalColorInterpolators); | ||
var colorInterpolatorIds = Object.keys(colorInterpolators); | ||
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 _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 _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 _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(); | ||
} | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
var it; | ||
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
var F = function F() {}; | ||
return { | ||
s: F, | ||
n: function n() { | ||
if (i >= o.length) return { | ||
done: true | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}, | ||
e: function e(_e) { | ||
throw _e; | ||
}, | ||
f: F | ||
}; | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var normalCompletion = true, | ||
didErr = false, | ||
err; | ||
return { | ||
s: function s() { | ||
it = o[Symbol.iterator](); | ||
}, | ||
n: function n() { | ||
var step = it.next(); | ||
normalCompletion = step.done; | ||
return step; | ||
}, | ||
e: function e(_e2) { | ||
didErr = true; | ||
err = _e2; | ||
}, | ||
f: function f() { | ||
try { | ||
if (!normalCompletion && it["return"] != null) it["return"](); | ||
} finally { | ||
if (didErr) throw err; | ||
} | ||
} | ||
}; | ||
} | ||
var isInheritedColorConfigFromTheme = function isInheritedColorConfigFromTheme(config) { | ||
return config.theme !== undefined; | ||
}; | ||
var isInheritedColorConfigFromContext = function isInheritedColorConfigFromContext(config) { | ||
return config.from !== undefined; | ||
}; | ||
var getInheritedColorGenerator = function getInheritedColorGenerator(config, theme) { | ||
if (typeof config === 'function') { | ||
return config; | ||
} | ||
if (_isPlainObject(config)) { | ||
if (isInheritedColorConfigFromTheme(config)) { | ||
if (theme === undefined) { | ||
throw new Error("Unable to use color from theme as no theme was provided"); | ||
} | ||
var themeColor = _get(theme, config.theme); | ||
if (themeColor === undefined) { | ||
throw new Error("Color from theme is undefined at path: '".concat(config.theme, "'")); | ||
} | ||
return function () { | ||
return themeColor; | ||
}; | ||
} | ||
if (isInheritedColorConfigFromContext(config)) { | ||
var getColor = function getColor(d) { | ||
return _get(d, config.from); | ||
}; | ||
if (Array.isArray(config.modifiers)) { | ||
var modifiers = []; | ||
var _iterator = _createForOfIteratorHelper(config.modifiers), | ||
_step; | ||
try { | ||
var _loop = function _loop() { | ||
var modifier = _step.value; | ||
var _modifier = _slicedToArray(modifier, 2), | ||
modifierType = _modifier[0], | ||
amount = _modifier[1]; | ||
if (modifierType === 'brighter') { | ||
modifiers.push(function (color) { | ||
return color.brighter(amount); | ||
}); | ||
} else if (modifierType === 'darker') { | ||
modifiers.push(function (color) { | ||
return color.darker(amount); | ||
}); | ||
} else if (modifierType === 'opacity') { | ||
modifiers.push(function (color) { | ||
color.opacity = amount; | ||
return color; | ||
}); | ||
} else { | ||
throw new Error("Invalid color modifier: '".concat(modifierType, "', must be one of: 'brighter', 'darker', 'opacity'")); | ||
} | ||
}; | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
_loop(); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
if (modifiers.length === 0) return getColor; | ||
return function (datum) { | ||
return modifiers.reduce(function (color, modify) { | ||
return modify(color); | ||
}, rgb(getColor(datum))).toString(); | ||
}; | ||
} | ||
return getColor; | ||
} | ||
throw new Error("Invalid color spec, you should either specify 'theme' or 'from' when using a config object"); | ||
} | ||
return function () { | ||
return config; | ||
}; | ||
}; | ||
var useInheritedColor = function useInheritedColor(config, theme) { | ||
return useMemo(function () { | ||
return getInheritedColorGenerator(config, theme); | ||
}, [config, theme]); | ||
}; | ||
var interpolateColor = function interpolateColor(color, springConfig) { | ||
var colorComponents = rgb(color); | ||
if (!springConfig) { | ||
return { | ||
colorR: colorComponents.r, | ||
colorG: colorComponents.g, | ||
colorB: colorComponents.b | ||
}; | ||
} | ||
var configWithPrecision = _objectSpread2(_objectSpread2({}, springConfig), {}, { | ||
precision: 1 | ||
}); | ||
return { | ||
colorR: spring(colorComponents.r, configWithPrecision), | ||
colorG: spring(colorComponents.g, configWithPrecision), | ||
colorB: spring(colorComponents.b, configWithPrecision) | ||
}; | ||
}; | ||
var getInterpolatedColor = function getInterpolatedColor(_ref) { | ||
var colorR = _ref.colorR, | ||
colorG = _ref.colorG, | ||
colorB = _ref.colorB; | ||
return "rgb(".concat(Math.round(Math.max(colorR, 0)), ",").concat(Math.round(Math.max(colorG, 0)), ",").concat(Math.round(Math.max(colorB, 0)), ")"); | ||
}; | ||
var isOrdinalColorScaleConfigScheme = function isOrdinalColorScaleConfigScheme(config) { | ||
return config.scheme !== undefined; | ||
}; | ||
var isOrdinalColorScaleConfigDatumProperty = function isOrdinalColorScaleConfigDatumProperty(config) { | ||
return config.datum !== undefined; | ||
}; | ||
var getOrdinalColorScale = function getOrdinalColorScale(config, identity) { | ||
if (typeof config === 'function') { | ||
return config; | ||
} | ||
var getIdentity = typeof identity === 'function' ? identity : function (datum) { | ||
return _get(datum, identity); | ||
}; | ||
if (Array.isArray(config)) { | ||
var scale = scaleOrdinal(config); | ||
var generator = function generator(datum) { | ||
return scale(getIdentity(datum)); | ||
}; | ||
generator.scale = scale; | ||
return generator; | ||
} | ||
if (_isPlainObject(config)) { | ||
if (isOrdinalColorScaleConfigDatumProperty(config)) { | ||
return function (datum) { | ||
return _get(datum, config.datum); | ||
}; | ||
} | ||
if (isOrdinalColorScaleConfigScheme(config)) { | ||
if (isCategoricalColorScheme(config.scheme)) { | ||
var _scale = scaleOrdinal(colorSchemes[config.scheme]); | ||
var _generator = function _generator(datum) { | ||
return _scale(getIdentity(datum)); | ||
}; | ||
_generator.scale = _scale; | ||
return _generator; | ||
} | ||
if (isDivergingColorScheme(config.scheme)) { | ||
if (config.size !== undefined && (config.size < 3 || config.size > 11)) { | ||
throw new Error("Invalid size '".concat(config.size, "' for diverging color scheme '").concat(config.scheme, "', must be between 3~11")); | ||
} | ||
var _scale2 = scaleOrdinal(colorSchemes[config.scheme][config.size || 11]); | ||
var _generator2 = function _generator2(d) { | ||
return _scale2(getIdentity(d)); | ||
}; | ||
_generator2.scale = _scale2; | ||
return _generator2; | ||
} | ||
if (isSequentialColorScheme(config.scheme)) { | ||
if (config.size !== undefined && (config.size < 3 || config.size > 9)) { | ||
throw new Error("Invalid size '".concat(config.size, "' for sequential color scheme '").concat(config.scheme, "', must be between 3~9")); | ||
} | ||
var _scale3 = scaleOrdinal(colorSchemes[config.scheme][config.size || 9]); | ||
var _generator3 = function _generator3(d) { | ||
return _scale3(getIdentity(d)); | ||
}; | ||
_generator3.scale = _scale3; | ||
return _generator3; | ||
} | ||
} | ||
throw new Error("Invalid colors, when using an object, you should either pass a 'datum' or a 'scheme' property"); | ||
} | ||
return function () { | ||
return config; | ||
}; | ||
}; | ||
var useOrdinalColorScale = function useOrdinalColorScale(config, identity) { | ||
return useMemo(function () { | ||
return getOrdinalColorScale(config, identity); | ||
}, [config, identity]); | ||
}; | ||
var ordinalColorsPropType = PropTypes.oneOfType([PropTypes.func, PropTypes.arrayOf(PropTypes.string), PropTypes.shape({ | ||
scheme: PropTypes.oneOf(colorSchemeIds).isRequired, | ||
size: PropTypes.number | ||
}), PropTypes.shape({ | ||
datum: PropTypes.string.isRequired | ||
}), PropTypes.string]); | ||
var colorPropertyAccessorPropType = PropTypes.oneOfType([PropTypes.func, PropTypes.string]); | ||
var inheritedColorPropType = PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.shape({ | ||
theme: PropTypes.string.isRequired | ||
}), PropTypes.shape({ | ||
from: PropTypes.string.isRequired, | ||
modifiers: PropTypes.arrayOf(PropTypes.array) | ||
})]); | ||
export { categoricalColorSchemeIds, categoricalColorSchemes, colorInterpolatorIds, colorInterpolators, colorPropertyAccessorPropType, colorSchemeIds, colorSchemes, cyclicalColorInterpolators, divergingColorInterpolators, divergingColorSchemeIds, divergingColorSchemes, getInheritedColorGenerator, getInterpolatedColor, getOrdinalColorScale, inheritedColorPropType, interpolateColor, isCategoricalColorScheme, isDivergingColorScheme, isSequentialColorScheme, ordinalColorsPropType, sequentialColorInterpolators, sequentialColorSchemeIds, sequentialColorSchemes, useInheritedColor, useOrdinalColorScale }; | ||
import{schemeCategory10 as e,schemeAccent as r,schemeDark2 as n,schemePaired as o,schemePastel1 as t,schemePastel2 as i,schemeSet1 as u,schemeSet2 as a,schemeSet3 as l,schemeBrBG as c,schemePRGn as s,schemePiYG as f,schemePuOr as p,schemeRdBu as d,schemeRdGy as m,schemeRdYlBu as h,schemeRdYlGn as b,schemeSpectral as g,interpolateBrBG as y,interpolatePRGn as _,interpolatePiYG as w,interpolatePuOr as v,interpolateRdBu as O,interpolateRdGy as j,interpolateRdYlBu as z,interpolateRdYlGn as k,interpolateSpectral as A,schemeBlues as R,schemeGreens as E,schemeGreys as I,schemeOranges as G,schemePurples as M,schemeReds as x,schemeBuGn as S,schemeBuPu as q,schemeGnBu as T,schemeOrRd as B,schemePuBuGn as C,schemePuBu as P,schemePuRd as U,schemeRdPu as D,schemeYlGnBu as $,schemeYlGn as F,schemeYlOrBr as H,schemeYlOrRd as J,interpolateBlues as K,interpolateGreens as L,interpolateGreys as N,interpolateOranges as Q,interpolatePurples as V,interpolateReds as W,interpolateTurbo as X,interpolateViridis as Y,interpolateInferno as Z,interpolateMagma as ee,interpolatePlasma as re,interpolateCividis as ne,interpolateWarm as oe,interpolateCool as te,interpolateCubehelixDefault as ie,interpolateBuGn as ue,interpolateBuPu as ae,interpolateGnBu as le,interpolateOrRd as ce,interpolatePuBuGn as se,interpolatePuBu as fe,interpolatePuRd as pe,interpolateRdPu as de,interpolateYlGnBu as me,interpolateYlGn as he,interpolateYlOrBr as be,interpolateYlOrRd as ge,interpolateRainbow as ye,interpolateSinebow as _e}from"d3-scale-chromatic";import we from"lodash/isPlainObject";import ve from"lodash/get";import{useMemo as Oe}from"react";import{rgb as je}from"d3-color";import{spring as ze}from"react-motion";import{scaleOrdinal as ke}from"d3-scale";import Ae from"prop-types";function Re(){return Re=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},Re.apply(this,arguments)}function Ee(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,o=new Array(r);n<r;n++)o[n]=e[n];return o}function Ie(e,r){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return Ee(e,r);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Ee(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){n&&(e=n);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var Ge={nivo:["#e8c1a0","#f47560","#f1e15b","#e8a838","#61cdbb","#97e3d5"],category10:e,accent:r,dark2:n,paired:o,pastel1:t,pastel2:i,set1:u,set2:a,set3:l},Me=Object.keys(Ge),xe={brown_blueGreen:c,purpleRed_green:s,pink_yellowGreen:f,purple_orange:p,red_blue:d,red_grey:m,red_yellow_blue:h,red_yellow_green:b,spectral:g},Se=Object.keys(xe),qe={brown_blueGreen:y,purpleRed_green:_,pink_yellowGreen:w,purple_orange:v,red_blue:O,red_grey:j,red_yellow_blue:z,red_yellow_green:k,spectral:A},Te={blues:R,greens:E,greys:I,oranges:G,purples:M,reds:x,blue_green:S,blue_purple:q,green_blue:T,orange_red:B,purple_blue_green:C,purple_blue:P,purple_red:U,red_purple:D,yellow_green_blue:$,yellow_green:F,yellow_orange_brown:H,yellow_orange_red:J},Be=Object.keys(Te),Ce={blues:K,greens:L,greys:N,oranges:Q,purples:V,reds:W,turbo:X,viridis:Y,inferno:Z,magma:ee,plasma:re,cividis:ne,warm:oe,cool:te,cubehelixDefault:ie,blue_green:ue,blue_purple:ae,green_blue:le,orange_red:ce,purple_blue_green:se,purple_blue:fe,purple_red:pe,red_purple:de,yellow_green_blue:me,yellow_green:he,yellow_orange_brown:be,yellow_orange_red:ge},Pe=Re({},Ge,xe,Te),Ue=Object.keys(Pe),De=function(e){return Me.includes(e)},$e=function(e){return Se.includes(e)},Fe=function(e){return Be.includes(e)},He={rainbow:ye,sinebow:_e},Je=Re({},qe,Ce,He),Ke=Object.keys(Je),Le=function(e,r){if("function"==typeof e)return e;if(we(e)){if(function(e){return void 0!==e.theme}(e)){if(void 0===r)throw new Error("Unable to use color from theme as no theme was provided");var n=ve(r,e.theme);if(void 0===n)throw new Error("Color from theme is undefined at path: '"+e.theme+"'");return function(){return n}}if(function(e){return void 0!==e.from}(e)){var o=function(r){return ve(r,e.from)};if(Array.isArray(e.modifiers)){for(var t,i=[],u=function(){var e=t.value,r=e[0],n=e[1];if("brighter"===r)i.push((function(e){return e.brighter(n)}));else if("darker"===r)i.push((function(e){return e.darker(n)}));else{if("opacity"!==r)throw new Error("Invalid color modifier: '"+r+"', must be one of: 'brighter', 'darker', 'opacity'");i.push((function(e){return e.opacity=n,e}))}},a=Ie(e.modifiers);!(t=a()).done;)u();return 0===i.length?o:function(e){return i.reduce((function(e,r){return r(e)}),je(o(e))).toString()}}return o}throw new Error("Invalid color spec, you should either specify 'theme' or 'from' when using a config object")}return function(){return e}},Ne=function(e,r){return Oe((function(){return Le(e,r)}),[e,r])},Qe=function(e,r){var n=je(e);if(!r)return{colorR:n.r,colorG:n.g,colorB:n.b};var o=Re({},r,{precision:1});return{colorR:ze(n.r,o),colorG:ze(n.g,o),colorB:ze(n.b,o)}},Ve=function(e){var r=e.colorR,n=e.colorG,o=e.colorB;return"rgb("+Math.round(Math.max(r,0))+","+Math.round(Math.max(n,0))+","+Math.round(Math.max(o,0))+")"},We=function(e,r){if("function"==typeof e)return e;var n="function"==typeof r?r:function(e){return ve(e,r)};if(Array.isArray(e)){var o=ke(e),t=function(e){return o(n(e))};return t.scale=o,t}if(we(e)){if(function(e){return void 0!==e.datum}(e))return function(r){return ve(r,e.datum)};if(function(e){return void 0!==e.scheme}(e)){if(De(e.scheme)){var i=ke(Pe[e.scheme]),u=function(e){return i(n(e))};return u.scale=i,u}if($e(e.scheme)){if(void 0!==e.size&&(e.size<3||e.size>11))throw new Error("Invalid size '"+e.size+"' for diverging color scheme '"+e.scheme+"', must be between 3~11");var a=ke(Pe[e.scheme][e.size||11]),l=function(e){return a(n(e))};return l.scale=a,l}if(Fe(e.scheme)){if(void 0!==e.size&&(e.size<3||e.size>9))throw new Error("Invalid size '"+e.size+"' for sequential color scheme '"+e.scheme+"', must be between 3~9");var c=ke(Pe[e.scheme][e.size||9]),s=function(e){return c(n(e))};return s.scale=c,s}}throw new Error("Invalid colors, when using an object, you should either pass a 'datum' or a 'scheme' property")}return function(){return e}},Xe=function(e,r){return Oe((function(){return We(e,r)}),[e,r])},Ye=Ae.oneOfType([Ae.func,Ae.arrayOf(Ae.string),Ae.shape({scheme:Ae.oneOf(Ue).isRequired,size:Ae.number}),Ae.shape({datum:Ae.string.isRequired}),Ae.string]),Ze=Ae.oneOfType([Ae.func,Ae.string]),er=Ae.oneOfType([Ae.string,Ae.func,Ae.shape({theme:Ae.string.isRequired}),Ae.shape({from:Ae.string.isRequired,modifiers:Ae.arrayOf(Ae.array)})]);export{Me as categoricalColorSchemeIds,Ge as categoricalColorSchemes,Ke as colorInterpolatorIds,Je as colorInterpolators,Ze as colorPropertyAccessorPropType,Ue as colorSchemeIds,Pe as colorSchemes,He as cyclicalColorInterpolators,qe as divergingColorInterpolators,Se as divergingColorSchemeIds,xe as divergingColorSchemes,Le as getInheritedColorGenerator,Ve as getInterpolatedColor,We as getOrdinalColorScale,er as inheritedColorPropType,Qe as interpolateColor,De as isCategoricalColorScheme,$e as isDivergingColorScheme,Fe as isSequentialColorScheme,Ye as ordinalColorsPropType,Ce as sequentialColorInterpolators,Be as sequentialColorSchemeIds,Te as sequentialColorSchemes,Ne as useInheritedColor,Xe as useOrdinalColorScale}; | ||
//# sourceMappingURL=nivo-colors.es.js.map |
@@ -1,530 +0,2 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-scale-chromatic'), require('lodash/isPlainObject'), require('lodash/get'), require('react'), require('d3-color'), require('react-motion'), require('d3-scale'), require('prop-types')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'd3-scale-chromatic', 'lodash/isPlainObject', 'lodash/get', 'react', 'd3-color', 'react-motion', 'd3-scale', 'prop-types'], factory) : | ||
(global = global || self, factory(global.nivo = global.nivo || {}, global.d3, global['lodash/isPlainObject'], global['lodash/get'], global.React, global.d3, global.ReactMotion, global.d3, global.PropTypes)); | ||
}(this, (function (exports, d3ScaleChromatic, _isPlainObject, _get, react, d3Color, reactMotion, d3Scale, PropTypes) { 'use strict'; | ||
_isPlainObject = _isPlainObject && Object.prototype.hasOwnProperty.call(_isPlainObject, 'default') ? _isPlainObject['default'] : _isPlainObject; | ||
_get = _get && Object.prototype.hasOwnProperty.call(_get, 'default') ? _get['default'] : _get; | ||
PropTypes = PropTypes && Object.prototype.hasOwnProperty.call(PropTypes, 'default') ? PropTypes['default'] : PropTypes; | ||
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 categoricalColorSchemes = { | ||
nivo: ['#e8c1a0', '#f47560', '#f1e15b', '#e8a838', '#61cdbb', '#97e3d5'], | ||
category10: d3ScaleChromatic.schemeCategory10, | ||
accent: d3ScaleChromatic.schemeAccent, | ||
dark2: d3ScaleChromatic.schemeDark2, | ||
paired: d3ScaleChromatic.schemePaired, | ||
pastel1: d3ScaleChromatic.schemePastel1, | ||
pastel2: d3ScaleChromatic.schemePastel2, | ||
set1: d3ScaleChromatic.schemeSet1, | ||
set2: d3ScaleChromatic.schemeSet2, | ||
set3: d3ScaleChromatic.schemeSet3 | ||
}; | ||
var categoricalColorSchemeIds = Object.keys(categoricalColorSchemes); | ||
var divergingColorSchemes = { | ||
brown_blueGreen: d3ScaleChromatic.schemeBrBG, | ||
purpleRed_green: d3ScaleChromatic.schemePRGn, | ||
pink_yellowGreen: d3ScaleChromatic.schemePiYG, | ||
purple_orange: d3ScaleChromatic.schemePuOr, | ||
red_blue: d3ScaleChromatic.schemeRdBu, | ||
red_grey: d3ScaleChromatic.schemeRdGy, | ||
red_yellow_blue: d3ScaleChromatic.schemeRdYlBu, | ||
red_yellow_green: d3ScaleChromatic.schemeRdYlGn, | ||
spectral: d3ScaleChromatic.schemeSpectral | ||
}; | ||
var divergingColorSchemeIds = Object.keys(divergingColorSchemes); | ||
var divergingColorInterpolators = { | ||
brown_blueGreen: d3ScaleChromatic.interpolateBrBG, | ||
purpleRed_green: d3ScaleChromatic.interpolatePRGn, | ||
pink_yellowGreen: d3ScaleChromatic.interpolatePiYG, | ||
purple_orange: d3ScaleChromatic.interpolatePuOr, | ||
red_blue: d3ScaleChromatic.interpolateRdBu, | ||
red_grey: d3ScaleChromatic.interpolateRdGy, | ||
red_yellow_blue: d3ScaleChromatic.interpolateRdYlBu, | ||
red_yellow_green: d3ScaleChromatic.interpolateRdYlGn, | ||
spectral: d3ScaleChromatic.interpolateSpectral | ||
}; | ||
var sequentialColorSchemes = { | ||
blues: d3ScaleChromatic.schemeBlues, | ||
greens: d3ScaleChromatic.schemeGreens, | ||
greys: d3ScaleChromatic.schemeGreys, | ||
oranges: d3ScaleChromatic.schemeOranges, | ||
purples: d3ScaleChromatic.schemePurples, | ||
reds: d3ScaleChromatic.schemeReds, | ||
blue_green: d3ScaleChromatic.schemeBuGn, | ||
blue_purple: d3ScaleChromatic.schemeBuPu, | ||
green_blue: d3ScaleChromatic.schemeGnBu, | ||
orange_red: d3ScaleChromatic.schemeOrRd, | ||
purple_blue_green: d3ScaleChromatic.schemePuBuGn, | ||
purple_blue: d3ScaleChromatic.schemePuBu, | ||
purple_red: d3ScaleChromatic.schemePuRd, | ||
red_purple: d3ScaleChromatic.schemeRdPu, | ||
yellow_green_blue: d3ScaleChromatic.schemeYlGnBu, | ||
yellow_green: d3ScaleChromatic.schemeYlGn, | ||
yellow_orange_brown: d3ScaleChromatic.schemeYlOrBr, | ||
yellow_orange_red: d3ScaleChromatic.schemeYlOrRd | ||
}; | ||
var sequentialColorSchemeIds = Object.keys(sequentialColorSchemes); | ||
var sequentialColorInterpolators = { | ||
blues: d3ScaleChromatic.interpolateBlues, | ||
greens: d3ScaleChromatic.interpolateGreens, | ||
greys: d3ScaleChromatic.interpolateGreys, | ||
oranges: d3ScaleChromatic.interpolateOranges, | ||
purples: d3ScaleChromatic.interpolatePurples, | ||
reds: d3ScaleChromatic.interpolateReds, | ||
turbo: d3ScaleChromatic.interpolateTurbo, | ||
viridis: d3ScaleChromatic.interpolateViridis, | ||
inferno: d3ScaleChromatic.interpolateInferno, | ||
magma: d3ScaleChromatic.interpolateMagma, | ||
plasma: d3ScaleChromatic.interpolatePlasma, | ||
cividis: d3ScaleChromatic.interpolateCividis, | ||
warm: d3ScaleChromatic.interpolateWarm, | ||
cool: d3ScaleChromatic.interpolateCool, | ||
cubehelixDefault: d3ScaleChromatic.interpolateCubehelixDefault, | ||
blue_green: d3ScaleChromatic.interpolateBuGn, | ||
blue_purple: d3ScaleChromatic.interpolateBuPu, | ||
green_blue: d3ScaleChromatic.interpolateGnBu, | ||
orange_red: d3ScaleChromatic.interpolateOrRd, | ||
purple_blue_green: d3ScaleChromatic.interpolatePuBuGn, | ||
purple_blue: d3ScaleChromatic.interpolatePuBu, | ||
purple_red: d3ScaleChromatic.interpolatePuRd, | ||
red_purple: d3ScaleChromatic.interpolateRdPu, | ||
yellow_green_blue: d3ScaleChromatic.interpolateYlGnBu, | ||
yellow_green: d3ScaleChromatic.interpolateYlGn, | ||
yellow_orange_brown: d3ScaleChromatic.interpolateYlOrBr, | ||
yellow_orange_red: d3ScaleChromatic.interpolateYlOrRd | ||
}; | ||
var colorSchemes = _objectSpread2(_objectSpread2(_objectSpread2({}, categoricalColorSchemes), divergingColorSchemes), sequentialColorSchemes); | ||
var colorSchemeIds = Object.keys(colorSchemes); | ||
var isCategoricalColorScheme = function isCategoricalColorScheme(scheme) { | ||
return categoricalColorSchemeIds.includes(scheme); | ||
}; | ||
var isDivergingColorScheme = function isDivergingColorScheme(scheme) { | ||
return divergingColorSchemeIds.includes(scheme); | ||
}; | ||
var isSequentialColorScheme = function isSequentialColorScheme(scheme) { | ||
return sequentialColorSchemeIds.includes(scheme); | ||
}; | ||
var cyclicalColorInterpolators = { | ||
rainbow: d3ScaleChromatic.interpolateRainbow, | ||
sinebow: d3ScaleChromatic.interpolateSinebow | ||
}; | ||
var colorInterpolators = _objectSpread2(_objectSpread2(_objectSpread2({}, divergingColorInterpolators), sequentialColorInterpolators), cyclicalColorInterpolators); | ||
var colorInterpolatorIds = Object.keys(colorInterpolators); | ||
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 _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 _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 _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(); | ||
} | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
var it; | ||
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
var F = function F() {}; | ||
return { | ||
s: F, | ||
n: function n() { | ||
if (i >= o.length) return { | ||
done: true | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}, | ||
e: function e(_e) { | ||
throw _e; | ||
}, | ||
f: F | ||
}; | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var normalCompletion = true, | ||
didErr = false, | ||
err; | ||
return { | ||
s: function s() { | ||
it = o[Symbol.iterator](); | ||
}, | ||
n: function n() { | ||
var step = it.next(); | ||
normalCompletion = step.done; | ||
return step; | ||
}, | ||
e: function e(_e2) { | ||
didErr = true; | ||
err = _e2; | ||
}, | ||
f: function f() { | ||
try { | ||
if (!normalCompletion && it["return"] != null) it["return"](); | ||
} finally { | ||
if (didErr) throw err; | ||
} | ||
} | ||
}; | ||
} | ||
var isInheritedColorConfigFromTheme = function isInheritedColorConfigFromTheme(config) { | ||
return config.theme !== undefined; | ||
}; | ||
var isInheritedColorConfigFromContext = function isInheritedColorConfigFromContext(config) { | ||
return config.from !== undefined; | ||
}; | ||
var getInheritedColorGenerator = function getInheritedColorGenerator(config, theme) { | ||
if (typeof config === 'function') { | ||
return config; | ||
} | ||
if (_isPlainObject(config)) { | ||
if (isInheritedColorConfigFromTheme(config)) { | ||
if (theme === undefined) { | ||
throw new Error("Unable to use color from theme as no theme was provided"); | ||
} | ||
var themeColor = _get(theme, config.theme); | ||
if (themeColor === undefined) { | ||
throw new Error("Color from theme is undefined at path: '".concat(config.theme, "'")); | ||
} | ||
return function () { | ||
return themeColor; | ||
}; | ||
} | ||
if (isInheritedColorConfigFromContext(config)) { | ||
var getColor = function getColor(d) { | ||
return _get(d, config.from); | ||
}; | ||
if (Array.isArray(config.modifiers)) { | ||
var modifiers = []; | ||
var _iterator = _createForOfIteratorHelper(config.modifiers), | ||
_step; | ||
try { | ||
var _loop = function _loop() { | ||
var modifier = _step.value; | ||
var _modifier = _slicedToArray(modifier, 2), | ||
modifierType = _modifier[0], | ||
amount = _modifier[1]; | ||
if (modifierType === 'brighter') { | ||
modifiers.push(function (color) { | ||
return color.brighter(amount); | ||
}); | ||
} else if (modifierType === 'darker') { | ||
modifiers.push(function (color) { | ||
return color.darker(amount); | ||
}); | ||
} else if (modifierType === 'opacity') { | ||
modifiers.push(function (color) { | ||
color.opacity = amount; | ||
return color; | ||
}); | ||
} else { | ||
throw new Error("Invalid color modifier: '".concat(modifierType, "', must be one of: 'brighter', 'darker', 'opacity'")); | ||
} | ||
}; | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
_loop(); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
if (modifiers.length === 0) return getColor; | ||
return function (datum) { | ||
return modifiers.reduce(function (color, modify) { | ||
return modify(color); | ||
}, d3Color.rgb(getColor(datum))).toString(); | ||
}; | ||
} | ||
return getColor; | ||
} | ||
throw new Error("Invalid color spec, you should either specify 'theme' or 'from' when using a config object"); | ||
} | ||
return function () { | ||
return config; | ||
}; | ||
}; | ||
var useInheritedColor = function useInheritedColor(config, theme) { | ||
return react.useMemo(function () { | ||
return getInheritedColorGenerator(config, theme); | ||
}, [config, theme]); | ||
}; | ||
var interpolateColor = function interpolateColor(color, springConfig) { | ||
var colorComponents = d3Color.rgb(color); | ||
if (!springConfig) { | ||
return { | ||
colorR: colorComponents.r, | ||
colorG: colorComponents.g, | ||
colorB: colorComponents.b | ||
}; | ||
} | ||
var configWithPrecision = _objectSpread2(_objectSpread2({}, springConfig), {}, { | ||
precision: 1 | ||
}); | ||
return { | ||
colorR: reactMotion.spring(colorComponents.r, configWithPrecision), | ||
colorG: reactMotion.spring(colorComponents.g, configWithPrecision), | ||
colorB: reactMotion.spring(colorComponents.b, configWithPrecision) | ||
}; | ||
}; | ||
var getInterpolatedColor = function getInterpolatedColor(_ref) { | ||
var colorR = _ref.colorR, | ||
colorG = _ref.colorG, | ||
colorB = _ref.colorB; | ||
return "rgb(".concat(Math.round(Math.max(colorR, 0)), ",").concat(Math.round(Math.max(colorG, 0)), ",").concat(Math.round(Math.max(colorB, 0)), ")"); | ||
}; | ||
var isOrdinalColorScaleConfigScheme = function isOrdinalColorScaleConfigScheme(config) { | ||
return config.scheme !== undefined; | ||
}; | ||
var isOrdinalColorScaleConfigDatumProperty = function isOrdinalColorScaleConfigDatumProperty(config) { | ||
return config.datum !== undefined; | ||
}; | ||
var getOrdinalColorScale = function getOrdinalColorScale(config, identity) { | ||
if (typeof config === 'function') { | ||
return config; | ||
} | ||
var getIdentity = typeof identity === 'function' ? identity : function (datum) { | ||
return _get(datum, identity); | ||
}; | ||
if (Array.isArray(config)) { | ||
var scale = d3Scale.scaleOrdinal(config); | ||
var generator = function generator(datum) { | ||
return scale(getIdentity(datum)); | ||
}; | ||
generator.scale = scale; | ||
return generator; | ||
} | ||
if (_isPlainObject(config)) { | ||
if (isOrdinalColorScaleConfigDatumProperty(config)) { | ||
return function (datum) { | ||
return _get(datum, config.datum); | ||
}; | ||
} | ||
if (isOrdinalColorScaleConfigScheme(config)) { | ||
if (isCategoricalColorScheme(config.scheme)) { | ||
var _scale = d3Scale.scaleOrdinal(colorSchemes[config.scheme]); | ||
var _generator = function _generator(datum) { | ||
return _scale(getIdentity(datum)); | ||
}; | ||
_generator.scale = _scale; | ||
return _generator; | ||
} | ||
if (isDivergingColorScheme(config.scheme)) { | ||
if (config.size !== undefined && (config.size < 3 || config.size > 11)) { | ||
throw new Error("Invalid size '".concat(config.size, "' for diverging color scheme '").concat(config.scheme, "', must be between 3~11")); | ||
} | ||
var _scale2 = d3Scale.scaleOrdinal(colorSchemes[config.scheme][config.size || 11]); | ||
var _generator2 = function _generator2(d) { | ||
return _scale2(getIdentity(d)); | ||
}; | ||
_generator2.scale = _scale2; | ||
return _generator2; | ||
} | ||
if (isSequentialColorScheme(config.scheme)) { | ||
if (config.size !== undefined && (config.size < 3 || config.size > 9)) { | ||
throw new Error("Invalid size '".concat(config.size, "' for sequential color scheme '").concat(config.scheme, "', must be between 3~9")); | ||
} | ||
var _scale3 = d3Scale.scaleOrdinal(colorSchemes[config.scheme][config.size || 9]); | ||
var _generator3 = function _generator3(d) { | ||
return _scale3(getIdentity(d)); | ||
}; | ||
_generator3.scale = _scale3; | ||
return _generator3; | ||
} | ||
} | ||
throw new Error("Invalid colors, when using an object, you should either pass a 'datum' or a 'scheme' property"); | ||
} | ||
return function () { | ||
return config; | ||
}; | ||
}; | ||
var useOrdinalColorScale = function useOrdinalColorScale(config, identity) { | ||
return react.useMemo(function () { | ||
return getOrdinalColorScale(config, identity); | ||
}, [config, identity]); | ||
}; | ||
var ordinalColorsPropType = PropTypes.oneOfType([PropTypes.func, PropTypes.arrayOf(PropTypes.string), PropTypes.shape({ | ||
scheme: PropTypes.oneOf(colorSchemeIds).isRequired, | ||
size: PropTypes.number | ||
}), PropTypes.shape({ | ||
datum: PropTypes.string.isRequired | ||
}), PropTypes.string]); | ||
var colorPropertyAccessorPropType = PropTypes.oneOfType([PropTypes.func, PropTypes.string]); | ||
var inheritedColorPropType = PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.shape({ | ||
theme: PropTypes.string.isRequired | ||
}), PropTypes.shape({ | ||
from: PropTypes.string.isRequired, | ||
modifiers: PropTypes.arrayOf(PropTypes.array) | ||
})]); | ||
exports.categoricalColorSchemeIds = categoricalColorSchemeIds; | ||
exports.categoricalColorSchemes = categoricalColorSchemes; | ||
exports.colorInterpolatorIds = colorInterpolatorIds; | ||
exports.colorInterpolators = colorInterpolators; | ||
exports.colorPropertyAccessorPropType = colorPropertyAccessorPropType; | ||
exports.colorSchemeIds = colorSchemeIds; | ||
exports.colorSchemes = colorSchemes; | ||
exports.cyclicalColorInterpolators = cyclicalColorInterpolators; | ||
exports.divergingColorInterpolators = divergingColorInterpolators; | ||
exports.divergingColorSchemeIds = divergingColorSchemeIds; | ||
exports.divergingColorSchemes = divergingColorSchemes; | ||
exports.getInheritedColorGenerator = getInheritedColorGenerator; | ||
exports.getInterpolatedColor = getInterpolatedColor; | ||
exports.getOrdinalColorScale = getOrdinalColorScale; | ||
exports.inheritedColorPropType = inheritedColorPropType; | ||
exports.interpolateColor = interpolateColor; | ||
exports.isCategoricalColorScheme = isCategoricalColorScheme; | ||
exports.isDivergingColorScheme = isDivergingColorScheme; | ||
exports.isSequentialColorScheme = isSequentialColorScheme; | ||
exports.ordinalColorsPropType = ordinalColorsPropType; | ||
exports.sequentialColorInterpolators = sequentialColorInterpolators; | ||
exports.sequentialColorSchemeIds = sequentialColorSchemeIds; | ||
exports.sequentialColorSchemes = sequentialColorSchemes; | ||
exports.useInheritedColor = useInheritedColor; | ||
exports.useOrdinalColorScale = useOrdinalColorScale; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("d3-scale-chromatic"),require("lodash/isPlainObject"),require("lodash/get"),require("react"),require("d3-color"),require("react-motion"),require("d3-scale"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","d3-scale-chromatic","lodash/isPlainObject","lodash/get","react","d3-color","react-motion","d3-scale","prop-types"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).nivo=e.nivo||{},e.d3,e["lodash/isPlainObject"],e["lodash/get"],e.React,e.d3,e.ReactMotion,e.d3,e.PropTypes)}(this,(function(e,r,t,n,o,l,i,a,u){"use strict";function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=s(t),d=s(n),f=s(u);function p(){return p=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},p.apply(this,arguments)}function h(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function m(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return h(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?h(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var g={nivo:["#e8c1a0","#f47560","#f1e15b","#e8a838","#61cdbb","#97e3d5"],category10:r.schemeCategory10,accent:r.schemeAccent,dark2:r.schemeDark2,paired:r.schemePaired,pastel1:r.schemePastel1,pastel2:r.schemePastel2,set1:r.schemeSet1,set2:r.schemeSet2,set3:r.schemeSet3},y=Object.keys(g),b={brown_blueGreen:r.schemeBrBG,purpleRed_green:r.schemePRGn,pink_yellowGreen:r.schemePiYG,purple_orange:r.schemePuOr,red_blue:r.schemeRdBu,red_grey:r.schemeRdGy,red_yellow_blue:r.schemeRdYlBu,red_yellow_green:r.schemeRdYlGn,spectral:r.schemeSpectral},_=Object.keys(b),v={brown_blueGreen:r.interpolateBrBG,purpleRed_green:r.interpolatePRGn,pink_yellowGreen:r.interpolatePiYG,purple_orange:r.interpolatePuOr,red_blue:r.interpolateRdBu,red_grey:r.interpolateRdGy,red_yellow_blue:r.interpolateRdYlBu,red_yellow_green:r.interpolateRdYlGn,spectral:r.interpolateSpectral},w={blues:r.schemeBlues,greens:r.schemeGreens,greys:r.schemeGreys,oranges:r.schemeOranges,purples:r.schemePurples,reds:r.schemeReds,blue_green:r.schemeBuGn,blue_purple:r.schemeBuPu,green_blue:r.schemeGnBu,orange_red:r.schemeOrRd,purple_blue_green:r.schemePuBuGn,purple_blue:r.schemePuBu,purple_red:r.schemePuRd,red_purple:r.schemeRdPu,yellow_green_blue:r.schemeYlGnBu,yellow_green:r.schemeYlGn,yellow_orange_brown:r.schemeYlOrBr,yellow_orange_red:r.schemeYlOrRd},O=Object.keys(w),G={blues:r.interpolateBlues,greens:r.interpolateGreens,greys:r.interpolateGreys,oranges:r.interpolateOranges,purples:r.interpolatePurples,reds:r.interpolateReds,turbo:r.interpolateTurbo,viridis:r.interpolateViridis,inferno:r.interpolateInferno,magma:r.interpolateMagma,plasma:r.interpolatePlasma,cividis:r.interpolateCividis,warm:r.interpolateWarm,cool:r.interpolateCool,cubehelixDefault:r.interpolateCubehelixDefault,blue_green:r.interpolateBuGn,blue_purple:r.interpolateBuPu,green_blue:r.interpolateGnBu,orange_red:r.interpolateOrRd,purple_blue_green:r.interpolatePuBuGn,purple_blue:r.interpolatePuBu,purple_red:r.interpolatePuRd,red_purple:r.interpolateRdPu,yellow_green_blue:r.interpolateYlGnBu,yellow_green:r.interpolateYlGn,yellow_orange_brown:r.interpolateYlOrBr,yellow_orange_red:r.interpolateYlOrRd},P=p({},g,b,w),R=Object.keys(P),B=function(e){return y.includes(e)},C=function(e){return _.includes(e)},S=function(e){return O.includes(e)},I={rainbow:r.interpolateRainbow,sinebow:r.interpolateSinebow},j=p({},v,G,I),q=Object.keys(j),Y=function(e,r){if("function"==typeof e)return e;if(c.default(e)){if(function(e){return void 0!==e.theme}(e)){if(void 0===r)throw new Error("Unable to use color from theme as no theme was provided");var t=d.default(r,e.theme);if(void 0===t)throw new Error("Color from theme is undefined at path: '"+e.theme+"'");return function(){return t}}if(function(e){return void 0!==e.from}(e)){var n=function(r){return d.default(r,e.from)};if(Array.isArray(e.modifiers)){for(var o,i=[],a=function(){var e=o.value,r=e[0],t=e[1];if("brighter"===r)i.push((function(e){return e.brighter(t)}));else if("darker"===r)i.push((function(e){return e.darker(t)}));else{if("opacity"!==r)throw new Error("Invalid color modifier: '"+r+"', must be one of: 'brighter', 'darker', 'opacity'");i.push((function(e){return e.opacity=t,e}))}},u=m(e.modifiers);!(o=u()).done;)a();return 0===i.length?n:function(e){return i.reduce((function(e,r){return r(e)}),l.rgb(n(e))).toString()}}return n}throw new Error("Invalid color spec, you should either specify 'theme' or 'from' when using a config object")}return function(){return e}},z=function(e,r){if("function"==typeof e)return e;var t="function"==typeof r?r:function(e){return d.default(e,r)};if(Array.isArray(e)){var n=a.scaleOrdinal(e),o=function(e){return n(t(e))};return o.scale=n,o}if(c.default(e)){if(function(e){return void 0!==e.datum}(e))return function(r){return d.default(r,e.datum)};if(function(e){return void 0!==e.scheme}(e)){if(B(e.scheme)){var l=a.scaleOrdinal(P[e.scheme]),i=function(e){return l(t(e))};return i.scale=l,i}if(C(e.scheme)){if(void 0!==e.size&&(e.size<3||e.size>11))throw new Error("Invalid size '"+e.size+"' for diverging color scheme '"+e.scheme+"', must be between 3~11");var u=a.scaleOrdinal(P[e.scheme][e.size||11]),s=function(e){return u(t(e))};return s.scale=u,s}if(S(e.scheme)){if(void 0!==e.size&&(e.size<3||e.size>9))throw new Error("Invalid size '"+e.size+"' for sequential color scheme '"+e.scheme+"', must be between 3~9");var f=a.scaleOrdinal(P[e.scheme][e.size||9]),p=function(e){return f(t(e))};return p.scale=f,p}}throw new Error("Invalid colors, when using an object, you should either pass a 'datum' or a 'scheme' property")}return function(){return e}},k=f.default.oneOfType([f.default.func,f.default.arrayOf(f.default.string),f.default.shape({scheme:f.default.oneOf(R).isRequired,size:f.default.number}),f.default.shape({datum:f.default.string.isRequired}),f.default.string]),A=f.default.oneOfType([f.default.func,f.default.string]),M=f.default.oneOfType([f.default.string,f.default.func,f.default.shape({theme:f.default.string.isRequired}),f.default.shape({from:f.default.string.isRequired,modifiers:f.default.arrayOf(f.default.array)})]);e.categoricalColorSchemeIds=y,e.categoricalColorSchemes=g,e.colorInterpolatorIds=q,e.colorInterpolators=j,e.colorPropertyAccessorPropType=A,e.colorSchemeIds=R,e.colorSchemes=P,e.cyclicalColorInterpolators=I,e.divergingColorInterpolators=v,e.divergingColorSchemeIds=_,e.divergingColorSchemes=b,e.getInheritedColorGenerator=Y,e.getInterpolatedColor=function(e){var r=e.colorR,t=e.colorG,n=e.colorB;return"rgb("+Math.round(Math.max(r,0))+","+Math.round(Math.max(t,0))+","+Math.round(Math.max(n,0))+")"},e.getOrdinalColorScale=z,e.inheritedColorPropType=M,e.interpolateColor=function(e,r){var t=l.rgb(e);if(!r)return{colorR:t.r,colorG:t.g,colorB:t.b};var n=p({},r,{precision:1});return{colorR:i.spring(t.r,n),colorG:i.spring(t.g,n),colorB:i.spring(t.b,n)}},e.isCategoricalColorScheme=B,e.isDivergingColorScheme=C,e.isSequentialColorScheme=S,e.ordinalColorsPropType=k,e.sequentialColorInterpolators=G,e.sequentialColorSchemeIds=O,e.sequentialColorSchemes=w,e.useInheritedColor=function(e,r){return o.useMemo((function(){return Y(e,r)}),[e,r])},e.useOrdinalColorScale=function(e,r){return o.useMemo((function(){return z(e,r)}),[e,r])},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=nivo-colors.umd.js.map |
import PropTypes from 'prop-types'; | ||
export declare const ordinalColorsPropType: PropTypes.Requireable<string | ((...args: any[]) => any) | (string | null)[] | PropTypes.InferProps<{ | ||
export declare const ordinalColorsPropType: PropTypes.Requireable<string | ((...args: any[]) => any) | (string | null | undefined)[] | PropTypes.InferProps<{ | ||
scheme: PropTypes.Validator<import("./schemes").ColorSchemeId>; | ||
@@ -13,4 +13,4 @@ size: PropTypes.Requireable<number>; | ||
from: PropTypes.Validator<string>; | ||
modifiers: PropTypes.Requireable<(any[] | null)[]>; | ||
modifiers: PropTypes.Requireable<(any[] | null | undefined)[]>; | ||
}>>; | ||
//# sourceMappingURL=props.d.ts.map |
{ | ||
"name": "@nivo/colors", | ||
"version": "0.74.1", | ||
"version": "0.75.0", | ||
"license": "MIT", | ||
@@ -31,3 +31,3 @@ "author": { | ||
"devDependencies": { | ||
"@nivo/core": "0.74.1", | ||
"@nivo/core": "0.75.0", | ||
"@types/d3-color": "^2.0.0", | ||
@@ -39,3 +39,3 @@ "@types/d3-scale-chromatic": "^2.0.0", | ||
"peerDependencies": { | ||
"@nivo/core": "0.74.1", | ||
"@nivo/core": "0.75.0", | ||
"prop-types": ">= 15.5.10 < 16.0.0", | ||
@@ -47,3 +47,3 @@ "react": ">= 16.14.0 < 18.0.0" | ||
}, | ||
"gitHead": "4ae8bc60779cb9bb8cb14b16726819217da16133" | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7
136949
560
4
1