@evergis/react 3.1.16 → 3.1.17

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
@@ -2,7 +2,7 @@ import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
2
2
  import { IconButton, Flex, transition, Chip, Icon, Description, FlexSpan, IconToggle, Popup, Menu, DraggableTree, shadows, Divider, LegendToggler, Tooltip as Tooltip$1, DropdownField, MultiSelectContainer, IconButtonButton, FlatButton, DraggableTreeContainer, LinearProgress, H2, ThemeProvider, defaultTheme, Preview, Blank, Popover, darkTheme, NumberRangeSlider, useAsyncAutocomplete, AutoComplete, Dropdown, Checkbox, CircularProgress, RangeNumberInput, dateFormat } from '@evergis/uilib-gl';
3
3
  import { createContext, memo, useRef, useState, useEffect, useCallback, useContext, useMemo, Fragment } from 'react';
4
4
  import styled, { createGlobalStyle, css, useTheme } from 'styled-components';
5
- import { lineChartClassNames, barChartClassNames, BarChart as BarChart$1, LineChart, PieChart } from '@evergis/charts';
5
+ import { lineChartClassNames, BarChart as BarChart$1, barChartClassNames, LineChart, PieChart } from '@evergis/charts';
6
6
  import { AttributeType, GeometryType } from '@evergis/api';
7
7
  import Gradient from 'javascript-color-gradient';
8
8
  import { Color as Color$1 } from '@evergis/color';
@@ -110,7 +110,7 @@ const Tooltip = styled.div `
110
110
  height: 0;
111
111
  }
112
112
  `;
