Skip to content
Snippets Groups Projects
Unverified Commit 988398ce authored by Nick Fitzpatrick's avatar Nick Fitzpatrick Committed by GitHub
Browse files

34618 splitting breakouts (#34674)

* no splitting when there is only 1 metric

* checking for unique cards, not series

* beefy e2e test
parent 595d2078
Branches
Tags
No related merge requests found
......@@ -5,6 +5,8 @@ import {
getDraggableElements,
moveColumnDown,
popover,
visitDashboard,
cypressWaitAll,
} from "e2e/support/helpers";
import { SAMPLE_DB_ID } from "e2e/support/cypress_data";
......@@ -358,59 +360,157 @@ describe("scenarios > visualizations > bar chart", () => {
});
it("should support showing data points with > 10 series (#33725)", () => {
visitQuestionAdhoc({
display: "bar",
dataset_query: {
database: SAMPLE_DB_ID,
type: "query",
query: {
"source-table": ORDERS_ID,
aggregation: [["count"]],
filter: [
"and",
[
"time-interval",
[
"field",
ORDERS.CREATED_AT,
{
"base-type": "type/DateTime",
},
],
-1,
"month",
{},
],
[
"=",
["field", PEOPLE.STATE, {}],
"AK",
"AL",
"AR",
"AZ",
"CA",
"CO",
"CT",
"FL",
"GA",
"IA",
],
],
breakout: [
["field", ORDERS.CREATED_AT, { "temporal-unit": "month" }],
["field", PEOPLE.STATE, { "source-field": ORDERS.USER_ID }],
],
cy.signInAsAdmin();
const stateFilter = [
"=",
["field", PEOPLE.STATE, {}],
"AK",
"AL",
"AR",
"AZ",
"CA",
"CO",
"CT",
"FL",
"GA",
"IA",
];
const dateFilter = [
"between",
[
"field",
ORDERS.CREATED_AT,
{
"base-type": "type/DateTime",
},
],
"2023-09-01",
"2023-09-30",
];
const avgTotalByMonth = {
name: "Average Total by Month",
type: "query",
query: {
"source-table": ORDERS_ID,
aggregation: [["avg", ["field", ORDERS.TOTAL]]],
breakout: [["field", ORDERS.CREATED_AT, { "temporal-unit": "month" }]],
},
display: "line",
};
const sumTotalByMonth = {
name: "Sum Total by Month",
type: "query",
query: {
"source-table": ORDERS_ID,
aggregation: [["sum", ["field", ORDERS.TOTAL]]],
breakout: [["field", ORDERS.CREATED_AT, { "temporal-unit": "month" }]],
},
display: "line",
};
const multiMetric = {
name: "Should split",
type: "query",
query: {
"source-table": ORDERS_ID,
aggregation: [
["avg", ["field", ORDERS.TAX]],
["sum", ["field", ORDERS.TAX]],
["min", ["field", ORDERS.TAX]],
["max", ["field", ORDERS.TAX]],
["avg", ["field", ORDERS.SUBTOTAL]],
["sum", ["field", ORDERS.SUBTOTAL]],
["min", ["field", ORDERS.SUBTOTAL]],
["max", ["field", ORDERS.SUBTOTAL]],
["avg", ["field", ORDERS.TOTAL]],
["sum", ["field", ORDERS.TOTAL]],
["min", ["field", ORDERS.TOTAL]],
["max", ["field", ORDERS.TOTAL]],
],
breakout: [["field", ORDERS.CREATED_AT, { "temporal-unit": "month" }]],
filter: dateFilter,
},
display: "bar",
visualization_settings: {
"graph.show_values": true,
},
};
const breakoutQuestion = {
name: "Should not Split",
type: "query",
query: {
"source-table": ORDERS_ID,
aggregation: [["count"]],
breakout: [
["field", ORDERS.CREATED_AT, { "temporal-unit": "month" }],
["field", PEOPLE.STATE, { "source-field": ORDERS.USER_ID }],
],
filter: ["and", stateFilter, dateFilter],
},
display: "bar",
visualization_settings: {
"graph.dimensions": ["CREATED_AT", "STATE"],
"graph.metrics": ["count"],
"graph.show_values": true,
},
};
cy.createDashboardWithQuestions({
dashboardName: "Split Test Dashboard",
questions: [multiMetric],
}).then(({ dashboard }) => {
cy.createQuestion(sumTotalByMonth, { wrapId: true }).then(() => {
cy.get("@questionId").then(questionId => {
cypressWaitAll([
cy.createQuestionAndAddToDashboard(avgTotalByMonth, dashboard.id, {
series: [
{
id: questionId,
},
],
col: 12,
row: 0,
visualization_settings: {
"card.title": "Multi Series",
},
}),
cy.createQuestionAndAddToDashboard(breakoutQuestion, dashboard.id, {
col: 0,
row: 9,
size_x: 15,
}),
]).then(() => {
visitDashboard(dashboard.id);
});
});
});
});
cy.get(".value-labels").should("contain", "6");
cy.get(".value-labels").should("contain", "13");
cy.get(".value-labels").should("contain", "19");
//This card is testing #33725 now, as the changes made for #34618 would cause "Should not Split" to no longer split and error
cy.findAllByTestId("dashcard")
.contains("[data-testid=dashcard]", "Should split")
.within(() => {
cy.get(".axis.yr").should("exist");
});
cy.findAllByTestId("dashcard")
.contains("[data-testid=dashcard]", "Multi Series")
.within(() => {
cy.get(".axis.yr").should("exist");
});
cy.log("Should not produce a split axis graph (#34618)");
cy.findAllByTestId("dashcard")
.contains("[data-testid=dashcard]", "Should not Split")
.within(() => {
cy.get(".value-labels").should("contain", "6");
cy.get(".value-labels").should("contain", "13");
cy.get(".value-labels").should("contain", "19");
cy.get(".axis.yr").should("not.exist");
});
});
});
......@@ -353,6 +353,19 @@ export function xValueForWaterfallTotal({ settings, series }) {
return TOTAL_ORDINAL_VALUE;
}
const uniqueCards = series => _.uniq(series.map(({ card }) => card.id)).length;
const aggregateColumns = series => {
return _.uniq(
series
.map(({ data: { cols } }) => {
return cols.filter(col => col.source === "aggregation");
})
.flat()
.map(({ name }) => name),
).length;
};
export function shouldSplitYAxis(
{ settings, chartType, isScalarSeries, series },
datas,
......@@ -362,6 +375,7 @@ export function shouldSplitYAxis(
isScalarSeries ||
chartType === "scatter" ||
settings["graph.y_axis.auto_split"] === false ||
(uniqueCards(series) < 2 && aggregateColumns(series) < 2) ||
isStacked(settings, datas)
) {
return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment