Skip to content

Commit 06bd7fc

Browse files
authored
feat(explore): Flatten visualize yaxes into multiple (#91664)
There are still places where we have multiple y axes in a visualize. This flattens them into multiple visualizes at render time. A migration will follow in the future to fix all of them.
1 parent f8a7b59 commit 06bd7fc

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

static/app/views/explore/contexts/pageParamsContext/index.spec.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,14 @@ describe('PageParamsProvider', function () {
322322
query: '',
323323
sortBys: [{field: 'max(span.duration)', kind: 'desc'}],
324324
visualizes: [
325-
new Visualize(['min(span.self_time)', 'max(span.duration)'], {
325+
new Visualize(['min(span.self_time)'], {
326326
label: 'A',
327327
chartType: ChartType.AREA,
328328
}),
329+
new Visualize(['max(span.duration)'], {
330+
label: 'B',
331+
chartType: ChartType.AREA,
332+
}),
329333
],
330334
});
331335
});
@@ -352,10 +356,14 @@ describe('PageParamsProvider', function () {
352356
query: '',
353357
sortBys: [{field: 'min(span.self_time)', kind: 'desc'}],
354358
visualizes: [
355-
new Visualize(['min(span.self_time)', 'max(span.duration)'], {
359+
new Visualize(['min(span.self_time)'], {
356360
label: 'A',
357361
chartType: ChartType.AREA,
358362
}),
363+
new Visualize(['max(span.duration)'], {
364+
label: 'B',
365+
chartType: ChartType.AREA,
366+
}),
359367
],
360368
});
361369
});
@@ -421,10 +429,14 @@ describe('PageParamsProvider', function () {
421429
sortBys: [{field: 'count(span.self_time)', kind: 'asc'}],
422430
visualizes: [
423431
new Visualize(['count(span.self_time)'], {label: 'A', chartType: ChartType.AREA}),
424-
new Visualize(['avg(span.duration)', 'avg(span.self_time)'], {
432+
new Visualize(['avg(span.duration)'], {
425433
label: 'B',
426434
chartType: ChartType.LINE,
427435
}),
436+
new Visualize(['avg(span.self_time)'], {
437+
label: 'C',
438+
chartType: ChartType.LINE,
439+
}),
428440
],
429441
});
430442
});

static/app/views/explore/contexts/pageParamsContext/visualizes.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,26 @@ export function getVisualizesFromLocation(
8686
): Visualize[] {
8787
const rawVisualizes = decodeList(location.query.visualize);
8888

89-
const result: Visualize[] = rawVisualizes
89+
const visualizes: Visualize[] = [];
90+
91+
const baseVisualizes: BaseVisualize[] = rawVisualizes
9092
.map(raw => parseVisualizes(raw, organization))
91-
.filter(defined)
92-
.filter(parsed => parsed.yAxes.length > 0)
93-
.map((parsed, i) => {
94-
return new Visualize(parsed.yAxes, {
95-
label: String.fromCharCode(65 + i), // starts from 'A'
96-
chartType: parsed.chartType,
97-
});
98-
});
93+
.filter(defined);
94+
95+
let i = 0;
96+
for (const visualize of baseVisualizes) {
97+
for (const yAxis of visualize.yAxes) {
98+
visualizes.push(
99+
new Visualize([yAxis], {
100+
label: String.fromCharCode(65 + i), // starts from 'A',
101+
chartType: visualize.chartType,
102+
})
103+
);
104+
i++;
105+
}
106+
}
99107

100-
return result.length ? result : defaultVisualizes();
108+
return visualizes.length ? visualizes : defaultVisualizes();
101109
}
102110

103111
function parseVisualizes(raw: string, organization: Organization): BaseVisualize | null {

static/app/views/explore/hooks/useAddToDashboard.spec.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,8 @@ describe('AddToDashboardButton', () => {
245245
queries: [
246246
{
247247
aggregates: [
248+
// because the visualizes get flattend, we only take the first y axis
248249
'avg(span.duration)',
249-
'max(span.duration)',
250-
'min(span.duration)',
251250
],
252251
columns: [],
253252
fields: [],

0 commit comments

Comments
 (0)