@nivo/colors
Advanced tools
Comparing version 0.64.0 to 0.65.0
@@ -8,9 +8,9 @@ 'use strict'; | ||
var d3ScaleChromatic = require('d3-scale-chromatic'); | ||
var _isPlainObject = _interopDefault(require('lodash/isPlainObject')); | ||
var _get = _interopDefault(require('lodash/get')); | ||
var react = require('react'); | ||
var get = _interopDefault(require('lodash.get')); | ||
var isPlainObject = _interopDefault(require('lodash.isplainobject')); | ||
var d3Color = require('d3-color'); | ||
var reactMotion = require('react-motion'); | ||
var d3Scale = require('d3-scale'); | ||
var d3Color = require('d3-color'); | ||
var PropTypes = _interopDefault(require('prop-types')); | ||
var reactMotion = require('react-motion'); | ||
@@ -73,5 +73,3 @@ function _defineProperty(obj, key, value) { | ||
var categoricalColorSchemeIds = Object.keys(categoricalColorSchemes); | ||
var isCategoricalColorScheme = function isCategoricalColorScheme(scheme) { | ||
return categoricalColorSchemeIds.includes(scheme); | ||
}; | ||
var divergingColorSchemes = { | ||
@@ -89,5 +87,14 @@ brown_blueGreen: d3ScaleChromatic.schemeBrBG, | ||
var divergingColorSchemeIds = Object.keys(divergingColorSchemes); | ||
var isDivergingColorScheme = function isDivergingColorScheme(scheme) { | ||
return divergingColorSchemeIds.includes(scheme); | ||
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 = { | ||
@@ -114,17 +121,3 @@ blues: d3ScaleChromatic.schemeBlues, | ||
var sequentialColorSchemeIds = Object.keys(sequentialColorSchemes); | ||
var isSequentialColorScheme = function isSequentialColorScheme(scheme) { | ||
return sequentialColorSchemeIds.includes(scheme); | ||
}; | ||
var colorSchemes = _objectSpread2(_objectSpread2(_objectSpread2({}, categoricalColorSchemes), divergingColorSchemes), sequentialColorSchemes); | ||
var colorSchemeIds = Object.keys(colorSchemes); | ||
var colorInterpolators = { | ||
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 sequentialColorInterpolators = { | ||
blues: d3ScaleChromatic.interpolateBlues, | ||
@@ -136,2 +129,3 @@ greens: d3ScaleChromatic.interpolateGreens, | ||
reds: d3ScaleChromatic.interpolateReds, | ||
turbo: d3ScaleChromatic.interpolateTurbo, | ||
viridis: d3ScaleChromatic.interpolateViridis, | ||
@@ -141,2 +135,3 @@ inferno: d3ScaleChromatic.interpolateInferno, | ||
plasma: d3ScaleChromatic.interpolatePlasma, | ||
cividis: d3ScaleChromatic.interpolateCividis, | ||
warm: d3ScaleChromatic.interpolateWarm, | ||
@@ -156,71 +151,25 @@ cool: d3ScaleChromatic.interpolateCool, | ||
yellow_orange_brown: d3ScaleChromatic.interpolateYlOrBr, | ||
yellow_orange_red: d3ScaleChromatic.interpolateYlOrRd, | ||
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); | ||
var getOrdinalColorScale = function getOrdinalColorScale(instruction, identity) { | ||
if (typeof instruction === 'function') return instruction; | ||
var getIdentity = typeof identity === 'function' ? identity : function (d) { | ||
return get(d, identity); | ||
}; | ||
if (Array.isArray(instruction)) { | ||
var scale = d3Scale.scaleOrdinal(instruction); | ||
var generator = function generator(d) { | ||
return scale(getIdentity(d)); | ||
}; | ||
generator.scale = scale; | ||
return generator; | ||
} | ||
if (isPlainObject(instruction)) { | ||
if (instruction.datum !== undefined) { | ||
return function (datum) { | ||
return get(datum, instruction.datum); | ||
}; | ||
} | ||
if (instruction.scheme !== undefined) { | ||
if (isCategoricalColorScheme(instruction.scheme)) { | ||
var _scale = d3Scale.scaleOrdinal(colorSchemes[instruction.scheme]); | ||
var _generator = function _generator(d) { | ||
return _scale(getIdentity(d)); | ||
}; | ||
_generator.scale = _scale; | ||
return _generator; | ||
} | ||
if (isDivergingColorScheme(instruction.scheme)) { | ||
if (instruction.size !== undefined && (instruction.size < 3 || instruction.size > 11)) { | ||
throw new Error("Invalid size '".concat(instruction.size, "' for diverging color scheme '").concat(instruction.scheme, "', must be between 3~11")); | ||
} | ||
var _scale2 = d3Scale.scaleOrdinal(colorSchemes[instruction.scheme][instruction.size || 11]); | ||
var _generator2 = function _generator2(d) { | ||
return _scale2(getIdentity(d)); | ||
}; | ||
_generator2.scale = _scale2; | ||
return _generator2; | ||
} | ||
if (isSequentialColorScheme(instruction.scheme)) { | ||
if (instruction.size !== undefined && (instruction.size < 3 || instruction.size > 9)) { | ||
throw new Error("Invalid size '".concat(instruction.size, "' for sequential color scheme '").concat(instruction.scheme, "', must be between 3~9")); | ||
} | ||
var _scale3 = d3Scale.scaleOrdinal(colorSchemes[instruction.scheme][instruction.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 instruction; | ||
}; | ||
}; | ||
var useOrdinalColorScale = function useOrdinalColorScale(instruction, identity) { | ||
return react.useMemo(function () { | ||
return getOrdinalColorScale(instruction, identity); | ||
}, [instruction, identity]); | ||
}; | ||
function _arrayWithHoles(arr) { | ||
@@ -330,15 +279,29 @@ if (Array.isArray(arr)) return arr; | ||
var getInheritedColorGenerator = function getInheritedColorGenerator(inheritedColor, theme) { | ||
if (typeof inheritedColor === 'function') return function (node) { | ||
return inheritedColor(node); | ||
}; | ||
if (isPlainObject(inheritedColor)) { | ||
if (inheritedColor.theme !== undefined) { | ||
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 function (datum) { | ||
return config(datum); | ||
}; | ||
} | ||
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, inheritedColor.theme); | ||
var themeColor = _get(theme, config.theme); | ||
if (themeColor === undefined) { | ||
throw new Error("Color from theme is undefined at path: '".concat(inheritedColor.theme, "'")); | ||
throw new Error("Color from theme is undefined at path: '".concat(config.theme, "'")); | ||
} | ||
return function () { | ||
@@ -348,16 +311,22 @@ return themeColor; | ||
} | ||
if (inheritedColor.from !== undefined) { | ||
var getColor = function getColor(datum) { | ||
return get(datum, inheritedColor.from); | ||
if (isInheritedColorConfigFromContext(config)) { | ||
var getColor = function getColor(d) { | ||
return _get(d, config.from); | ||
}; | ||
if (Array.isArray(inheritedColor.modifiers)) { | ||
if (Array.isArray(config.modifiers)) { | ||
var modifiers = []; | ||
var _iterator = _createForOfIteratorHelper(inheritedColor.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') { | ||
@@ -380,2 +349,3 @@ modifiers.push(function (color) { | ||
}; | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
@@ -389,2 +359,3 @@ _loop(); | ||
} | ||
if (modifiers.length === 0) return getColor; | ||
@@ -397,32 +368,22 @@ return function (datum) { | ||
} | ||
return getColor; | ||
} | ||
throw new Error("Invalid color spec, you should either specify 'theme' or 'from' when using a config object"); | ||
} | ||
return function () { | ||
return inheritedColor; | ||
return config; | ||
}; | ||
}; | ||
var useInheritedColor = function useInheritedColor(parentColor, theme) { | ||
var useInheritedColor = function useInheritedColor(config, theme) { | ||
return react.useMemo(function () { | ||
return getInheritedColorGenerator(parentColor, theme); | ||
}, [parentColor, theme]); | ||
return getInheritedColorGenerator(config, theme); | ||
}, [config, theme]); | ||
}; | ||
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) | ||
})]); | ||
var interpolateColor = function interpolateColor(color, springConfig) { | ||
var colorComponents = d3Color.rgb(color); | ||
if (!springConfig) { | ||
@@ -435,5 +396,7 @@ return { | ||
} | ||
var configWithPrecision = _objectSpread2(_objectSpread2({}, springConfig), {}, { | ||
precision: 1 | ||
}); | ||
return { | ||
@@ -452,2 +415,107 @@ colorR: reactMotion.spring(colorComponents.r, configWithPrecision), | ||
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; | ||
@@ -460,2 +528,4 @@ exports.categoricalColorSchemes = categoricalColorSchemes; | ||
exports.colorSchemes = colorSchemes; | ||
exports.cyclicalColorInterpolators = cyclicalColorInterpolators; | ||
exports.divergingColorInterpolators = divergingColorInterpolators; | ||
exports.divergingColorSchemeIds = divergingColorSchemeIds; | ||
@@ -472,2 +542,3 @@ exports.divergingColorSchemes = divergingColorSchemes; | ||
exports.ordinalColorsPropType = ordinalColorsPropType; | ||
exports.sequentialColorInterpolators = sequentialColorInterpolators; | ||
exports.sequentialColorSchemeIds = sequentialColorSchemeIds; | ||
@@ -474,0 +545,0 @@ exports.sequentialColorSchemes = sequentialColorSchemes; |
@@ -1,9 +0,9 @@ | ||
import { schemeCategory10, schemeAccent, schemeDark2, schemePaired, schemePastel1, schemePastel2, schemeSet1, schemeSet2, schemeSet3, schemeBrBG, schemePRGn, schemePiYG, schemePuOr, schemeRdBu, schemeRdGy, schemeRdYlBu, schemeRdYlGn, schemeSpectral, schemeBlues, schemeGreens, schemeGreys, schemeOranges, schemePurples, schemeReds, schemeBuGn, schemeBuPu, schemeGnBu, schemeOrRd, schemePuBuGn, schemePuBu, schemePuRd, schemeRdPu, schemeYlGnBu, schemeYlGn, schemeYlOrBr, schemeYlOrRd, interpolateBrBG, interpolatePRGn, interpolatePiYG, interpolatePuOr, interpolateRdBu, interpolateRdGy, interpolateRdYlBu, interpolateRdYlGn, interpolateSpectral, interpolateBlues, interpolateGreens, interpolateGreys, interpolateOranges, interpolatePurples, interpolateReds, interpolateViridis, interpolateInferno, interpolateMagma, interpolatePlasma, interpolateWarm, interpolateCool, interpolateCubehelixDefault, interpolateBuGn, interpolateBuPu, interpolateGnBu, interpolateOrRd, interpolatePuBuGn, interpolatePuBu, interpolatePuRd, interpolateRdPu, interpolateYlGnBu, interpolateYlGn, interpolateYlOrBr, interpolateYlOrRd, interpolateRainbow, interpolateSinebow } from 'd3-scale-chromatic'; | ||
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 get from 'lodash.get'; | ||
import isPlainObject from 'lodash.isplainobject'; | ||
import { rgb } from 'd3-color'; | ||
import { spring } from 'react-motion'; | ||
import { scaleOrdinal } from 'd3-scale'; | ||
import { rgb } from 'd3-color'; | ||
import PropTypes from 'prop-types'; | ||
import { spring } from 'react-motion'; | ||
@@ -66,5 +66,3 @@ function _defineProperty(obj, key, value) { | ||
var categoricalColorSchemeIds = Object.keys(categoricalColorSchemes); | ||
var isCategoricalColorScheme = function isCategoricalColorScheme(scheme) { | ||
return categoricalColorSchemeIds.includes(scheme); | ||
}; | ||
var divergingColorSchemes = { | ||
@@ -82,5 +80,14 @@ brown_blueGreen: schemeBrBG, | ||
var divergingColorSchemeIds = Object.keys(divergingColorSchemes); | ||
var isDivergingColorScheme = function isDivergingColorScheme(scheme) { | ||
return divergingColorSchemeIds.includes(scheme); | ||
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 = { | ||
@@ -107,17 +114,3 @@ blues: schemeBlues, | ||
var sequentialColorSchemeIds = Object.keys(sequentialColorSchemes); | ||
var isSequentialColorScheme = function isSequentialColorScheme(scheme) { | ||
return sequentialColorSchemeIds.includes(scheme); | ||
}; | ||
var colorSchemes = _objectSpread2(_objectSpread2(_objectSpread2({}, categoricalColorSchemes), divergingColorSchemes), sequentialColorSchemes); | ||
var colorSchemeIds = Object.keys(colorSchemes); | ||
var colorInterpolators = { | ||
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 sequentialColorInterpolators = { | ||
blues: interpolateBlues, | ||
@@ -129,2 +122,3 @@ greens: interpolateGreens, | ||
reds: interpolateReds, | ||
turbo: interpolateTurbo, | ||
viridis: interpolateViridis, | ||
@@ -134,2 +128,3 @@ inferno: interpolateInferno, | ||
plasma: interpolatePlasma, | ||
cividis: interpolateCividis, | ||
warm: interpolateWarm, | ||
@@ -149,71 +144,25 @@ cool: interpolateCool, | ||
yellow_orange_brown: interpolateYlOrBr, | ||
yellow_orange_red: interpolateYlOrRd, | ||
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); | ||
var getOrdinalColorScale = function getOrdinalColorScale(instruction, identity) { | ||
if (typeof instruction === 'function') return instruction; | ||
var getIdentity = typeof identity === 'function' ? identity : function (d) { | ||
return get(d, identity); | ||
}; | ||
if (Array.isArray(instruction)) { | ||
var scale = scaleOrdinal(instruction); | ||
var generator = function generator(d) { | ||
return scale(getIdentity(d)); | ||
}; | ||
generator.scale = scale; | ||
return generator; | ||
} | ||
if (isPlainObject(instruction)) { | ||
if (instruction.datum !== undefined) { | ||
return function (datum) { | ||
return get(datum, instruction.datum); | ||
}; | ||
} | ||
if (instruction.scheme !== undefined) { | ||
if (isCategoricalColorScheme(instruction.scheme)) { | ||
var _scale = scaleOrdinal(colorSchemes[instruction.scheme]); | ||
var _generator = function _generator(d) { | ||
return _scale(getIdentity(d)); | ||
}; | ||
_generator.scale = _scale; | ||
return _generator; | ||
} | ||
if (isDivergingColorScheme(instruction.scheme)) { | ||
if (instruction.size !== undefined && (instruction.size < 3 || instruction.size > 11)) { | ||
throw new Error("Invalid size '".concat(instruction.size, "' for diverging color scheme '").concat(instruction.scheme, "', must be between 3~11")); | ||
} | ||
var _scale2 = scaleOrdinal(colorSchemes[instruction.scheme][instruction.size || 11]); | ||
var _generator2 = function _generator2(d) { | ||
return _scale2(getIdentity(d)); | ||
}; | ||
_generator2.scale = _scale2; | ||
return _generator2; | ||
} | ||
if (isSequentialColorScheme(instruction.scheme)) { | ||
if (instruction.size !== undefined && (instruction.size < 3 || instruction.size > 9)) { | ||
throw new Error("Invalid size '".concat(instruction.size, "' for sequential color scheme '").concat(instruction.scheme, "', must be between 3~9")); | ||
} | ||
var _scale3 = scaleOrdinal(colorSchemes[instruction.scheme][instruction.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 instruction; | ||
}; | ||
}; | ||
var useOrdinalColorScale = function useOrdinalColorScale(instruction, identity) { | ||
return useMemo(function () { | ||
return getOrdinalColorScale(instruction, identity); | ||
}, [instruction, identity]); | ||
}; | ||
function _arrayWithHoles(arr) { | ||
@@ -323,15 +272,29 @@ if (Array.isArray(arr)) return arr; | ||
var getInheritedColorGenerator = function getInheritedColorGenerator(inheritedColor, theme) { | ||
if (typeof inheritedColor === 'function') return function (node) { | ||
return inheritedColor(node); | ||
}; | ||
if (isPlainObject(inheritedColor)) { | ||
if (inheritedColor.theme !== undefined) { | ||
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 function (datum) { | ||
return config(datum); | ||
}; | ||
} | ||
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, inheritedColor.theme); | ||
var themeColor = _get(theme, config.theme); | ||
if (themeColor === undefined) { | ||
throw new Error("Color from theme is undefined at path: '".concat(inheritedColor.theme, "'")); | ||
throw new Error("Color from theme is undefined at path: '".concat(config.theme, "'")); | ||
} | ||
return function () { | ||
@@ -341,16 +304,22 @@ return themeColor; | ||
} | ||
if (inheritedColor.from !== undefined) { | ||
var getColor = function getColor(datum) { | ||
return get(datum, inheritedColor.from); | ||
if (isInheritedColorConfigFromContext(config)) { | ||
var getColor = function getColor(d) { | ||
return _get(d, config.from); | ||
}; | ||
if (Array.isArray(inheritedColor.modifiers)) { | ||
if (Array.isArray(config.modifiers)) { | ||
var modifiers = []; | ||
var _iterator = _createForOfIteratorHelper(inheritedColor.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') { | ||
@@ -373,2 +342,3 @@ modifiers.push(function (color) { | ||
}; | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
@@ -382,2 +352,3 @@ _loop(); | ||
} | ||
if (modifiers.length === 0) return getColor; | ||
@@ -390,32 +361,22 @@ return function (datum) { | ||
} | ||
return getColor; | ||
} | ||
throw new Error("Invalid color spec, you should either specify 'theme' or 'from' when using a config object"); | ||
} | ||
return function () { | ||
return inheritedColor; | ||
return config; | ||
}; | ||
}; | ||
var useInheritedColor = function useInheritedColor(parentColor, theme) { | ||
var useInheritedColor = function useInheritedColor(config, theme) { | ||
return useMemo(function () { | ||
return getInheritedColorGenerator(parentColor, theme); | ||
}, [parentColor, theme]); | ||
return getInheritedColorGenerator(config, theme); | ||
}, [config, theme]); | ||
}; | ||
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) | ||
})]); | ||
var interpolateColor = function interpolateColor(color, springConfig) { | ||
var colorComponents = rgb(color); | ||
if (!springConfig) { | ||
@@ -428,5 +389,7 @@ return { | ||
} | ||
var configWithPrecision = _objectSpread2(_objectSpread2({}, springConfig), {}, { | ||
precision: 1 | ||
}); | ||
return { | ||
@@ -445,3 +408,108 @@ colorR: spring(colorComponents.r, configWithPrecision), | ||
export { categoricalColorSchemeIds, categoricalColorSchemes, colorInterpolatorIds, colorInterpolators, colorPropertyAccessorPropType, colorSchemeIds, colorSchemes, divergingColorSchemeIds, divergingColorSchemes, getInheritedColorGenerator, getInterpolatedColor, getOrdinalColorScale, inheritedColorPropType, interpolateColor, isCategoricalColorScheme, isDivergingColorScheme, isSequentialColorScheme, ordinalColorsPropType, sequentialColorSchemeIds, sequentialColorSchemes, useInheritedColor, useOrdinalColorScale }; | ||
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 }; | ||
//# sourceMappingURL=nivo-colors.es.js.map |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-scale-chromatic'), require('react'), require('lodash.get'), require('lodash.isplainobject'), require('d3-scale'), require('d3-color'), require('prop-types'), require('react-motion')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'd3-scale-chromatic', 'react', 'lodash.get', 'lodash.isplainobject', 'd3-scale', 'd3-color', 'prop-types', 'react-motion'], factory) : | ||
(global = global || self, factory(global.nivo = global.nivo || {}, global.d3, global.React, global.lodash.get, global.lodash.isplainobject, global.d3, global.d3, global.PropTypes, global.ReactMotion)); | ||
}(this, (function (exports, d3ScaleChromatic, react, get, isPlainObject, d3Scale, d3Color, PropTypes, reactMotion) { 'use strict'; | ||
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'; | ||
get = get && Object.prototype.hasOwnProperty.call(get, 'default') ? get['default'] : get; | ||
isPlainObject = isPlainObject && Object.prototype.hasOwnProperty.call(isPlainObject, 'default') ? isPlainObject['default'] : isPlainObject; | ||
_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; | ||
@@ -67,5 +67,3 @@ | ||
var categoricalColorSchemeIds = Object.keys(categoricalColorSchemes); | ||
var isCategoricalColorScheme = function isCategoricalColorScheme(scheme) { | ||
return categoricalColorSchemeIds.includes(scheme); | ||
}; | ||
var divergingColorSchemes = { | ||
@@ -83,5 +81,14 @@ brown_blueGreen: d3ScaleChromatic.schemeBrBG, | ||
var divergingColorSchemeIds = Object.keys(divergingColorSchemes); | ||
var isDivergingColorScheme = function isDivergingColorScheme(scheme) { | ||
return divergingColorSchemeIds.includes(scheme); | ||
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 = { | ||
@@ -108,17 +115,3 @@ blues: d3ScaleChromatic.schemeBlues, | ||
var sequentialColorSchemeIds = Object.keys(sequentialColorSchemes); | ||
var isSequentialColorScheme = function isSequentialColorScheme(scheme) { | ||
return sequentialColorSchemeIds.includes(scheme); | ||
}; | ||
var colorSchemes = _objectSpread2(_objectSpread2(_objectSpread2({}, categoricalColorSchemes), divergingColorSchemes), sequentialColorSchemes); | ||
var colorSchemeIds = Object.keys(colorSchemes); | ||
var colorInterpolators = { | ||
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 sequentialColorInterpolators = { | ||
blues: d3ScaleChromatic.interpolateBlues, | ||
@@ -130,2 +123,3 @@ greens: d3ScaleChromatic.interpolateGreens, | ||
reds: d3ScaleChromatic.interpolateReds, | ||
turbo: d3ScaleChromatic.interpolateTurbo, | ||
viridis: d3ScaleChromatic.interpolateViridis, | ||
@@ -135,2 +129,3 @@ inferno: d3ScaleChromatic.interpolateInferno, | ||
plasma: d3ScaleChromatic.interpolatePlasma, | ||
cividis: d3ScaleChromatic.interpolateCividis, | ||
warm: d3ScaleChromatic.interpolateWarm, | ||
@@ -150,71 +145,25 @@ cool: d3ScaleChromatic.interpolateCool, | ||
yellow_orange_brown: d3ScaleChromatic.interpolateYlOrBr, | ||
yellow_orange_red: d3ScaleChromatic.interpolateYlOrRd, | ||
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); | ||
var getOrdinalColorScale = function getOrdinalColorScale(instruction, identity) { | ||
if (typeof instruction === 'function') return instruction; | ||
var getIdentity = typeof identity === 'function' ? identity : function (d) { | ||
return get(d, identity); | ||
}; | ||
if (Array.isArray(instruction)) { | ||
var scale = d3Scale.scaleOrdinal(instruction); | ||
var generator = function generator(d) { | ||
return scale(getIdentity(d)); | ||
}; | ||
generator.scale = scale; | ||
return generator; | ||
} | ||
if (isPlainObject(instruction)) { | ||
if (instruction.datum !== undefined) { | ||
return function (datum) { | ||
return get(datum, instruction.datum); | ||
}; | ||
} | ||
if (instruction.scheme !== undefined) { | ||
if (isCategoricalColorScheme(instruction.scheme)) { | ||
var _scale = d3Scale.scaleOrdinal(colorSchemes[instruction.scheme]); | ||
var _generator = function _generator(d) { | ||
return _scale(getIdentity(d)); | ||
}; | ||
_generator.scale = _scale; | ||
return _generator; | ||
} | ||
if (isDivergingColorScheme(instruction.scheme)) { | ||
if (instruction.size !== undefined && (instruction.size < 3 || instruction.size > 11)) { | ||
throw new Error("Invalid size '".concat(instruction.size, "' for diverging color scheme '").concat(instruction.scheme, "', must be between 3~11")); | ||
} | ||
var _scale2 = d3Scale.scaleOrdinal(colorSchemes[instruction.scheme][instruction.size || 11]); | ||
var _generator2 = function _generator2(d) { | ||
return _scale2(getIdentity(d)); | ||
}; | ||
_generator2.scale = _scale2; | ||
return _generator2; | ||
} | ||
if (isSequentialColorScheme(instruction.scheme)) { | ||
if (instruction.size !== undefined && (instruction.size < 3 || instruction.size > 9)) { | ||
throw new Error("Invalid size '".concat(instruction.size, "' for sequential color scheme '").concat(instruction.scheme, "', must be between 3~9")); | ||
} | ||
var _scale3 = d3Scale.scaleOrdinal(colorSchemes[instruction.scheme][instruction.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 instruction; | ||
}; | ||
}; | ||
var useOrdinalColorScale = function useOrdinalColorScale(instruction, identity) { | ||
return react.useMemo(function () { | ||
return getOrdinalColorScale(instruction, identity); | ||
}, [instruction, identity]); | ||
}; | ||
function _arrayWithHoles(arr) { | ||
@@ -324,15 +273,29 @@ if (Array.isArray(arr)) return arr; | ||
var getInheritedColorGenerator = function getInheritedColorGenerator(inheritedColor, theme) { | ||
if (typeof inheritedColor === 'function') return function (node) { | ||
return inheritedColor(node); | ||
}; | ||
if (isPlainObject(inheritedColor)) { | ||
if (inheritedColor.theme !== undefined) { | ||
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 function (datum) { | ||
return config(datum); | ||
}; | ||
} | ||
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, inheritedColor.theme); | ||
var themeColor = _get(theme, config.theme); | ||
if (themeColor === undefined) { | ||
throw new Error("Color from theme is undefined at path: '".concat(inheritedColor.theme, "'")); | ||
throw new Error("Color from theme is undefined at path: '".concat(config.theme, "'")); | ||
} | ||
return function () { | ||
@@ -342,16 +305,22 @@ return themeColor; | ||
} | ||
if (inheritedColor.from !== undefined) { | ||
var getColor = function getColor(datum) { | ||
return get(datum, inheritedColor.from); | ||
if (isInheritedColorConfigFromContext(config)) { | ||
var getColor = function getColor(d) { | ||
return _get(d, config.from); | ||
}; | ||
if (Array.isArray(inheritedColor.modifiers)) { | ||
if (Array.isArray(config.modifiers)) { | ||
var modifiers = []; | ||
var _iterator = _createForOfIteratorHelper(inheritedColor.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') { | ||
@@ -374,2 +343,3 @@ modifiers.push(function (color) { | ||
}; | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
@@ -383,2 +353,3 @@ _loop(); | ||
} | ||
if (modifiers.length === 0) return getColor; | ||
@@ -391,32 +362,22 @@ return function (datum) { | ||
} | ||
return getColor; | ||
} | ||
throw new Error("Invalid color spec, you should either specify 'theme' or 'from' when using a config object"); | ||
} | ||
return function () { | ||
return inheritedColor; | ||
return config; | ||
}; | ||
}; | ||
var useInheritedColor = function useInheritedColor(parentColor, theme) { | ||
var useInheritedColor = function useInheritedColor(config, theme) { | ||
return react.useMemo(function () { | ||
return getInheritedColorGenerator(parentColor, theme); | ||
}, [parentColor, theme]); | ||
return getInheritedColorGenerator(config, theme); | ||
}, [config, theme]); | ||
}; | ||
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) | ||
})]); | ||
var interpolateColor = function interpolateColor(color, springConfig) { | ||
var colorComponents = d3Color.rgb(color); | ||
if (!springConfig) { | ||
@@ -429,5 +390,7 @@ return { | ||
} | ||
var configWithPrecision = _objectSpread2(_objectSpread2({}, springConfig), {}, { | ||
precision: 1 | ||
}); | ||
return { | ||
@@ -446,2 +409,107 @@ colorR: reactMotion.spring(colorComponents.r, configWithPrecision), | ||
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; | ||
@@ -454,2 +522,4 @@ exports.categoricalColorSchemes = categoricalColorSchemes; | ||
exports.colorSchemes = colorSchemes; | ||
exports.cyclicalColorInterpolators = cyclicalColorInterpolators; | ||
exports.divergingColorInterpolators = divergingColorInterpolators; | ||
exports.divergingColorSchemeIds = divergingColorSchemeIds; | ||
@@ -466,2 +536,3 @@ exports.divergingColorSchemes = divergingColorSchemes; | ||
exports.ordinalColorsPropType = ordinalColorsPropType; | ||
exports.sequentialColorInterpolators = sequentialColorInterpolators; | ||
exports.sequentialColorSchemeIds = sequentialColorSchemeIds; | ||
@@ -468,0 +539,0 @@ exports.sequentialColorSchemes = sequentialColorSchemes; |
{ | ||
"name": "@nivo/colors", | ||
"version": "0.64.0", | ||
"version": "0.65.0", | ||
"license": "MIT", | ||
@@ -9,21 +9,33 @@ "author": { | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/plouc/nivo.git", | ||
"directory": "packages/colors" | ||
}, | ||
"main": "./dist/nivo-colors.cjs.js", | ||
"module": "./dist/nivo-colors.es.js", | ||
"typings": "./dist/types/index.d.ts", | ||
"files": [ | ||
"README.md", | ||
"LICENSE.md", | ||
"index.d.ts", | ||
"dist/" | ||
], | ||
"dependencies": { | ||
"d3-color": "^1.2.3", | ||
"d3-color": "^2.0.0", | ||
"d3-scale": "^3.0.0", | ||
"d3-scale-chromatic": "^1.3.3", | ||
"lodash.get": "^4.4.2", | ||
"lodash.isplainobject": "^4.0.6", | ||
"d3-scale-chromatic": "^2.0.0", | ||
"lodash": "^4.17.11", | ||
"react-motion": "^0.5.2" | ||
}, | ||
"devDependencies": { | ||
"@nivo/core": "0.65.0", | ||
"@types/d3-color": "^2.0.0", | ||
"@types/d3-scale-chromatic": "^2.0.0", | ||
"@types/lodash": "^4.14.149", | ||
"@types/react-motion": "^0.0.29" | ||
}, | ||
"peerDependencies": { | ||
"@nivo/core": "0.64.0", | ||
"prop-types": ">= 15.5.10 < 16.0.0", | ||
"react": ">= 16.8.4 < 17.0.0" | ||
"react": ">= 16.8.4 <= 17.0.0" | ||
}, | ||
@@ -33,3 +45,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "fd731453ed88a31074a8199365e837ad61c90e4c" | ||
"gitHead": "f1e4749d1697347101a3e22edf578e86ebd87ec2" | ||
} |
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
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
473717
34
1801
0
5
+ Addedlodash@^4.17.11
+ Added@babel/runtime@7.26.0(transitive)
+ Added@nivo/core@0.62.00.64.0(transitive)
+ Added@nivo/tooltip@0.62.00.63.0(transitive)
+ Addedasap@2.0.6(transitive)
+ Addedchange-emitter@0.1.6(transitive)
+ Addedcore-js@1.2.7(transitive)
+ Addedd3-color@2.0.0(transitive)
+ Addedd3-format@1.4.5(transitive)
+ Addedd3-hierarchy@1.1.9(transitive)
+ Addedd3-path@1.0.9(transitive)
+ Addedd3-scale-chromatic@2.0.0(transitive)
+ Addedd3-shape@1.3.7(transitive)
+ Addedd3-time@1.1.0(transitive)
+ Addedd3-time-format@2.3.0(transitive)
+ Addedencoding@0.1.13(transitive)
+ Addedfbjs@0.8.18(transitive)
+ Addedget-node-dimensions@1.2.2(transitive)
+ Addedhoist-non-react-statics@2.5.5(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedisomorphic-fetch@2.2.1(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addednode-fetch@1.7.3(transitive)
+ Addedpromise@7.3.1(transitive)
+ Addedreact@17.0.018.3.1(transitive)
+ Addedreact-dom@18.3.1(transitive)
+ Addedreact-lifecycles-compat@3.0.4(transitive)
+ Addedreact-measure@2.5.2(transitive)
+ Addedreact-spring@8.0.27(transitive)
+ Addedrecompose@0.30.0(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
+ Addedresize-observer-polyfill@1.5.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedscheduler@0.23.2(transitive)
+ Addedsetimmediate@1.0.5(transitive)
+ Addedsymbol-observable@1.2.0(transitive)
+ Addedua-parser-js@0.7.39(transitive)
+ Addedwhatwg-fetch@3.6.20(transitive)
- Removedlodash.get@^4.4.2
- Removedlodash.isplainobject@^4.0.6
- Removedd3-format@2.0.0(transitive)
- Removedd3-time-format@3.0.0(transitive)
- Removedlodash.get@4.4.2(transitive)
- Removedlodash.isplainobject@4.0.6(transitive)
Updatedd3-color@^2.0.0
Updatedd3-scale-chromatic@^2.0.0