Skip to content

Commit ee5d0bf

Browse files
justinparkFahrenheit35
authored andcommitted
fix(plugin-chart-echarts): missing value format in mixed timeseries (apache#21044)
1 parent c9c25aa commit ee5d0bf

File tree

3 files changed

+141
-2
lines changed

3 files changed

+141
-2
lines changed

superset-frontend/packages/superset-ui-demo/storybook/stories/plugins/plugin-chart-echarts/MixedTimeseries/Stories.tsx

+63-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
MixedTimeseriesTransformProps,
3232
} from '@superset-ui/plugin-chart-echarts';
3333
import data from '../Timeseries/data';
34+
import negativeNumData from './negativeData';
3435
import { withResizableChartDemo } from '../../../../shared/components/ResizableChartDemo';
3536

3637
new EchartsTimeseriesChartPlugin()
@@ -57,6 +58,8 @@ export const Timeseries = ({ width, height }) => {
5758
Boston: row.Boston,
5859
}))
5960
.filter(row => !!row.Boston),
61+
colnames: ['__timestamp'],
62+
coltypes: [2],
6063
},
6164
{
6265
data: data
@@ -82,8 +85,13 @@ export const Timeseries = ({ width, height }) => {
8285
logAxis: boolean('Log axis', false),
8386
xAxisTimeFormat: 'smart_date',
8487
tooltipTimeFormat: 'smart_date',
85-
yAxisFormat: 'SMART_NUMBER',
88+
yAxisFormat: select(
89+
'y-axis format',
90+
['$,.2f', 'SMART_NUMBER'],
91+
'$,.2f',
92+
),
8693
yAxisTitle: text('Y Axis title', ''),
94+
yAxisIndexB: select('yAxisIndexB', [0, 1], 1),
8795
minorSplitLine: boolean('Query 1: Minor splitline', false),
8896
seriesType: select(
8997
'Query 1: Line type',
@@ -105,7 +113,61 @@ export const Timeseries = ({ width, height }) => {
105113
markerEnabledB: boolean('Query 2: Enable markers', false),
106114
markerSizeB: number('Query 2: Marker Size', 6),
107115
opacityB: number('Query 2: Opacity', 0.2),
116+
showValue: true,
108117
}}
109118
/>
110119
);
111120
};
121+
122+
export const WithNegativeNumbers = ({ width, height }) => (
123+
<SuperChart
124+
chartType="mixed-timeseries"
125+
width={width}
126+
height={height}
127+
queriesData={[
128+
{
129+
data: negativeNumData,
130+
colnames: ['__timestamp'],
131+
coltypes: [2],
132+
},
133+
{
134+
data: negativeNumData.map(({ __timestamp, Boston }) => ({
135+
__timestamp,
136+
avgRate: Boston / 100,
137+
})),
138+
},
139+
]}
140+
formData={{
141+
contributionMode: undefined,
142+
colorScheme: 'supersetColors',
143+
seriesType: select(
144+
'Line type',
145+
['line', 'scatter', 'smooth', 'bar', 'start', 'middle', 'end'],
146+
'line',
147+
),
148+
xAxisTimeFormat: 'smart_date',
149+
yAxisFormat: select(
150+
'y-axis format',
151+
{
152+
'Original value': '~g',
153+
'Smart number': 'SMART_NUMBER',
154+
'(12345.432 => $12,345.43)': '$,.2f',
155+
},
156+
'$,.2f',
157+
),
158+
stack: true,
159+
showValue: boolean('Query 1: Show Value', true),
160+
showValueB: boolean('Query 2: Show Value', false),
161+
showLegend: true,
162+
markerEnabledB: true,
163+
yAxisIndexB: select(
164+
'Query 2: Y Axis',
165+
{
166+
Primary: 0,
167+
Secondary: 1,
168+
},
169+
1,
170+
),
171+
}}
172+
/>
173+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
export default [
21+
{
22+
__timestamp: 1619827200000,
23+
Boston: 10.8812312312,
24+
Washington: -45.3089432023,
25+
JerseyCity: -23.0509234029834,
26+
},
27+
{
28+
__timestamp: 1622505600000,
29+
Boston: 80.81029340234,
30+
Washington: -10.299023489023,
31+
JerseyCity: 53.54239402349,
32+
},
33+
{
34+
__timestamp: 1625097600000,
35+
Boston: 30.9129034924,
36+
Washington: 100.25234902349,
37+
JerseyCity: 27.17239402394,
38+
},
39+
{
40+
__timestamp: 1627776000000,
41+
Boston: 42.6129034924,
42+
Washington: 90.23234902349,
43+
JerseyCity: -32.23239402394,
44+
},
45+
];

superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts

+33-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ import {
4747
getAxisType,
4848
getColtypesMapping,
4949
getLegendProps,
50+
extractDataTotalValues,
51+
extractShowValueIndexes,
5052
} from '../utils/series';
5153
import { extractAnnotationLabels } from '../utils/annotation';
5254
import {
@@ -136,6 +138,7 @@ export default function transformProps(
136138
yAxisTitlePosition,
137139
sliceId,
138140
timeGrainSqla,
141+
percentageThreshold,
139142
}: EchartsMixedTimeseriesFormData = { ...DEFAULT_FORM_DATA, ...formData };
140143

141144
const colorScale = CategoricalColorNamespace.getScale(colorScheme as string);
@@ -181,7 +184,28 @@ export default function transformProps(
181184
rawSeriesB.forEach(seriesOption =>
182185
mapSeriesIdToAxis(seriesOption, yAxisIndexB),
183186
);
184-
187+
const showValueIndexesA = extractShowValueIndexes(rawSeriesA, {
188+
stack,
189+
});
190+
const showValueIndexesB = extractShowValueIndexes(rawSeriesB, {
191+
stack,
192+
});
193+
const { totalStackedValues, thresholdValues } = extractDataTotalValues(
194+
rebasedDataA,
195+
{
196+
stack,
197+
percentageThreshold,
198+
xAxisCol,
199+
},
200+
);
201+
const {
202+
totalStackedValues: totalStackedValuesB,
203+
thresholdValues: thresholdValuesB,
204+
} = extractDataTotalValues(rebasedDataB, {
205+
stack: Boolean(stackB),
206+
percentageThreshold,
207+
xAxisCol,
208+
});
185209
rawSeriesA.forEach(entry => {
186210
const transformedSeries = transformSeries(entry, colorScale, {
187211
area,
@@ -195,6 +219,10 @@ export default function transformProps(
195219
filterState,
196220
seriesKey: entry.name,
197221
sliceId,
222+
formatter,
223+
showValueIndexes: showValueIndexesA,
224+
totalStackedValues,
225+
thresholdValues,
198226
});
199227
if (transformedSeries) series.push(transformedSeries);
200228
});
@@ -214,6 +242,10 @@ export default function transformProps(
214242
? `${entry.name} (1)`
215243
: entry.name,
216244
sliceId,
245+
formatter: formatterSecondary,
246+
showValueIndexes: showValueIndexesB,
247+
totalStackedValues: totalStackedValuesB,
248+
thresholdValues: thresholdValuesB,
217249
});
218250
if (transformedSeries) series.push(transformedSeries);
219251
});

0 commit comments

Comments
 (0)