113
- const LineChartTooltipStyles = createGlobalStyle `
113
+ const LineChartStyles = createGlobalStyle `
114
114
  .dashboardLineChartTooltip.${lineChartClassNames.lineChartMouseLabel} {
115
115
  .${lineChartClassNames.lineChartLabelFlex} {
116
116
  justify-content: center;
@@ -185,11 +185,19 @@ const LineChartTooltipStyles = createGlobalStyle `
185
185
  fill: ${({ theme: { palette } }) => palette.textDisabled};
186
186
  }
187
187
  `;
188
- const BarChartStyles = createGlobalStyle `
189
- .dashboardBarChart {
190
- .domain,
188
+ const StyledBarChart = styled(BarChart$1) `
189
+ .domain,
190
+ line {
191
+ display: none;
192
+ }
193
+
194
+ .tick {
195
+ text {
196
+ fill: ${({ theme: { palette } }) => palette.textDisabled};
197
+ }
198
+
191
199
  line {
192
- display: none;
200
+ visibility: hidden;
193
201
  }
194
202
  }
195
203
  `;
@@ -3987,41 +3995,7 @@ function wrap() {
3987
3995
  textLength = self.node().getComputedTextLength();
3988
3996
  }
3989
3997
  }
3990
- // https://jr.everpoint.ru/browse/PUB-5221
3991
- /* function wrap2(text, width, content) {
3992
- text.each(() => {
3993
- const textElem = d3.select(this);
3994
- const words = content.split(/\s+/).reverse();
3995
- let word;
3996
- let line = [];
3997
- let lineNumber = 0;
3998
- const lineHeight = 1.1; // ems
3999
- const x = 0; // textElem.attr("x");
4000
- const y = 0; // textElem.attr("y");
4001
- const dy = 0; // parseFloat(text.attr("dy")),
4002
- // eslint-disable-next-line newline-per-chained-call
4003
- let tspan = textElem.text(null).append("tspan").attr("x", x).attr("y", y).attr("dy", `${dy}em`);
4004
-
4005
- // eslint-disable-next-line no-cond-assign
4006
- while ((word = words.pop())) {
4007
- line.push(word);
4008
- tspan.text(line.join(" "));
4009
- if (tspan.node().getComputedTextLength() > width) {
4010
- line.pop();
4011
- tspan.text(line.join(" "));
4012
- line = [word];
4013
- tspan = textElem
4014
- .append("tspan")
4015
- .attr("x", x)
4016
- .attr("y", y)
4017
- // eslint-disable-next-line no-plusplus
4018
- .attr("dy", `${++lineNumber * lineHeight + dy}em`)
4019
- .text(word);
4020
- }
4021
- }
4022
- });
4023
- }*/
4024
- const useChartChange = ({ dataSources, chartId, width, height, relatedAttributes, defaultColor, fontColor, }) => {
3998
+ const useChartChange = ({ dataSources, chartId, width, height, relatedAttributes, defaultColor, fontColor, showMarkers, }) => {
4025
3999
  const { t } = useGlobalContext();
4026
4000
  const { layerInfos } = useWidgetContext();
4027
4001
  const strokeColors = relatedAttributes.filter(({ chartAxis }) => chartAxis === "y").map(({ axisColor }) => axisColor);
@@ -4058,11 +4032,17 @@ const useChartChange = ({ dataSources, chartId, width, height, relatedAttributes
4058
4032
  if (index === nodes.length - 1) {
4059
4033
  nodes[index].style.textAnchor = "end";
4060
4034
  }
4061
- if (index && index < nodes.length - 1) {
4062
- nodes[index].remove();
4035
+ if (showMarkers) {
4036
+ if (index % (showMarkers || 1) !== 0) {
4037
+ nodes[index].remove();
4038
+ }
4039
+ }
4040
+ else {
4041
+ if (index && index < nodes.length - 1) {
4042
+ nodes[index].remove();
4043
+ }
4063
4044
  }
4064
4045
  });
4065
- // svg.selectAll(`.${lineChartClassNames.lineChartXScaleGlobal} .tick text`).call(wrap2, 5, "!!!");
4066
4046
  svg.selectAll(`.${lineChartClassNames.lineChartXScaleGlobal} .tick text`).attr("y", 16);
4067
4047
  svg
4068
4048
  .selectAll(`.${lineChartClassNames.lineChartYScaleGlobal} .tick text`)
@@ -4108,7 +4088,7 @@ const useChartChange = ({ dataSources, chartId, width, height, relatedAttributes
4108
4088
  onChange();
4109
4089
  });
4110
4090
  svg.append("defs").html(() => defs.join(""));
4111
- }, [fontColor, dataSources, layerInfos, relatedAttributes, chartId, strokeColors, defaultColor, width, onChange]);
4091
+ }, [fontColor, dataSources, layerInfos, relatedAttributes, chartId, strokeColors, defaultColor, width, onChange, showMarkers]);
4112
4092
  return [customize, onChange];
4113
4093
  };
4114
4094
 
@@ -5397,7 +5377,11 @@ const getChartFilterName = (relatedDataSources) => {
5397
5377
  return axes?.[0]?.filterName;
5398
5378
  };
5399
5379
 
5400
- const getChartMarkers = (items, markers) => {
5380
+ const getChartMarkers = (items, markers, dataSources) => {
5381
+ if (typeof markers === "string") {
5382
+ const dataSource = getDataSource(markers, dataSources);
5383
+ return dataSource?.features?.map(({ attributes }) => attributes) || [];
5384
+ }
5401
5385
  return (markers?.map(marker => ({
5402
5386
  ...marker,
5403
5387
  value: items?.findIndex(({ name }) => name.toString() === marker.value?.toString()),
@@ -8149,7 +8133,7 @@ const useBarChartFilter = ({ type, filter, elementConfig }) => {
8149
8133
  bars.attr("rx", radius).attr("ry", radius);
8150
8134
  }, [radius]);
8151
8135
  const tooltipY = useMemo(() => (barHeight ? height - barHeight - DEFAULT_BAR_CHART_MARGINS.bottom : undefined), [barHeight, height]);
8152
- const markers = useMemo(() => getChartMarkers(filterItems, configMarkers), [configMarkers, filterItems]);
8136
+ const markers = useMemo(() => getChartMarkers(filterItems, configMarkers, dataSources), [configMarkers, dataSources, filterItems]);
8153
8137
  const hasDefinedColors = useMemo(() => configColors?.length || colorAttribute, [configColors, colorAttribute]);
8154
8138
  const marshalledMap = useCallback(items => {
8155
8139
  if (hasDefinedColors)
@@ -8481,7 +8465,7 @@ const getRenderElement = ({ t, config, elementConfig, attributes = [], layerInfo
8481
8465
  return formatElementValue({ t, value, elementConfig: element, attributes, wrap });
8482
8466
  };
8483
8467
 
8484
- const getResourceUrl = (url) => url ? (url.startsWith("http") ? url : `/sp/resources/${url}/download`) : "";
8468
+ const getResourceUrl = (url) => url ? (url.startsWith("http") ? url : `/sp/resources/file/${url}`) : "";
8485
8469
 
8486
8470
  const getSlideshowImages = ({ element, attribute, }) => {
8487
8471
  const { defaultValue, options } = element;
@@ -9127,10 +9111,11 @@ const StackBar = ({ data, filterName, type, alias, options, renderElement, rende
9127
9111
  const Chart = memo(({ config, element, elementConfig, type, renderElement }) => {
9128
9112
  const theme = useTheme();
9129
9113
  const { palette } = theme;
9114
+ const primaryColor = palette.primary;
9130
9115
  const { t } = useGlobalContext();
9131
- const { expandedContainers, layerInfos, attributes } = useWidgetContext(type);
9116
+ const { expandedContainers, layerInfos, attributes, dataSources } = useWidgetContext(type);
9132
9117
  const { id, options, children } = element || {};
9133
- const { column, markers: configMarkers, showTotal, expandable, expanded, chartType, relatedDataSources, defaultColor } = options || {};
9118
+ const { column, markers: configMarkers, showLabels, showMarkers, showTotal, totalWord: configTotalWord, totalAttribute, expandable, expanded, chartType, relatedDataSources, defaultColor } = options || {};
9134
9119
  const isLineChart = chartType === "line";
9135
9120
  const isPieChart = chartType === "pie";
9136
9121
  const isStackBar = chartType === "stack";
@@ -9142,7 +9127,6 @@ const Chart = memo(({ config, element, elementConfig, type, renderElement }) =>
9142
9127
  const angle = options?.angle || DEFAULT_CHART_ANGLE;
9143
9128
  const barWidth = options?.barWidth || DEFAULT_BAR_WIDTH;
9144
9129
  const cornerRadius = options?.cornerRadius || 0;
9145
- const primaryColor = theme.palette.primary;
9146
9130
  const relatedAttributes = useMemo(() => relatedDataSources || [], [relatedDataSources]);
9147
9131
  const axes = useMemo(() => relatedAttributes.filter(({ chartAxis }) => chartAxis === "y"), [relatedAttributes]);
9148
9132
  const filterName = getChartFilterName(relatedDataSources);
@@ -9162,16 +9146,17 @@ const Chart = memo(({ config, element, elementConfig, type, renderElement }) =>
9162
9146
  height,
9163
9147
  fontColor,
9164
9148
  relatedAttributes,
9165
- defaultColor: primaryColor
9149
+ defaultColor: primaryColor,
9150
+ showMarkers,
9166
9151
  });
9167
9152
  const { formatFilterColor, onFilter } = useFeatureFilters(type, filterName, data?.[0]?.items);
9168
9153
  const formattedAttributes = useMemo(() => getFormattedAttributes(t, (data[0]?.items || []), attributes, element), [attributes, data, element, t]);
9169
9154
  const totalSum = useMemo(() => isRelated
9170
9155
  ? getTotalFromRelatedFeatures((data[0]?.items || []))
9171
9156
  : getTotalFromAttributes(children, formattedAttributes), [data, children, formattedAttributes, isRelated]);
9172
- const totalWord = useMemo(() => options?.totalAttribute
9173
- ? attributes?.find(({ name }) => name === options.totalAttribute)?.value
9174
- : options?.totalWord, [attributes, options.totalAttribute, options?.totalWord]);
9157
+ const totalWord = useMemo(() => totalAttribute
9158
+ ? attributes?.find(({ name }) => name === totalAttribute)?.value
9159
+ : configTotalWord, [attributes, totalAttribute, configTotalWord]);
9175
9160
  const renderPieChartTooltip = useCallback(item => isRelated
9176
9161
  ? pieChartTooltipFromRelatedFeatures(t, item, relatedAttributes, data[0]?.layerInfo)
9177
9162
  : pieChartTooltipFromAttributes(t, item, formattedAttributes), [data, formattedAttributes, isRelated, relatedAttributes]);
@@ -9190,11 +9175,17 @@ const Chart = memo(({ config, element, elementConfig, type, renderElement }) =>
9190
9175
  return (jsxs(ChartTooltipRow, { children: [jsx(ChartLegendColor$1, { "$color": stroke }), jsx(ChartLegendValue, { children: attribute ? formatAttributeValue({ t, type: attribute.type, value, stringFormat: attribute.stringFormat }) : value })] }, index));
9191
9176
  })] }));
9192
9177
  }, [labels, layerInfos]);
9193
- const markers = useMemo(() => getChartMarkers(data[0]?.items, configMarkers), [data, configMarkers]);
9178
+ const markers = useMemo(() => getChartMarkers(data[0]?.items, configMarkers, dataSources), [data, dataSources, configMarkers]);
9194
9179
  const formatTooltipName = useCallback((name) => (isRelated ? name : tooltipNameFromAttributes(name, formattedAttributes)), [formattedAttributes, isRelated]);
9195
9180
  const formatTooltipValue = useCallback((value, name) => isRelated
9196
9181
  ? tooltipValueFromRelatedFeatures(t, value, relatedAttributes, data[0]?.layerInfo)
9197
9182
  : tooltipValueFromAttributes(t, value, name, formattedAttributes), [data, formattedAttributes, isRelated, relatedAttributes]);
9183
+ const customXAxisBottom = useCallback((xAxisBottom, data) => {
9184
+ xAxisBottom.tickFormat((index) => (showMarkers
9185
+ ? index % (showMarkers || 1) === 0
9186
+ : index === 0 || index === data.length - 1)
9187
+ ? data[index]?.groupName || "" : "");
9188
+ }, [showMarkers]);
9198
9189
  const renderChart = useMemo(() => {
9199
9190
  if (!element)
9200
9191
  return null;
@@ -9212,7 +9203,7 @@ const Chart = memo(({ config, element, elementConfig, type, renderElement }) =>
9212
9203
  .flat()
9213
9204
  .map(({ values }) => values)
9214
9205
  .flat();
9215
- return (jsxs(AnyChartWrapper, { height: height, children: [jsx(LineChartTooltipStyles, {}), jsx(LineChart, { data: lineChartData, labels: labels, width: +width, height: height, xAxisPadding: 15, yAxisPadding: 0, min: Math.min(...chartValues), customYAxisSelection: yAxis => {
9206
+ return (jsxs(AnyChartWrapper, { height: height, children: [jsx(LineChartStyles, {}), jsx(LineChart, { data: lineChartData, labels: labels, width: +width, height: height, xAxisPadding: 15, yAxisPadding: 0, min: Math.min(...chartValues), customYAxisSelection: yAxis => {
9216
9207
  if (isHidedY) {
9217
9208
  yAxis.remove();
9218
9209
  }
@@ -9234,18 +9225,20 @@ const Chart = memo(({ config, element, elementConfig, type, renderElement }) =>
9234
9225
  color: formatFilterColor(item.name, item.color, defaultColor)
9235
9226
  })) || []), width: +width, height: +width, padAngle: angle, outerRadius: radius, cornerRadius: cornerRadius, renderTooltip: renderPieChartTooltip, withTooltip: true, onClick: filterName ? item => onFilter(item.name) : undefined, children: showTotal && jsx(PieChartCenter, { children: totalWord || roundTotalSum(+totalSum) }) }) }));
9236
9227
  }
9237
- const markersMargin = options?.showMarkers ? 10 : 0;
9228
+ const barChartData = getDataFromFilterItems(data[0]?.items);
9229
+ const markersMargin = showMarkers ? 10 : 0;
9238
9230
  const margin = {
9239
9231
  top: markersMargin,
9240
9232
  right: markersMargin,
9241
9233
  bottom: markers?.length ? 20 : markersMargin,
9242
9234
  left: markersMargin
9243
9235
  };
9244
- return (jsx(BarChartWrapper, { height: height + margin.bottom, children: jsxs(BarChartContainer, { children: [jsx(BarChartStyles, {}), jsx(BarChart$1, { data: getDataFromFilterItems(data[0]?.items), colors: getColorsFromFilterItems(data[0]?.items, defaultColor, formatFilterColor), minValue: getMinValueFromFilterItems(data[0]?.items), markers: markers, width: +width, height: height, barWidth: barWidth, barPadding: padding, className: "dashboardBarChart", customXAxis: axis => axis.remove(), customYAxis: axis => !options?.showMarkers && axis.remove(), customBars: ({ bars }) => {
9245
- bars.attr("rx", radius);
9246
- bars.attr("ry", radius);
9247
- }, margin: margin, xAxisPadding: 0, yAxisPadding: 0, formatTooltipValue: formatTooltipValue, formatTooltipName: formatTooltipName, hideTooltipGroupName: true, dynamicTooltipEnable: true, isBarTooltip: true, onBarClick: filterName ? item => onFilter(item.name) : undefined })] }) }));
9236
+ return (jsx(BarChartWrapper, { height: height + margin.bottom, children: jsx(BarChartContainer, { children: jsx(StyledBarChart, { data: barChartData, colors: getColorsFromFilterItems(data[0]?.items, defaultColor, formatFilterColor), minValue: getMinValueFromFilterItems(data[0]?.items), markers: markers, width: +width, height: height, barWidth: barWidth, barPadding: padding, className: "dashboardBarChart", customXAxisBottom: xAxisBottom => customXAxisBottom(xAxisBottom, barChartData), customYAxis: axis => !showLabels && axis.remove(), customBars: ({ bars }) => {
9237
+ bars.attr("rx", radius);
9238
+ bars.attr("ry", radius);
9239
+ }, margin: margin, xAxisPadding: 0, yAxisPadding: 0, formatTooltipValue: formatTooltipValue, formatTooltipName: formatTooltipName, hideTooltipGroupName: true, dynamicTooltipEnable: true, isBarTooltip: true, onBarClick: filterName ? item => onFilter(item.name) : undefined }) }) }));
9248
9240
  }, [
9241
+ customXAxisBottom,
9249
9242
  element,
9250
9243
  isLineChart,
9251
9244
  isStackBar,
@@ -9257,6 +9250,8 @@ const Chart = memo(({ config, element, elementConfig, type, renderElement }) =>
9257
9250
  formatFilterColor,
9258
9251
  width,
9259
9252
  barWidth,
9253
+ showLabels,
9254
+ showMarkers,
9260
9255
  padding,
9261
9256
  formatTooltipValue,
9262
9257
  formatTooltipName,