@evergis/react 3.1.16 → 3.1.18

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.
@@ -18,7 +18,7 @@ export declare const ChartWrapperContainer: import('styled-components').StyledCo
18
18
  export declare const Tooltip: import('styled-components').StyledComponent<"div", any, {
19
19
  transform?: CSSProperties["transform"];
20
20
  }, never>;
21
- export declare const LineChartTooltipStyles: import('styled-components').GlobalStyleComponent<{
21
+ export declare const LineChartStyles: import('styled-components').GlobalStyleComponent<{
22
22
  [x: string]: any;
23
23
  [x: number]: any;
24
24
  [x: symbol]: any;
@@ -28,4 +28,4 @@ export declare const LineChartTooltipStyles: import('styled-components').GlobalS
28
28
  as?: string | import('react').ComponentType<any>;
29
29
  forwardedAs?: string | import('react').ComponentType<any>;
30
30
  }, import('styled-components').DefaultTheme>;
31
- export declare const BarChartStyles: import('styled-components').GlobalStyleComponent<{}, import('styled-components').DefaultTheme>;
31
+ export declare const StyledBarChart: import('styled-components').StyledComponent<import('react').FC<import('@evergis/charts').BarChartProps>, any, {}, never>;
@@ -1,6 +1,6 @@
1
1
  import { LineChartProps } from '@evergis/charts';
2
2
  import { ConfigDataSource, ConfigRelatedDataSource } from '../types';
3
- export declare const useChartChange: ({ dataSources, chartId, width, height, relatedAttributes, defaultColor, fontColor, }: {
3
+ export declare const useChartChange: ({ dataSources, chartId, width, height, relatedAttributes, defaultColor, fontColor, showMarkers, }: {
4
4
  dataSources: ConfigDataSource[];
5
5
  chartId: string;
6
6
  width: string | number;
@@ -8,4 +8,5 @@ export declare const useChartChange: ({ dataSources, chartId, width, height, rel
8
8
  relatedAttributes: ConfigRelatedDataSource[];
9
9
  defaultColor: string;
10
10
  fontColor: string;
11
+ showMarkers: number;
11
12
  }) => [LineChartProps["customize"], (range: [number, number]) => void];
@@ -43,7 +43,6 @@ export interface ConfigOptions {
43
43
  srid?: string;
44
44
  title?: string;
45
45
  label?: string;
46
- showMarkers?: boolean;
47
46
  withPadding?: boolean;
48
47
  withDivider?: boolean;
49
48
  tagView?: boolean;
@@ -76,7 +75,9 @@ export interface ConfigOptions {
76
75
  height?: number;
77
76
  barWidth?: number;
78
77
  barHeight?: number;
79
- markers?: BarChartMarker[];
78
+ showLabels?: boolean;
79
+ showMarkers?: number;
80
+ markers?: BarChartMarker[] | string;
80
81
  drawMinMax?: boolean;
81
82
  attributes?: string[];
82
83
  colors?: string[];
@@ -1,3 +1,3 @@
1
1
  import { BarChartMarker } from '@evergis/charts';
2
- import { FilterItem } from '../types';
3
- export declare const getChartMarkers: (items: FilterItem[], markers: BarChartMarker[]) => BarChartMarker[];
2
+ import { FetchedDataSource, FilterItem } from '../types';
3
+ export declare const getChartMarkers: (items: FilterItem[], markers: BarChartMarker[] | string, dataSources: FetchedDataSource[]) => BarChartMarker[];
package/dist/index.js CHANGED
@@ -112,7 +112,7 @@ const Tooltip = styled.div `
112
112
  height: 0;
113
113
  }
114
114
  `;
115
- const LineChartTooltipStyles = styled.createGlobalStyle `
115
+ const LineChartStyles = styled.createGlobalStyle `
116
116
  .dashboardLineChartTooltip.${charts.lineChartClassNames.lineChartMouseLabel} {
117
117
  .${charts.lineChartClassNames.lineChartLabelFlex} {
118
118
  justify-content: center;
@@ -187,11 +187,19 @@ const LineChartTooltipStyles = styled.createGlobalStyle `
187
187
  fill: ${({ theme: { palette } }) => palette.textDisabled};
188
188
  }
189
189
  `;
190
- const BarChartStyles = styled.createGlobalStyle `
191
- .dashboardBarChart {
192
- .domain,
190
+ const StyledBarChart = styled(charts.BarChart) `
191
+ .domain,
192
+ line {
193
+ display: none;
194
+ }
195
+
196
+ .tick {
197
+ text {
198
+ fill: ${({ theme: { palette } }) => palette.textDisabled};
199
+ }
200
+
193
201
  line {
194
- display: none;
202
+ visibility: hidden;
195
203
  }
196
204
  }
197
205
  `;
@@ -3989,41 +3997,7 @@ function wrap() {
3989
3997
  textLength = self.node().getComputedTextLength();
3990
3998
  }
3991
3999
  }
3992
- // https://jr.everpoint.ru/browse/PUB-5221
3993
- /* function wrap2(text, width, content) {
3994
- text.each(() => {
3995
- const textElem = d3.select(this);
3996
- const words = content.split(/\s+/).reverse();
3997
- let word;
3998
- let line = [];
3999
- let lineNumber = 0;
4000
- const lineHeight = 1.1; // ems
4001
- const x = 0; // textElem.attr("x");
4002
- const y = 0; // textElem.attr("y");
4003
- const dy = 0; // parseFloat(text.attr("dy")),
4004
- // eslint-disable-next-line newline-per-chained-call
4005
- let tspan = textElem.text(null).append("tspan").attr("x", x).attr("y", y).attr("dy", `${dy}em`);
4006
-
4007
- // eslint-disable-next-line no-cond-assign
4008
- while ((word = words.pop())) {
4009
- line.push(word);
4010
- tspan.text(line.join(" "));
4011
- if (tspan.node().getComputedTextLength() > width) {
4012
- line.pop();
4013
- tspan.text(line.join(" "));
4014
- line = [word];
4015
- tspan = textElem
4016
- .append("tspan")
4017
- .attr("x", x)
4018
- .attr("y", y)
4019
- // eslint-disable-next-line no-plusplus
4020
- .attr("dy", `${++lineNumber * lineHeight + dy}em`)
4021
- .text(word);
4022
- }
4023
- }
4024
- });
4025
- }*/
4026
- const useChartChange = ({ dataSources, chartId, width, height, relatedAttributes, defaultColor, fontColor, }) => {
4000
+ const useChartChange = ({ dataSources, chartId, width, height, relatedAttributes, defaultColor, fontColor, showMarkers, }) => {
4027
4001
  const { t } = useGlobalContext();
4028
4002
  const { layerInfos } = useWidgetContext();
4029
4003
  const strokeColors = relatedAttributes.filter(({ chartAxis }) => chartAxis === "y").map(({ axisColor }) => axisColor);
@@ -4060,11 +4034,17 @@ const useChartChange = ({ dataSources, chartId, width, height, relatedAttributes
4060
4034
  if (index === nodes.length - 1) {
4061
4035
  nodes[index].style.textAnchor = "end";
4062
4036
  }
4063
- if (index && index < nodes.length - 1) {
4064
- nodes[index].remove();
4037
+ if (showMarkers) {
4038
+ if (index % (showMarkers || 1) !== 0) {
4039
+ nodes[index].remove();
4040
+ }
4041
+ }
4042
+ else {
4043
+ if (index && index < nodes.length - 1) {
4044
+ nodes[index].remove();
4045
+ }
4065
4046
  }
4066
4047
  });
4067
- // svg.selectAll(`.${lineChartClassNames.lineChartXScaleGlobal} .tick text`).call(wrap2, 5, "!!!");
4068
4048
  svg.selectAll(`.${charts.lineChartClassNames.lineChartXScaleGlobal} .tick text`).attr("y", 16);
4069
4049
  svg
4070
4050
  .selectAll(`.${charts.lineChartClassNames.lineChartYScaleGlobal} .tick text`)
@@ -4110,7 +4090,7 @@ const useChartChange = ({ dataSources, chartId, width, height, relatedAttributes
4110
4090
  onChange();
4111
4091
  });
4112
4092
  svg.append("defs").html(() => defs.join(""));
4113
- }, [fontColor, dataSources, layerInfos, relatedAttributes, chartId, strokeColors, defaultColor, width, onChange]);
4093
+ }, [fontColor, dataSources, layerInfos, relatedAttributes, chartId, strokeColors, defaultColor, width, onChange, showMarkers]);
4114
4094
  return [customize, onChange];
4115
4095
  };
4116
4096
 
@@ -5399,7 +5379,11 @@ const getChartFilterName = (relatedDataSources) => {
5399
5379
  return axes?.[0]?.filterName;
5400
5380
  };
5401
5381
 
5402
- const getChartMarkers = (items, markers) => {
5382
+ const getChartMarkers = (items, markers, dataSources) => {
5383
+ if (typeof markers === "string") {
5384
+ const dataSource = getDataSource(markers, dataSources);
5385
+ return dataSource?.features?.map(({ attributes }) => attributes) || [];
5386
+ }
5403
5387
  return (markers?.map(marker => ({
5404
5388
  ...marker,
5405
5389
  value: items?.findIndex(({ name }) => name.toString() === marker.value?.toString()),
@@ -8151,7 +8135,7 @@ const useBarChartFilter = ({ type, filter, elementConfig }) => {
8151
8135
  bars.attr("rx", radius).attr("ry", radius);
8152
8136
  }, [radius]);
8153
8137
  const tooltipY = React.useMemo(() => (barHeight ? height - barHeight - DEFAULT_BAR_CHART_MARGINS.bottom : undefined), [barHeight, height]);
8154
- const markers = React.useMemo(() => getChartMarkers(filterItems, configMarkers), [configMarkers, filterItems]);
8138
+ const markers = React.useMemo(() => getChartMarkers(filterItems, configMarkers, dataSources), [configMarkers, dataSources, filterItems]);
8155
8139
  const hasDefinedColors = React.useMemo(() => configColors?.length || colorAttribute, [configColors, colorAttribute]);
8156
8140
  const marshalledMap = React.useCallback(items => {
8157
8141
  if (hasDefinedColors)
@@ -8483,7 +8467,7 @@ const getRenderElement = ({ t, config, elementConfig, attributes = [], layerInfo
8483
8467
  return formatElementValue({ t, value, elementConfig: element, attributes, wrap });
8484
8468
  };
8485
8469
 
8486
- const getResourceUrl = (url) => url ? (url.startsWith("http") ? url : `/sp/resources/${url}/download`) : "";
8470
+ const getResourceUrl = (url) => url ? (url.startsWith("http") ? url : `/sp/resources/file/${url}`) : "";
8487
8471
 
8488
8472
  const getSlideshowImages = ({ element, attribute, }) => {
8489
8473
  const { defaultValue, options } = element;
@@ -9129,10 +9113,11 @@ const StackBar = ({ data, filterName, type, alias, options, renderElement, rende
9129
9113
  const Chart = React.memo(({ config, element, elementConfig, type, renderElement }) => {
9130
9114
  const theme = styled.useTheme();
9131
9115
  const { palette } = theme;
9116
+ const primaryColor = palette.primary;
9132
9117
  const { t } = useGlobalContext();
9133
- const { expandedContainers, layerInfos, attributes } = useWidgetContext(type);
9118
+ const { expandedContainers, layerInfos, attributes, dataSources } = useWidgetContext(type);
9134
9119
  const { id, options, children } = element || {};
9135
- const { column, markers: configMarkers, showTotal, expandable, expanded, chartType, relatedDataSources, defaultColor } = options || {};
9120
+ const { column, markers: configMarkers, showLabels, showMarkers, showTotal, totalWord: configTotalWord, totalAttribute, expandable, expanded, chartType, relatedDataSources, defaultColor } = options || {};
9136
9121
  const isLineChart = chartType === "line";
9137
9122
  const isPieChart = chartType === "pie";
9138
9123
  const isStackBar = chartType === "stack";
@@ -9144,7 +9129,6 @@ const Chart = React.memo(({ config, element, elementConfig, type, renderElement
9144
9129
  const angle = options?.angle || DEFAULT_CHART_ANGLE;
9145
9130
  const barWidth = options?.barWidth || DEFAULT_BAR_WIDTH;
9146
9131
  const cornerRadius = options?.cornerRadius || 0;
9147
- const primaryColor = theme.palette.primary;
9148
9132
  const relatedAttributes = React.useMemo(() => relatedDataSources || [], [relatedDataSources]);
9149
9133
  const axes = React.useMemo(() => relatedAttributes.filter(({ chartAxis }) => chartAxis === "y"), [relatedAttributes]);
9150
9134
  const filterName = getChartFilterName(relatedDataSources);
@@ -9164,16 +9148,17 @@ const Chart = React.memo(({ config, element, elementConfig, type, renderElement
9164
9148
  height,
9165
9149
  fontColor,
9166
9150
  relatedAttributes,
9167
- defaultColor: primaryColor
9151
+ defaultColor: primaryColor,
9152
+ showMarkers,
9168
9153
  });
9169
9154
  const { formatFilterColor, onFilter } = useFeatureFilters(type, filterName, data?.[0]?.items);
9170
9155
  const formattedAttributes = React.useMemo(() => getFormattedAttributes(t, (data[0]?.items || []), attributes, element), [attributes, data, element, t]);
9171
9156
  const totalSum = React.useMemo(() => isRelated
9172
9157
  ? getTotalFromRelatedFeatures((data[0]?.items || []))
9173
9158
  : getTotalFromAttributes(children, formattedAttributes), [data, children, formattedAttributes, isRelated]);
9174
- const totalWord = React.useMemo(() => options?.totalAttribute
9175
- ? attributes?.find(({ name }) => name === options.totalAttribute)?.value
9176
- : options?.totalWord, [attributes, options.totalAttribute, options?.totalWord]);
9159
+ const totalWord = React.useMemo(() => totalAttribute
9160
+ ? attributes?.find(({ name }) => name === totalAttribute)?.value
9161
+ : configTotalWord, [attributes, totalAttribute, configTotalWord]);
9177
9162
  const renderPieChartTooltip = React.useCallback(item => isRelated
9178
9163
  ? pieChartTooltipFromRelatedFeatures(t, item, relatedAttributes, data[0]?.layerInfo)
9179
9164
  : pieChartTooltipFromAttributes(t, item, formattedAttributes), [data, formattedAttributes, isRelated, relatedAttributes]);
@@ -9192,11 +9177,17 @@ const Chart = React.memo(({ config, element, elementConfig, type, renderElement
9192
9177
  return (jsxRuntime.jsxs(ChartTooltipRow, { children: [jsxRuntime.jsx(ChartLegendColor$1, { "$color": stroke }), jsxRuntime.jsx(ChartLegendValue, { children: attribute ? formatAttributeValue({ t, type: attribute.type, value, stringFormat: attribute.stringFormat }) : value })] }, index));
9193
9178
  })] }));
9194
9179
  }, [labels, layerInfos]);
9195
- const markers = React.useMemo(() => getChartMarkers(data[0]?.items, configMarkers), [data, configMarkers]);
9180
+ const markers = React.useMemo(() => getChartMarkers(data[0]?.items, configMarkers, dataSources), [data, dataSources, configMarkers]);
9196
9181
  const formatTooltipName = React.useCallback((name) => (isRelated ? name : tooltipNameFromAttributes(name, formattedAttributes)), [formattedAttributes, isRelated]);
9197
9182
  const formatTooltipValue = React.useCallback((value, name) => isRelated
9198
9183
  ? tooltipValueFromRelatedFeatures(t, value, relatedAttributes, data[0]?.layerInfo)
9199
9184
  : tooltipValueFromAttributes(t, value, name, formattedAttributes), [data, formattedAttributes, isRelated, relatedAttributes]);
9185
+ const customXAxisBottom = React.useCallback((xAxisBottom, data) => {
9186
+ xAxisBottom.tickFormat((index) => (showMarkers
9187
+ ? index % (showMarkers || 1) === 0
9188
+ : index === 0 || index === data.length - 1)
9189
+ ? data[index]?.groupName || "" : "");
9190
+ }, [showMarkers]);
9200
9191
  const renderChart = React.useMemo(() => {
9201
9192
  if (!element)
9202
9193
  return null;
@@ -9214,7 +9205,7 @@ const Chart = React.memo(({ config, element, elementConfig, type, renderElement
9214
9205
  .flat()
9215
9206
  .map(({ values }) => values)
9216
9207
  .flat();
9217
- return (jsxRuntime.jsxs(AnyChartWrapper, { height: height, children: [jsxRuntime.jsx(LineChartTooltipStyles, {}), jsxRuntime.jsx(charts.LineChart, { data: lineChartData, labels: labels, width: +width, height: height, xAxisPadding: 15, yAxisPadding: 0, min: Math.min(...chartValues), customYAxisSelection: yAxis => {
9208
+ return (jsxRuntime.jsxs(AnyChartWrapper, { height: height, children: [jsxRuntime.jsx(LineChartStyles, {}), jsxRuntime.jsx(charts.LineChart, { data: lineChartData, labels: labels, width: +width, height: height, xAxisPadding: 15, yAxisPadding: 0, min: Math.min(...chartValues), customYAxisSelection: yAxis => {
9218
9209
  if (isHidedY) {
9219
9210
  yAxis.remove();
9220
9211
  }
@@ -9236,18 +9227,20 @@ const Chart = React.memo(({ config, element, elementConfig, type, renderElement
9236
9227
  color: formatFilterColor(item.name, item.color, defaultColor)
9237
9228
  })) || []), width: +width, height: +width, padAngle: angle, outerRadius: radius, cornerRadius: cornerRadius, renderTooltip: renderPieChartTooltip, withTooltip: true, onClick: filterName ? item => onFilter(item.name) : undefined, children: showTotal && jsxRuntime.jsx(PieChartCenter, { children: totalWord || roundTotalSum(+totalSum) }) }) }));
9238
9229
  }
9239
- const markersMargin = options?.showMarkers ? 10 : 0;
9230
+ const barChartData = getDataFromFilterItems(data[0]?.items);
9231
+ const markersMargin = showMarkers ? 10 : 0;
9240
9232
  const margin = {
9241
9233
  top: markersMargin,
9242
9234
  right: markersMargin,
9243
9235
  bottom: markers?.length ? 20 : markersMargin,
9244
9236
  left: markersMargin
9245
9237
  };
9246
- return (jsxRuntime.jsx(BarChartWrapper, { height: height + margin.bottom, children: jsxRuntime.jsxs(BarChartContainer, { children: [jsxRuntime.jsx(BarChartStyles, {}), jsxRuntime.jsx(charts.BarChart, { 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 }) => {
9247
- bars.attr("rx", radius);
9248
- bars.attr("ry", radius);
9249
- }, margin: margin, xAxisPadding: 0, yAxisPadding: 0, formatTooltipValue: formatTooltipValue, formatTooltipName: formatTooltipName, hideTooltipGroupName: true, dynamicTooltipEnable: true, isBarTooltip: true, onBarClick: filterName ? item => onFilter(item.name) : undefined })] }) }));
9238
+ return (jsxRuntime.jsx(BarChartWrapper, { height: height + margin.bottom, children: jsxRuntime.jsx(BarChartContainer, { children: jsxRuntime.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 }) => {
9239
+ bars.attr("rx", radius);
9240
+ bars.attr("ry", radius);
9241
+ }, margin: margin, xAxisPadding: 0, yAxisPadding: 0, formatTooltipValue: formatTooltipValue, formatTooltipName: formatTooltipName, hideTooltipGroupName: true, dynamicTooltipEnable: true, isBarTooltip: true, onBarClick: filterName ? item => onFilter(item.name) : undefined }) }) }));
9250
9242
  }, [
9243
+ customXAxisBottom,
9251
9244
  element,
9252
9245
  isLineChart,
9253
9246
  isStackBar,
@@ -9259,6 +9252,8 @@ const Chart = React.memo(({ config, element, elementConfig, type, renderElement
9259
9252
  formatFilterColor,
9260
9253
  width,
9261
9254
  barWidth,
9255
+ showLabels,
9256
+ showMarkers,
9262
9257
  padding,
9263
9258
  formatTooltipValue,
9264
9259
  formatTooltipName,
@@ -9553,7 +9548,10 @@ const SvgImage = React.memo(({ url, width, height, fontColor }) => {
9553
9548
  React.useEffect(() => () => {
9554
9549
  setSvg(null);
9555
9550
  }, []);
9556
- if (!svg?.endsWith("</svg>"))
9551
+ // Todo remove the test info
9552
+ console.info("svg", svg);
9553
+ const regexp = /<\/svg>\s*$/im;
9554
+ if (!regexp.test(svg))
9557
9555
  return null;
9558
9556
  return (jsxRuntime.jsx(StyledSvg, { "$width": width, "$height": height, "$fontColor": fontColor, dangerouslySetInnerHTML: { __html: svg } }));
9559
9557
  });