@evergis/react 4.0.93 → 4.0.94

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6,7 +6,6 @@ var React = require('react');
6
6
  var styled = require('styled-components');
7
7
  var charts = require('@evergis/charts');
8
8
  var api = require('@evergis/api');
9
- var Gradient = require('javascript-color-gradient');
10
9
  var color$1 = require('@evergis/color');
11
10
  var dateFns = require('date-fns');
12
11
  var lodash = require('lodash');
@@ -3564,13 +3563,26 @@ const GRADIENT_COLORS = [
3564
3563
  "#A1E062",
3565
3564
  "#51D8A5",
3566
3565
  ];
3567
- const getGradientColors = (colorsCount) => {
3568
- return new Gradient()
3569
- .setColorGradient(...GRADIENT_COLORS)
3570
- .setMidpoint(colorsCount === undefined || colorsCount < GRADIENT_COLORS.length ? GRADIENT_COLORS.length : colorsCount + 10)
3571
- .getColors()
3572
- .slice(0, colorsCount === undefined || colorsCount < GRADIENT_COLORS.length ? GRADIENT_COLORS.length : colorsCount);
3566
+ const HEX_RRGGBB_LENGTH = 7;
3567
+ /**
3568
+ * Растягивает палитру на нужное количество цветов: опорные цвета равномерно
3569
+ * раскладываются по шкале, недостающие интерполируются между ними.
3570
+ * @param colors - опорные цвета палитры в hex
3571
+ * @param count - требуемое количество цветов
3572
+ * @returns массив ровно из count цветов
3573
+ */
3574
+ const stretchPalette = (colors, count) => {
3575
+ if (!colors?.length || count <= 0)
3576
+ return [];
3577
+ if (colors.length === 1)
3578
+ return Array.from({ length: count }, () => colors[0]);
3579
+ const scale = new color$1.ColorScale(colors.map((color, index) => [index / (colors.length - 1), color]));
3580
+ return Array.from({ length: count }, (_, index) => {
3581
+ const color = scale.getColor(count === 1 ? 0 : index / (count - 1));
3582
+ return color ? new color$1.Color(color).toString("hex").slice(0, HEX_RRGGBB_LENGTH) : colors[colors.length - 1];
3583
+ });
3573
3584
  };
3585
+ const getGradientColors = (colorsCount) => stretchPalette(GRADIENT_COLORS, colorsCount === undefined || colorsCount < GRADIENT_COLORS.length ? GRADIENT_COLORS.length : colorsCount);
3574
3586
  /**
3575
3587
  * Converts HSL hue value to RGB
3576
3588
  * @param p - lower bound
@@ -10270,7 +10282,7 @@ const getDashboardHeader = (templateName) => {
10270
10282
  };
10271
10283
 
10272
10284
  const getDataFromAttributes = (t, config, attributes) => {
10273
- const colors = config?.options?.colors || FEATURE_CARD_DEFAULT_COLORS;
10285
+ const colors = stretchPalette(config?.options?.colors || FEATURE_CARD_DEFAULT_COLORS, config?.children?.length || 0);
10274
10286
  const data = config?.children?.map(({ attributeName }, index) => {
10275
10287
  const attribute = attributes?.find(item => item.attributeName === attributeName);
10276
10288
  return {
@@ -10322,12 +10334,8 @@ const getDataFromRelatedFeatures = ({ t, config, filters, relatedConfig, dataSou
10322
10334
  if (isOtherSliced) {
10323
10335
  data = data.slice(0, config?.options?.otherItems);
10324
10336
  }
10325
- const gradientColors = colors?.length === 1 ? [colors[0], colors[0]] : colors;
10326
- const gradientArray = relatedConfig.chartAxis && colors?.length < data.length
10327
- ? new Gradient()
10328
- .setColorGradient(...gradientColors)
10329
- .setMidpoint(data.length)
10330
- .getColors()
10337
+ const gradientArray = relatedConfig.chartAxis
10338
+ ? stretchPalette(colors, data.length)
10331
10339
  : colors;
10332
10340
  const filter = getConfigFilter(relatedConfig?.filterName, filters);
10333
10341
  const result = data.reduce((acc, feature, index) => {
@@ -14700,6 +14708,7 @@ exports.removeDataSource = removeDataSource;
14700
14708
  exports.rgbToHex = rgbToHex;
14701
14709
  exports.roundTotalSum = roundTotalSum;
14702
14710
  exports.sliceShownOtherItems = sliceShownOtherItems;
14711
+ exports.stretchPalette = stretchPalette;
14703
14712
  exports.timeOptions = timeOptions;
14704
14713
  exports.toRenderableValue = toRenderableValue;
14705
14714
  exports.tooltipNameFromAttributes = tooltipNameFromAttributes;