Skip to content

Commit c47560c

Browse files
committed
refactor(charts-web): refactor to remove duplicate aggregate method call
1 parent 3af32be commit c47560c

File tree

7 files changed

+12
-32
lines changed

7 files changed

+12
-32
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,23 @@ export const AreaChart = memo(function AreaChart(props: AreaChartContainerProps)
3737
const lineColorExpression = line.dataSet === "static" ? line.staticLineColor : line.dynamicLineColor;
3838
const markerColorExpression = line.dataSet === "static" ? line.staticMarkerColor : line.dynamicMarkerColor;
3939
const fillColorExpression = line.dataSet === "static" ? line.staticFillColor : line.dynamicFillColor;
40-
const pts =
41-
line.aggregationType === "none" ? dataPoints : aggregateDataPoints(line.aggregationType, dataPoints);
4240

4341
return {
4442
type: "scatter",
4543
fill: "tonexty",
4644
fillcolor: fillColorExpression
47-
? getExpressionValue<string>(fillColorExpression, pts.dataSourceItems)
45+
? getExpressionValue<string>(fillColorExpression, dataPoints.dataSourceItems)
4846
: undefined,
4947
mode: line.lineStyle === "line" ? "lines" : "lines+markers",
5048
line: {
5149
shape: line.interpolation,
5250
color: lineColorExpression
53-
? getExpressionValue<string>(lineColorExpression, pts.dataSourceItems)
51+
? getExpressionValue<string>(lineColorExpression, dataPoints.dataSourceItems)
5452
: undefined
5553
},
5654
marker: {
5755
color: markerColorExpression
58-
? getExpressionValue<string>(markerColorExpression, pts.dataSourceItems)
56+
? getExpressionValue<string>(markerColorExpression, dataPoints.dataSourceItems)
5957
: undefined
6058
}
6159
};

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,13 @@ export const BarChart = memo(function BarChart(props: BarChartContainerProps): R
4646
useCallback((dataSeries, dataPoints, { getExpressionValue }) => {
4747
const barColorExpression =
4848
dataSeries.dataSet === "static" ? dataSeries.staticBarColor : dataSeries.dynamicBarColor;
49-
const pts =
50-
dataSeries.aggregationType === "none"
51-
? dataPoints
52-
: aggregateDataPoints(dataSeries.aggregationType, dataPoints);
49+
5350
return {
5451
type: "bar",
5552
orientation: "h",
5653
marker: {
5754
color: barColorExpression
58-
? getExpressionValue<string>(barColorExpression, pts.dataSourceItems)
55+
? getExpressionValue<string>(barColorExpression, dataPoints.dataSourceItems)
5956
: undefined
6057
}
6158
};

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,13 @@ export const BubbleChart = memo(
7070
);
7171
const markerColorExpression =
7272
line.dataSet === "static" ? line.staticMarkerColor : line.dynamicMarkerColor;
73-
const pts =
74-
line.aggregationType === "none"
75-
? dataPoints
76-
: aggregateDataPoints(line.aggregationType, dataPoints);
73+
7774
return {
7875
type: "scatter",
7976
mode: "markers",
8077
marker: {
8178
color: markerColorExpression
82-
? getExpressionValue<string>(markerColorExpression, pts.dataSourceItems)
79+
? getExpressionValue<string>(markerColorExpression, dataPoints.dataSourceItems)
8380
: undefined,
8481
symbol: ["circle"],
8582
size,

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,10 @@ export const ColumnChart = memo(function ColumnChart(props: ColumnChartContainer
4646
useCallback((dataSeries, dataPoints, { getExpressionValue }) => {
4747
const columnColorExpression =
4848
dataSeries.dataSet === "static" ? dataSeries.staticBarColor : dataSeries.dynamicBarColor;
49-
const pts =
50-
dataSeries.aggregationType === "none"
51-
? dataPoints
52-
: aggregateDataPoints(dataSeries.aggregationType, dataPoints);
5349
return {
5450
marker: {
5551
color: columnColorExpression
56-
? getExpressionValue<string>(columnColorExpression, pts.dataSourceItems)
52+
? getExpressionValue<string>(columnColorExpression, dataPoints.dataSourceItems)
5753
: undefined
5854
}
5955
};

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,19 @@ export const LineChart = memo(
3535
const lineColorExpression = line.dataSet === "static" ? line.staticLineColor : line.dynamicLineColor;
3636
const markerColorExpression =
3737
line.dataSet === "static" ? line.staticMarkerColor : line.dynamicMarkerColor;
38-
const pts =
39-
line.aggregationType === "none"
40-
? dataPoints
41-
: aggregateDataPoints(line.aggregationType, dataPoints);
38+
4239
return {
4340
type: "scatter",
4441
mode: line.lineStyle === "line" ? "lines" : "lines+markers",
4542
line: {
4643
shape: line.interpolation,
4744
color: lineColorExpression
48-
? getExpressionValue<string>(lineColorExpression, pts.dataSourceItems)
45+
? getExpressionValue<string>(lineColorExpression, dataPoints.dataSourceItems)
4946
: undefined
5047
},
5148
marker: {
5249
color: markerColorExpression
53-
? getExpressionValue<string>(markerColorExpression, pts.dataSourceItems)
50+
? getExpressionValue<string>(markerColorExpression, dataPoints.dataSourceItems)
5451
: undefined
5552
}
5653
};

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,7 @@ export const TimeSeries = memo(
5757
function TimeSeries(props: TimeSeriesContainerProps): ReactElement | null {
5858
const chartLines = usePlotChartDataSeries(
5959
props.lines,
60-
useCallback((line, dataPoints) => {
61-
const pts =
62-
line.aggregationType === "none"
63-
? dataPoints
64-
: aggregateDataPoints(line.aggregationType, dataPoints);
60+
useCallback(line => {
6561
return {
6662
mode: line.lineStyle === "line" ? "lines" : "lines+markers",
6763
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)