@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.
@@ -1,9 +1,8 @@
1
1
  import { FC } from 'react';
2
2
  import { QueryLayerServiceInfoDc } from '@evergis/api';
3
3
  import { ClientFeatureAttribute, ContainerProps } from '../../types';
4
- interface ElementSvgProps extends ContainerProps {
4
+ export interface ElementSvgProps extends ContainerProps {
5
5
  layerInfo?: QueryLayerServiceInfoDc;
6
6
  attributes?: ClientFeatureAttribute[];
7
7
  }
8
8
  export declare const ElementSvg: FC<ElementSvgProps>;
9
- export {};
@@ -2,7 +2,7 @@ export declare const elementComponents: {
2
2
  readonly control: import('react').FC<import('..').ContainerProps>;
3
3
  readonly image: import('react').FC<import('..').ContainerProps>;
4
4
  readonly slideshow: import('react').FC<import('./ElementSlideshow/types').DashboardSlideshowProps>;
5
- readonly svg: import('react').FC<import('..').ContainerProps>;
5
+ readonly svg: import('react').FC<import('./ElementSvg').ElementSvgProps>;
6
6
  readonly icon: import('react').FC<import('..').ContainerProps>;
7
7
  readonly tooltip: import('react').FC<import('..').ContainerProps>;
8
8
  readonly tags: import('react').FC<import('..').ContainerProps>;
@@ -33,7 +33,7 @@ export interface ConfigRelatedResource {
33
33
  fileName?: string;
34
34
  methodName?: string;
35
35
  }
36
- export interface ConfigControl extends Pick<ConfigOptions, "relatedDataSource" | "minValue" | "maxValue" | "step" | "label" | "placeholder" | "width"> {
36
+ export interface ConfigControl extends Pick<ConfigOptions, "relatedDataSource" | "minValue" | "maxValue" | "step" | "label" | "placeholder" | "width" | "variants"> {
37
37
  type: "dropdown" | "checkbox" | "chips" | "string";
38
38
  attributeName?: string;
39
39
  targetAttributeName?: string;
package/dist/index.js CHANGED
@@ -4204,7 +4204,9 @@ function getLinePoints(numPoints, svgLine) {
4204
4204
  else {
4205
4205
  interval = lineLength / (numPoints - 1);
4206
4206
  }
4207
- return range(numPoints).filter(d => d * interval).map(d => {
4207
+ return range(numPoints)
4208
+ .filter(d => d * interval)
4209
+ .map(d => {
4208
4210
  const value = d * interval;
4209
4211
  const { x, y } = svgLine.getPointAtLength(value);
4210
4212
  return [x, y];
@@ -4225,7 +4227,9 @@ function wrap() {
4225
4227
  const useChartChange = ({ dataSources, chartId, width, height, relatedAttributes, defaultColor, fontColor, markers, showMarkers, }) => {
4226
4228
  const { t } = useGlobalContext();
4227
4229
  const { layerInfos } = useWidgetContext();
4228
- const strokeColors = relatedAttributes.filter(({ chartAxis }) => chartAxis === "y").map(({ axisColor }) => axisColor);
4230
+ const strokeColors = relatedAttributes
4231
+ .filter(({ chartAxis }) => chartAxis === "y")
4232
+ .map(({ axisColor }) => axisColor);
4229
4233
  const ref = React.useRef({
4230
4234
  path: null,
4231
4235
  area: null,
@@ -4246,13 +4250,15 @@ const useChartChange = ({ dataSources, chartId, width, height, relatedAttributes
4246
4250
  const customize = React.useCallback(({ svg }) => {
4247
4251
  svg.style("overflow", "visible");
4248
4252
  svg
4249
- .selectAll(`.${charts.lineChartClassNames.lineChartXScaleGlobal} line,
4250
- .${charts.lineChartClassNames.lineChartYScaleGlobal} line,
4253
+ .selectAll(`.${charts.lineChartClassNames.lineChartXScaleGlobal} line,
4254
+ .${charts.lineChartClassNames.lineChartYScaleGlobal} line,
4251
4255
  .domain`)
4252
4256
  .each((_, index, nodes) => {
4253
4257
  nodes[index].remove();
4254
4258
  });
4255
- svg.selectAll(`.${charts.lineChartClassNames.lineChartXScaleGlobal} .tick`).each((_, index, nodes) => {
4259
+ svg
4260
+ .selectAll(`.${charts.lineChartClassNames.lineChartXScaleGlobal} .tick`)
4261
+ .each((_, index, nodes) => {
4256
4262
  if (!index) {
4257
4263
  nodes[index].style.textAnchor = "start";
4258
4264
  }
@@ -4273,16 +4279,28 @@ const useChartChange = ({ dataSources, chartId, width, height, relatedAttributes
4273
4279
  }
4274
4280
  }
4275
4281
  });
4276
- svg.selectAll(`.${charts.lineChartClassNames.lineChartXScaleGlobal} .tick text`).attr("y", 16);
4282
+ svg
4283
+ .selectAll(`.${charts.lineChartClassNames.lineChartXScaleGlobal} .tick text`)
4284
+ .attr("y", 16);
4277
4285
  svg
4278
4286
  .selectAll(`.${charts.lineChartClassNames.lineChartYScaleGlobal} .tick text`)
4279
4287
  .text(item => {
4280
4288
  if (!item)
4281
4289
  return 0;
4282
4290
  const dataSource = dataSources?.find(({ name }) => name === relatedAttributes[0].dataSourceName);
4283
- const layerInfo = dataSource ? layerInfos.find(({ name }) => name === dataSource.layerName) : null;
4291
+ const layerInfo = dataSource
4292
+ ? layerInfos.find(({ name }) => name === dataSource.layerName)
4293
+ : null;
4284
4294
  const attribute = layerInfo?.layerDefinition.attributes[relatedAttributes[0].attributeName];
4285
- return attribute ? formatAttributeValue({ t, type: attribute.type, value: item, stringFormat: attribute.stringFormat, noUnits: true }) : item;
4295
+ return attribute
4296
+ ? formatAttributeValue({
4297
+ t,
4298
+ type: attribute.type,
4299
+ value: item,
4300
+ stringFormat: attribute.stringFormat,
4301
+ noUnits: true,
4302
+ })
4303
+ : item;
4286
4304
  })
4287
4305
  .each(wrap);
4288
4306
  svg.selectAll(".tick text").attr("style", `color: ${fontColor}`);
@@ -4304,11 +4322,11 @@ const useChartChange = ({ dataSources, chartId, width, height, relatedAttributes
4304
4322
  .attr("fill", `url(#${gradientId})`)
4305
4323
  .attr("stroke-width", "0")
4306
4324
  .attr("fill-opacity", FILL_OPACITY);
4307
- defs.push(`
4308
- <linearGradient id="${gradientId}" x1="0" y1="0" x2="0" y2="1">
4309
- <stop offset="0" stop-color="${color}" stop-opacity="1" />
4310
- <stop offset="1" stop-color="${color}" stop-opacity="0" />
4311
- </linearGradient>
4325
+ defs.push(`
4326
+ <linearGradient id="${gradientId}" x1="0" y1="0" x2="0" y2="1">
4327
+ <stop offset="0" stop-color="${color}" stop-opacity="1" />
4328
+ <stop offset="1" stop-color="${color}" stop-opacity="0" />
4329
+ </linearGradient>
4312
4330
  `);
4313
4331
  ref.current = {
4314
4332
  path: newPath,
@@ -4318,7 +4336,19 @@ const useChartChange = ({ dataSources, chartId, width, height, relatedAttributes
4318
4336
  onChange();
4319
4337
  });
4320
4338
  svg.append("defs").html(() => defs.join(""));
4321
- }, [fontColor, dataSources, layerInfos, relatedAttributes, chartId, strokeColors, defaultColor, width, onChange, showMarkers, markers]);
4339
+ }, [
4340
+ fontColor,
4341
+ dataSources,
4342
+ layerInfos,
4343
+ relatedAttributes,
4344
+ chartId,
4345
+ strokeColors,
4346
+ defaultColor,
4347
+ width,
4348
+ onChange,
4349
+ showMarkers,
4350
+ markers,
4351
+ ]);
4322
4352
  return [customize, onChange];
4323
4353
  };
4324
4354
 
@@ -7162,6 +7192,7 @@ const RoundedBackgroundContainerWrapper = styled(uilibGl.Flex) `
7162
7192
 
7163
7193
  * {
7164
7194
  color: ${$color};
7195
+ fill: ${$color};
7165
7196
  }
7166
7197
  `};
7167
7198
 
@@ -8465,11 +8496,19 @@ const ElementChart = React.memo(({ type, elementConfig, renderElement }) => {
8465
8496
  const ElementChips = React.memo(({ type, elementConfig }) => {
8466
8497
  const { attributes } = useWidgetContext(type);
8467
8498
  const { attributeName, options, style } = elementConfig || {};
8468
- const { separator, bgColor, fontColor, fontSize, colorAttribute } = options || {};
8499
+ const { separator, bgColor, fontColor, fontSize, colorAttribute, variants, } = options || {};
8469
8500
  const valueAttr = getAttributeByName(attributeName, attributes);
8470
8501
  const colorAttr = getAttributeByName(colorAttribute, attributes);
8471
- const tags = valueAttr?.value?.split(separator || ",");
8472
- return (jsxRuntime.jsx(DashboardChipsContainer, { style: style, children: tags?.map(tag => (jsxRuntime.jsx(DashboardChip$1, { text: tag, "$bgColor": colorAttr?.value || bgColor, "$fontColor": fontColor, "$fontSize": fontSize, "$isDefault": !colorAttr?.value }, tag))) }));
8502
+ const tags = React.useMemo(() => {
8503
+ if (variants?.length) {
8504
+ return variants.map(({ text, color }) => ({
8505
+ text,
8506
+ color,
8507
+ }));
8508
+ }
8509
+ return (valueAttr?.value?.split(separator || ",") ?? []).map(text => ({ text, color: undefined }));
8510
+ }, [variants, valueAttr?.value, separator]);
8511
+ return (jsxRuntime.jsx(DashboardChipsContainer, { style: style, children: tags.map(tag => (jsxRuntime.jsx(DashboardChip$1, { text: tag.text, "$bgColor": tag.color || colorAttr?.value || bgColor, "$fontColor": fontColor, "$fontSize": fontSize, "$isDefault": !tag.color && !colorAttr?.value }, tag.text))) }));
8473
8512
  });
8474
8513
 
8475
8514
  const ElementControl = ({ elementConfig }) => {
@@ -8483,6 +8522,9 @@ const ElementControl = ({ elementConfig }) => {
8483
8522
  const attribute = React.useMemo(() => attributes?.find(({ name }) => name === control?.targetAttributeName), [attributes, control?.targetAttributeName]);
8484
8523
  const dataSource = React.useMemo(() => getDataSource(relatedDataSource, dataSources), [relatedDataSource, dataSources]);
8485
8524
  const items = React.useMemo(() => {
8525
+ if (control?.variants) {
8526
+ return control.variants;
8527
+ }
8486
8528
  if (!dataSource?.features?.length || !attributeName) {
8487
8529
  return [];
8488
8530
  }
@@ -8490,14 +8532,23 @@ const ElementControl = ({ elementConfig }) => {
8490
8532
  value: item.properties?.[attributeName] || "",
8491
8533
  text: item.properties?.[control?.attributeName || attributeName] || "",
8492
8534
  }));
8493
- }, [control?.attributeName, dataSource?.features, attributeName]);
8535
+ }, [
8536
+ control?.variants,
8537
+ control?.attributeName,
8538
+ dataSource?.features,
8539
+ attributeName,
8540
+ ]);
8494
8541
  const isDisabled = React.useMemo(() => {
8495
8542
  const attr = layerInfo?.configuration?.attributesConfiguration?.attributes?.find(item => item.attributeName === control?.targetAttributeName);
8496
8543
  return !attr?.isEditable;
8497
8544
  }, [
8498
8545
  control?.targetAttributeName,
8499
- layerInfo?.configuration?.attributesConfiguration?.attributes,
8546
+ layerInfo?.configuration
8547
+ ?.attributesConfiguration?.attributes,
8500
8548
  ]);
8549
+ const currentValue = controls?.[control?.targetAttributeName] ??
8550
+ attribute?.value ??
8551
+ defaultValue;
8501
8552
  const handleChange = React.useCallback(([option]) => {
8502
8553
  if (control?.targetAttributeName && changeControls) {
8503
8554
  changeControls({
@@ -8505,9 +8556,7 @@ const ElementControl = ({ elementConfig }) => {
8505
8556
  });
8506
8557
  }
8507
8558
  }, [changeControls, control?.targetAttributeName]);
8508
- return (jsxRuntime.jsx(uilibGl.Dropdown, { zIndex: 1000, width: `${width ?? DEFAULT_DROPDOWN_WIDTH}px`, label: label, options: items, value: controls?.[control?.targetAttributeName] ??
8509
- attribute?.value ??
8510
- defaultValue, placeholder: placeholder, disabled: isDisabled, onChange: handleChange }));
8559
+ return (jsxRuntime.jsx(uilibGl.Dropdown, { zIndex: 1000, width: `${width ?? DEFAULT_DROPDOWN_WIDTH}px`, label: label, options: items, value: currentValue, placeholder: placeholder, disabled: isDisabled, onChange: handleChange }));
8511
8560
  };
8512
8561
 
8513
8562
  const StyledIconFontSizeMixin = styled.css `
@@ -8577,7 +8626,7 @@ const ElementLegend = React.memo(({ type, element, elementConfig }) => {
8577
8626
  return axes.map(({ alias, axisColor }) => {
8578
8627
  return {
8579
8628
  name: alias,
8580
- color: axisColor
8629
+ color: axisColor,
8581
8630
  };
8582
8631
  });
8583
8632
  }
@@ -8589,8 +8638,16 @@ const ElementLegend = React.memo(({ type, element, elementConfig }) => {
8589
8638
  const attribute = getAttributeByName(item.name, attributes);
8590
8639
  return { ...item, name: attribute?.alias || item.name };
8591
8640
  });
8592
- }, [attributes, axes, data, options.chartType, relatedDataSources, dataSources]);
8593
- return !chartElement?.options?.expanded || expandedContainers?.[chartElement.id] ? (jsxRuntime.jsx(ChartLegend, { data: legendData, loading: loading, chartElement: chartElement, twoColumns: twoColumns, fontSize: fontSize, type: type })) : null;
8641
+ }, [
8642
+ attributes,
8643
+ axes,
8644
+ data,
8645
+ options.chartType,
8646
+ relatedDataSources,
8647
+ dataSources,
8648
+ ]);
8649
+ return !chartElement?.options?.expanded ||
8650
+ expandedContainers?.[chartElement.id] ? (jsxRuntime.jsx(ChartLegend, { data: legendData, loading: loading, chartElement: chartElement, twoColumns: twoColumns, fontSize: fontSize, type: type })) : null;
8594
8651
  });
8595
8652
 
8596
8653
  const ExternalLink = styled(uilibGl.IconButton).attrs(() => ({
@@ -10605,7 +10662,9 @@ const useChartData = ({ element, type }) => {
10605
10662
  const dataSource = configDataSources.find(({ name }) => name === dataSourceName);
10606
10663
  const layerInfo = layerInfos?.find(item => item?.name === dataSource?.layerName);
10607
10664
  const featureDataSource = getDataSource(dataSourceName, dataSources);
10608
- const hasLayerInfo = !!layerInfo || !!featureDataSource?.attributeDefinition || !!featureDataSource?.features?.length;
10665
+ const hasLayerInfo = !!layerInfo ||
10666
+ !!featureDataSource?.attributeDefinition ||
10667
+ !!featureDataSource?.features?.length;
10609
10668
  return {
10610
10669
  items: hasLayerInfo
10611
10670
  ? getDataFromRelatedFeatures({
@@ -10615,7 +10674,11 @@ const useChartData = ({ element, type }) => {
10615
10674
  relatedConfig: relatedAxis,
10616
10675
  dataSource: featureDataSource,
10617
10676
  layerInfo: layerInfo ||
10618
- { layerDefinition: { attributes: featureDataSource.attributeDefinition } },
10677
+ {
10678
+ layerDefinition: {
10679
+ attributes: featureDataSource.attributeDefinition,
10680
+ },
10681
+ },
10619
10682
  })
10620
10683
  : null,
10621
10684
  color: axisColor,
@@ -10625,7 +10688,8 @@ const useChartData = ({ element, type }) => {
10625
10688
  layerInfo,
10626
10689
  };
10627
10690
  })
10628
- .filter(({ items }) => items === null || (items?.length && !items.every(({ value }) => value === null)));
10691
+ .filter(({ items }) => items === null ||
10692
+ (items?.length && !items.every(({ value }) => value === null)));
10629
10693
  }
10630
10694
  return [
10631
10695
  {