Skip to content

Commit bd35983

Browse files
rahmanunvergjulivan
authored andcommitted
refactor(charts-web): refactor to remove duplicate aggregate method call
1 parent 8c75857 commit bd35983

File tree

7 files changed

+12
-38
lines changed

7 files changed

+12
-38
lines changed

packages/pluggableWidgets/area-chart-web/src/AreaChart.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
containerPropsEqual,
66
usePlotChartDataSeries
77
} from "@mendix/shared-charts/main";
8-
import { aggregateDataPoints } from "@mendix/shared-charts/utils/aggregations";
98
import "@mendix/shared-charts/ui/Chart.scss";
109
import classNames from "classnames";
1110
import { createElement, memo, ReactElement, useCallback } from "react";
@@ -37,25 +36,23 @@ export const AreaChart = memo(function AreaChart(props: AreaChartContainerProps)
3736
const lineColorExpression = line.dataSet === "static" ? line.staticLineColor : line.dynamicLineColor;
3837
const markerColorExpression = line.dataSet === "static" ? line.staticMarkerColor : line.dynamicMarkerColor;
3938
const fillColorExpression = line.dataSet === "static" ? line.staticFillColor : line.dynamicFillColor;
40-
const pts =
41-
line.aggregationType === "none" ? dataPoints : aggregateDataPoints(line.aggregationType, dataPoints);
4239

4340
return {
4441
type: "scatter",
4542
fill: "tonexty",
4643
fillcolor: fillColorExpression
47-
? getExpressionValue<string>(fillColorExpression, pts.dataSourceItems)
44+
? getExpressionValue<string>(fillColorExpression, dataPoints.dataSourceItems)
4845
: undefined,
4946
mode: line.lineStyle === "line" ? "lines" : "lines+markers",
5047
line: {
5148
shape: line.interpolation,
5249
color: lineColorExpression
53-
? getExpressionValue<string>(lineColorExpression, pts.dataSourceItems)
50+
? getExpressionValue<string>(lineColorExpression, dataPoints.dataSourceItems)
5451
: undefined
5552
},
5653
marker: {
5754
color: markerColorExpression
58-
? getExpressionValue<string>(markerColorExpression, pts.dataSourceItems)
55+
? getExpressionValue<string>(markerColorExpression, dataPoints.dataSourceItems)
5956
: undefined
6057
}
6158
};

packages/pluggableWidgets/bar-chart-web/src/BarChart.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { ChartWidget, ChartWidgetProps, containerPropsEqual, usePlotChartDataSer
22
import "@mendix/shared-charts/ui/Chart.scss";
33
import classNames from "classnames";
44
import { ReactElement, createElement, memo, useCallback, useMemo } from "react";
5-
import { aggregateDataPoints } from "@mendix/shared-charts/utils/aggregations";
65

76
import { BarChartContainerProps } from "../typings/BarChartProps";
87

@@ -46,16 +45,13 @@ export const BarChart = memo(function BarChart(props: BarChartContainerProps): R
4645
useCallback((dataSeries, dataPoints, { getExpressionValue }) => {
4746
const barColorExpression =
4847
dataSeries.dataSet === "static" ? dataSeries.staticBarColor : dataSeries.dynamicBarColor;
49-
const pts =
50-
dataSeries.aggregationType === "none"
51-
? dataPoints
52-
: aggregateDataPoints(dataSeries.aggregationType, dataPoints);
48+
5349
return {
5450
type: "bar",
5551
orientation: "h",
5652
marker: {
5753
color: barColorExpression
58-
? getExpressionValue<string>(barColorExpression, pts.dataSourceItems)
54+
? getExpressionValue<string>(barColorExpression, dataPoints.dataSourceItems)
5955
: undefined
6056
}
6157
};

packages/pluggableWidgets/bubble-chart-web/src/BubbleChart.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import classNames from "classnames";
66
import { ReactElement, createElement, memo, useCallback } from "react";
77
import { BubbleChartContainerProps, LinesType } from "../typings/BubbleChartProps";
88
import { calculateSizeRef } from "./utils";
9-
import { aggregateDataPoints } from "@mendix/shared-charts/utils/aggregations";
109

1110
const bubbleChartLayoutOptions: ChartWidgetProps["layoutOptions"] = {
1211
xaxis: {
@@ -70,16 +69,13 @@ export const BubbleChart = memo(
7069
);
7170
const markerColorExpression =
7271
line.dataSet === "static" ? line.staticMarkerColor : line.dynamicMarkerColor;
73-
const pts =
74-
line.aggregationType === "none"
75-
? dataPoints
76-
: aggregateDataPoints(line.aggregationType, dataPoints);
72+
7773
return {
7874
type: "scatter",
7975
mode: "markers",
8076
marker: {
8177
color: markerColorExpression
82-
? getExpressionValue<string>(markerColorExpression, pts.dataSourceItems)
78+
? getExpressionValue<string>(markerColorExpression, dataPoints.dataSourceItems)
8379
: undefined,
8480
symbol: ["circle"],
8581
size,

packages/pluggableWidgets/column-chart-web/src/ColumnChart.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import "@mendix/shared-charts/ui/Chart.scss";
33
import classNames from "classnames";
44
import { ReactElement, createElement, memo, useCallback, useMemo } from "react";
55
import { ColumnChartContainerProps } from "../typings/ColumnChartProps";
6-
import { aggregateDataPoints } from "@mendix/shared-charts/utils/aggregations";
76

87
const columnChartLayoutOptions: ChartWidgetProps["layoutOptions"] = {
98
xaxis: {
@@ -46,14 +45,10 @@ export const ColumnChart = memo(function ColumnChart(props: ColumnChartContainer
4645
useCallback((dataSeries, dataPoints, { getExpressionValue }) => {
4746
const columnColorExpression =
4847
dataSeries.dataSet === "static" ? dataSeries.staticBarColor : dataSeries.dynamicBarColor;
49-
const pts =
50-
dataSeries.aggregationType === "none"
51-
? dataPoints
52-
: aggregateDataPoints(dataSeries.aggregationType, dataPoints);
5348
return {
5449
marker: {
5550
color: columnColorExpression
56-
? getExpressionValue<string>(columnColorExpression, pts.dataSourceItems)
51+
? getExpressionValue<string>(columnColorExpression, dataPoints.dataSourceItems)
5752
: undefined
5853
}
5954
};

packages/pluggableWidgets/line-chart-web/src/LineChart.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ChartWidget, ChartWidgetProps, traceEqual, usePlotChartDataSeries } from "@mendix/shared-charts/main";
2-
import { aggregateDataPoints } from "@mendix/shared-charts/utils/aggregations";
32
import "@mendix/shared-charts/ui/Chart.scss";
43
import { defaultEqual, flatEqual } from "@mendix/widget-plugin-platform/utils/flatEqual";
54
import classNames from "classnames";
@@ -35,22 +34,19 @@ export const LineChart = memo(
3534
const lineColorExpression = line.dataSet === "static" ? line.staticLineColor : line.dynamicLineColor;
3635
const markerColorExpression =
3736
line.dataSet === "static" ? line.staticMarkerColor : line.dynamicMarkerColor;
38-
const pts =
39-
line.aggregationType === "none"
40-
? dataPoints
41-
: aggregateDataPoints(line.aggregationType, dataPoints);
37+
4238
return {
4339
type: "scatter",
4440
mode: line.lineStyle === "line" ? "lines" : "lines+markers",
4541
line: {
4642
shape: line.interpolation,
4743
color: lineColorExpression
48-
? getExpressionValue<string>(lineColorExpression, pts.dataSourceItems)
44+
? getExpressionValue<string>(lineColorExpression, dataPoints.dataSourceItems)
4945
: undefined
5046
},
5147
marker: {
5248
color: markerColorExpression
53-
? getExpressionValue<string>(markerColorExpression, pts.dataSourceItems)
49+
? getExpressionValue<string>(markerColorExpression, dataPoints.dataSourceItems)
5450
: undefined
5551
}
5652
};

packages/pluggableWidgets/time-series-chart-web/src/TimeSeries.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ChartWidget, ChartWidgetProps, usePlotChartDataSeries, traceEqual } from "@mendix/shared-charts/main";
2-
import { aggregateDataPoints } from "@mendix/shared-charts/utils/aggregations";
32
import "@mendix/shared-charts/ui/Chart.scss";
43
import { defaultEqual, flatEqual } from "@mendix/widget-plugin-platform/utils/flatEqual";
54
import classNames from "classnames";
@@ -57,11 +56,7 @@ export const TimeSeries = memo(
5756
function TimeSeries(props: TimeSeriesContainerProps): ReactElement | null {
5857
const chartLines = usePlotChartDataSeries(
5958
props.lines,
60-
useCallback((line, dataPoints) => {
61-
const pts =
62-
line.aggregationType === "none"
63-
? dataPoints
64-
: aggregateDataPoints(line.aggregationType, dataPoints);
59+
useCallback(line => {
6560
return {
6661
mode: line.lineStyle === "line" ? "lines" : "lines+markers",
6762
fill: line.enableFillArea ? "tonexty" : "none",

packages/shared/charts/src/utils/aggregations.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// packages/shared/charts/src/utils/aggregations.ts
21
import { Datum } from "plotly.js-dist-min";
32
import { PlotChartDataPoints } from "../hooks/usePlotChartDataSeries";
43

0 commit comments

Comments
 (0)