@evergis/react 4.0.13 → 4.0.20

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/react.esm.js CHANGED
@@ -4202,7 +4202,9 @@ function getLinePoints(numPoints, svgLine) {
4202
4202
  else {
4203
4203
  interval = lineLength / (numPoints - 1);
4204
4204
  }
4205
- return range(numPoints).filter(d => d * interval).map(d => {
4205
+ return range(numPoints)
4206
+ .filter(d => d * interval)
4207
+ .map(d => {
4206
4208
  const value = d * interval;
4207
4209
  const { x, y } = svgLine.getPointAtLength(value);
4208
4210
  return [x, y];
@@ -4223,7 +4225,9 @@ function wrap() {
4223
4225
  const useChartChange = ({ dataSources, chartId, width, height, relatedAttributes, defaultColor, fontColor, markers, showMarkers, }) => {
4224
4226
  const { t } = useGlobalContext();
4225
4227
  const { layerInfos } = useWidgetContext();
4226
- const strokeColors = relatedAttributes.filter(({ chartAxis }) => chartAxis === "y").map(({ axisColor }) => axisColor);
4228
+ const strokeColors = relatedAttributes
4229
+ .filter(({ chartAxis }) => chartAxis === "y")
4230
+ .map(({ axisColor }) => axisColor);
4227
4231
  const ref = useRef({
4228
4232
  path: null,
4229
4233
  area: null,
@@ -4244,13 +4248,15 @@ const useChartChange = ({ dataSources, chartId, width, height, relatedAttributes
4244
4248
  const customize = useCallback(({ svg }) => {
4245
4249
  svg.style("overflow", "visible");
4246
4250
  svg
4247
- .selectAll(`.${lineChartClassNames.lineChartXScaleGlobal} line,
4248
- .${lineChartClassNames.lineChartYScaleGlobal} line,
4251
+ .selectAll(`.${lineChartClassNames.lineChartXScaleGlobal} line,
4252
+ .${lineChartClassNames.lineChartYScaleGlobal} line,
4249
4253
  .domain`)
4250
4254
  .each((_, index, nodes) => {
4251
4255
  nodes[index].remove();
4252
4256
  });
4253
- svg.selectAll(`.${lineChartClassNames.lineChartXScaleGlobal} .tick`).each((_, index, nodes) => {
4257
+ svg
4258
+ .selectAll(`.${lineChartClassNames.lineChartXScaleGlobal} .tick`)
4259
+ .each((_, index, nodes) => {
4254
4260
  if (!index) {
4255
4261
  nodes[index].style.textAnchor = "start";
4256
4262
  }
@@ -4271,16 +4277,28 @@ const useChartChange = ({ dataSources, chartId, width, height, relatedAttributes
4271
4277
  }
4272
4278
  }
4273
4279
  });
4274
- svg.selectAll(`.${lineChartClassNames.lineChartXScaleGlobal} .tick text`).attr("y", 16);
4280
+ svg
4281
+ .selectAll(`.${lineChartClassNames.lineChartXScaleGlobal} .tick text`)
4282
+ .attr("y", 16);
4275
4283
  svg
4276
4284
  .selectAll(`.${lineChartClassNames.lineChartYScaleGlobal} .tick text`)
4277
4285
  .text(item => {
4278
4286
  if (!item)
4279
4287
  return 0;
4280
4288
  const dataSource = dataSources?.find(({ name }) => name === relatedAttributes[0].dataSourceName);
4281
- const layerInfo = dataSource ? layerInfos.find(({ name }) => name === dataSource.layerName) : null;
4289
+ const layerInfo = dataSource
4290
+ ? layerInfos.find(({ name }) => name === dataSource.layerName)
4291
+ : null;
4282
4292
  const attribute = layerInfo?.layerDefinition.attributes[relatedAttributes[0].attributeName];
4283
- return attribute ? formatAttributeValue({ t, type: attribute.type, value: item, stringFormat: attribute.stringFormat, noUnits: true }) : item;
4293
+ return attribute
4294
+ ? formatAttributeValue({
4295
+ t,
4296
+ type: attribute.type,
4297
+ value: item,
4298
+ stringFormat: attribute.stringFormat,
4299
+ noUnits: true,
4300
+ })
4301
+ : item;
4284
4302
  })
4285
4303
  .each(wrap);
4286
4304
  svg.selectAll(".tick text").attr("style", `color: ${fontColor}`);
@@ -4302,11 +4320,11 @@ const useChartChange = ({ dataSources, chartId, width, height, relatedAttributes
4302
4320
  .attr("fill", `url(#${gradientId})`)
4303
4321
  .attr("stroke-width", "0")
4304
4322
  .attr("fill-opacity", FILL_OPACITY);
4305
- defs.push(`
4306
- <linearGradient id="${gradientId}" x1="0" y1="0" x2="0" y2="1">
4307
- <stop offset="0" stop-color="${color}" stop-opacity="1" />
4308
- <stop offset="1" stop-color="${color}" stop-opacity="0" />
4309
- </linearGradient>
4323
+ defs.push(`
4324
+ <linearGradient id="${gradientId}" x1="0" y1="0" x2="0" y2="1">
4325
+ <stop offset="0" stop-color="${color}" stop-opacity="1" />
4326
+ <stop offset="1" stop-color="${color}" stop-opacity="0" />
4327
+ </linearGradient>
4310
4328
  `);
4311
4329
  ref.current = {
4312
4330
  path: newPath,
@@ -4316,7 +4334,19 @@ const useChartChange = ({ dataSources, chartId, width, height, relatedAttributes
4316
4334
  onChange();
4317
4335
  });
4318
4336
  svg.append("defs").html(() => defs.join(""));
4319
- }, [fontColor, dataSources, layerInfos, relatedAttributes, chartId, strokeColors, defaultColor, width, onChange, showMarkers, markers]);
4337
+ }, [
4338
+ fontColor,
4339
+ dataSources,
4340
+ layerInfos,
4341
+ relatedAttributes,
4342
+ chartId,
4343
+ strokeColors,
4344
+ defaultColor,
4345
+ width,
4346
+ onChange,
4347
+ showMarkers,
4348
+ markers,
4349
+ ]);
4320
4350
  return [customize, onChange];
4321
4351
  };
4322
4352
 
@@ -7160,6 +7190,7 @@ const RoundedBackgroundContainerWrapper = styled(Flex) `
7160
7190
 
7161
7191
  * {
7162
7192
  color: ${$color};
7193
+ fill: ${$color};
7163
7194
  }
7164
7195
  `};
7165
7196
 
@@ -8463,11 +8494,19 @@ const ElementChart = memo(({ type, elementConfig, renderElement }) => {
8463
8494
  const ElementChips = memo(({ type, elementConfig }) => {
8464
8495
  const { attributes } = useWidgetContext(type);
8465
8496
  const { attributeName, options, style } = elementConfig || {};
8466
- const { separator, bgColor, fontColor, fontSize, colorAttribute } = options || {};
8497
+ const { separator, bgColor, fontColor, fontSize, colorAttribute, variants, } = options || {};
8467
8498
  const valueAttr = getAttributeByName(attributeName, attributes);
8468
8499
  const colorAttr = getAttributeByName(colorAttribute, attributes);
8469
- const tags = valueAttr?.value?.split(separator || ",");
8470
- return (jsx(DashboardChipsContainer, { style: style, children: tags?.map(tag => (jsx(DashboardChip$1, { text: tag, "$bgColor": colorAttr?.value || bgColor, "$fontColor": fontColor, "$fontSize": fontSize, "$isDefault": !colorAttr?.value }, tag))) }));
8500
+ const tags = useMemo(() => {
8501
+ if (variants?.length) {
8502
+ return variants.map(({ text, color }) => ({
8503
+ text,
8504
+ color,
8505
+ }));
8506
+ }
8507
+ return (valueAttr?.value?.split(separator || ",") ?? []).map(text => ({ text, color: undefined }));
8508
+ }, [variants, valueAttr?.value, separator]);
8509
+ return (jsx(DashboardChipsContainer, { style: style, children: tags.map(tag => (jsx(DashboardChip$1, { text: tag.text, "$bgColor": tag.color || colorAttr?.value || bgColor, "$fontColor": fontColor, "$fontSize": fontSize, "$isDefault": !tag.color && !colorAttr?.value }, tag.text))) }));
8471
8510
  });
8472
8511
 
8473
8512
  const ElementControl = ({ elementConfig }) => {
@@ -8481,6 +8520,9 @@ const ElementControl = ({ elementConfig }) => {
8481
8520
  const attribute = useMemo(() => attributes?.find(({ name }) => name === control?.targetAttributeName), [attributes, control?.targetAttributeName]);
8482
8521
  const dataSource = useMemo(() => getDataSource(relatedDataSource, dataSources), [relatedDataSource, dataSources]);
8483
8522
  const items = useMemo(() => {
8523
+ if (control?.variants) {
8524
+ return control.variants;
8525
+ }
8484
8526
  if (!dataSource?.features?.length || !attributeName) {
8485
8527
  return [];
8486
8528
  }
@@ -8488,14 +8530,23 @@ const ElementControl = ({ elementConfig }) => {
8488
8530
  value: item.properties?.[attributeName] || "",
8489
8531
  text: item.properties?.[control?.attributeName || attributeName] || "",
8490
8532
  }));
8491
- }, [control?.attributeName, dataSource?.features, attributeName]);
8533
+ }, [
8534
+ control?.variants,
8535
+ control?.attributeName,
8536
+ dataSource?.features,
8537
+ attributeName,
8538
+ ]);
8492
8539
  const isDisabled = useMemo(() => {
8493
8540
  const attr = layerInfo?.configuration?.attributesConfiguration?.attributes?.find(item => item.attributeName === control?.targetAttributeName);
8494
8541
  return !attr?.isEditable;
8495
8542
  }, [
8496
8543
  control?.targetAttributeName,
8497
- layerInfo?.configuration?.attributesConfiguration?.attributes,
8544
+ layerInfo?.configuration
8545
+ ?.attributesConfiguration?.attributes,
8498
8546
  ]);
8547
+ const currentValue = controls?.[control?.targetAttributeName] ??
8548
+ attribute?.value ??
8549
+ defaultValue;
8499
8550
  const handleChange = useCallback(([option]) => {
8500
8551
  if (control?.targetAttributeName && changeControls) {
8501
8552
  changeControls({
@@ -8503,9 +8554,7 @@ const ElementControl = ({ elementConfig }) => {
8503
8554
  });
8504
8555
  }
8505
8556
  }, [changeControls, control?.targetAttributeName]);
8506
- return (jsx(Dropdown, { zIndex: 1000, width: `${width ?? DEFAULT_DROPDOWN_WIDTH}px`, label: label, options: items, value: controls?.[control?.targetAttributeName] ??
8507
- attribute?.value ??
8508
- defaultValue, placeholder: placeholder, disabled: isDisabled, onChange: handleChange }));
8557
+ return (jsx(Dropdown, { zIndex: 1000, width: `${width ?? DEFAULT_DROPDOWN_WIDTH}px`, label: label, options: items, value: currentValue, placeholder: placeholder, disabled: isDisabled, onChange: handleChange }));
8509
8558
  };
8510
8559
 
8511
8560
  const StyledIconFontSizeMixin = css `
@@ -8575,7 +8624,7 @@ const ElementLegend = memo(({ type, element, elementConfig }) => {
8575
8624
  return axes.map(({ alias, axisColor }) => {
8576
8625
  return {
8577
8626
  name: alias,
8578
- color: axisColor
8627
+ color: axisColor,
8579
8628
  };
8580
8629
  });
8581
8630
  }
@@ -8587,8 +8636,16 @@ const ElementLegend = memo(({ type, element, elementConfig }) => {
8587
8636
  const attribute = getAttributeByName(item.name, attributes);
8588
8637
  return { ...item, name: attribute?.alias || item.name };
8589
8638
  });
8590
- }, [attributes, axes, data, options.chartType, relatedDataSources, dataSources]);
8591
- return !chartElement?.options?.expanded || expandedContainers?.[chartElement.id] ? (jsx(ChartLegend, { data: legendData, loading: loading, chartElement: chartElement, twoColumns: twoColumns, fontSize: fontSize, type: type })) : null;
8639
+ }, [
8640
+ attributes,
8641
+ axes,
8642
+ data,
8643
+ options.chartType,
8644
+ relatedDataSources,
8645
+ dataSources,
8646
+ ]);
8647
+ return !chartElement?.options?.expanded ||
8648
+ expandedContainers?.[chartElement.id] ? (jsx(ChartLegend, { data: legendData, loading: loading, chartElement: chartElement, twoColumns: twoColumns, fontSize: fontSize, type: type })) : null;
8592
8649
  });
8593
8650
 
8594
8651
  const ExternalLink = styled(IconButton).attrs(() => ({
@@ -10603,7 +10660,9 @@ const useChartData = ({ element, type }) => {
10603
10660
  const dataSource = configDataSources.find(({ name }) => name === dataSourceName);
10604
10661
  const layerInfo = layerInfos?.find(item => item?.name === dataSource?.layerName);
10605
10662
  const featureDataSource = getDataSource(dataSourceName, dataSources);
10606
- const hasLayerInfo = !!layerInfo || !!featureDataSource?.attributeDefinition || !!featureDataSource?.features?.length;
10663
+ const hasLayerInfo = !!layerInfo ||
10664
+ !!featureDataSource?.attributeDefinition ||
10665
+ !!featureDataSource?.features?.length;
10607
10666
  return {
10608
10667
  items: hasLayerInfo
10609
10668
  ? getDataFromRelatedFeatures({
@@ -10613,7 +10672,11 @@ const useChartData = ({ element, type }) => {
10613
10672
  relatedConfig: relatedAxis,
10614
10673
  dataSource: featureDataSource,
10615
10674
  layerInfo: layerInfo ||
10616
- { layerDefinition: { attributes: featureDataSource.attributeDefinition } },
10675
+ {
10676
+ layerDefinition: {
10677
+ attributes: featureDataSource.attributeDefinition,
10678
+ },
10679
+ },
10617
10680
  })
10618
10681
  : null,
10619
10682
  color: axisColor,
@@ -10623,7 +10686,8 @@ const useChartData = ({ element, type }) => {
10623
10686
  layerInfo,
10624
10687
  };
10625
10688
  })
10626
- .filter(({ items }) => items === null || (items?.length && !items.every(({ value }) => value === null)));
10689
+ .filter(({ items }) => items === null ||
10690
+ (items?.length && !items.every(({ value }) => value === null)));
10627
10691
  }
10628
10692
  return [
10629
10693
  {