The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
const { H } = cy;
import { SAMPLE_DB_ID } from "e2e/support/cypress_data";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
const { ORDERS, ORDERS_ID, PRODUCTS } = SAMPLE_DATABASE;
const testQuery = {
database: SAMPLE_DB_ID,
query: {
"source-table": ORDERS_ID,
aggregation: [
["count"],
[
"distinct",
["field", PRODUCTS.ID, { "source-field": ORDERS.PRODUCT_ID }],
],
],
breakout: [["field", ORDERS.CREATED_AT, { "temporal-unit": "month" }]],
},
type: "query",
};
const testQueryBreakout = {
database: SAMPLE_DB_ID,
query: {
"source-table": ORDERS_ID,
aggregation: [["count"]],
breakout: [
["field", ORDERS.CREATED_AT, { "temporal-unit": "year" }],
["field", PRODUCTS.CATEGORY, { "source-field": ORDERS.PRODUCT_ID }],
["field", PRODUCTS.RATING, null],
],
},
type: "query",
};
describe("scenarios > visualizations > scatter", () => {
beforeEach(() => {
H.restore();
cy.signInAsNormalUser();
});
it("should show correct labels in tooltip (metabase#15150)", () => {
H.visitQuestionAdhoc({
dataset_query: testQuery,
display: "scatter",
visualization_settings: {
"graph.dimensions": ["CREATED_AT"],
"graph.metrics": ["count", "count_2"],
},
});
triggerPopoverForBubble();
H.assertEChartsTooltip({
header: "May 2026",
rows: [
{
name: "Count",
value: "271",
},
{
name: "Distinct values of Product → ID",
value: "137",
},
],
});
});
it("should show correct labels in tooltip when display name has manually set (metabase#11395)", () => {
H.visitQuestionAdhoc({
dataset_query: testQuery,
display: "scatter",
visualization_settings: {
"graph.dimensions": ["CREATED_AT"],
"graph.metrics": ["count", "count_2"],
series_settings: {
count: {
title: "Orders count",
},
count_2: {
title: "Products count",
},
},
},
});
triggerPopoverForBubble();
H.assertEChartsTooltip({
header: "May 2026",
rows: [
{
name: "Orders count",
value: "271",
},
{
name: "Products count",
value: "137",
},
],
});
});
it("should not show non-hovered breakout series in the tooltip (metabase#50630)", () => {
H.visitQuestionAdhoc({
dataset_query: testQueryBreakout,
display: "scatter",
visualization_settings: {
"graph.dimensions": ["CREATED_AT", "CATEGORY"],
"graph.metrics": ["count"],
},
});
// Use force=true because this chart has too many bubbles that overlap with each other
triggerPopoverForBubble(300, true);
H.assertEChartsTooltip({
header: "2028",
rows: [
{
name: "Widget",
value: "173",
},
],
});
H.assertEChartsTooltipNotContain(["Gizmo", "Gadget", "Doohickey"]);
});
it("should not display data points even when enabled in settings (metabase#13247)", () => {
H.visitQuestionAdhoc({
display: "scatter",
dataset_query: testQuery,
visualization_settings: {
"graph.metrics": ["count"],
"graph.dimensions": ["CREATED_AT"],
"graph.show_values": true,
},
});
H.cartesianChartCircle().should("have.length", 49);
H.getValueLabels().should("not.exist");
H.echartsContainer().findByText("79").should("not.exist");
});
it("should respect circle size in a visualization (metabase#22929)", () => {
H.visitQuestionAdhoc({
dataset_query: {
type: "native",
native: {
query: `select 1 as size, 1 as x, 5 as y union all
select 10 as size, 2 as x, 5 as y`,
},
database: SAMPLE_DB_ID,
},
display: "scatter",
visualization_settings: {
"scatter.bubble": "SIZE",
"graph.dimensions": ["X"],
"graph.metrics": ["Y"],
},
});
H.cartesianChartCircle().each(([circle], index) => {
const { width, height } = circle.getBoundingClientRect();
const TOLERANCE = 0.1;
expect(width).to.be.greaterThan(0);
expect(height).to.be.within(width - TOLERANCE, width + TOLERANCE);
cy.wrap(width).as("radius" + index);
});
cy.get("@radius0").then((r0) => {
cy.get("@radius1").then((r1) => {
assert.notEqual(r0, r1);
});
});
});
it("should allow adding non-series columns to the tooltip", () => {
const allTooltipRows = [
{ name: "Tax", value: "0.86" },
{ name: "ID", value: "562" },
{ name: "User ID", value: "70" },
{ name: "Product ID", value: "61" },
{ name: "Total", value: "16.55" },
{ name: "Discount", value: "" },
{ name: "Created At", value: "July 4, 2026, 4:57 AM" },
{ name: "Quantity", value: "4" },
];
H.visitQuestionAdhoc({
display: "scatter",
dataset_query: {
type: "query",
database: SAMPLE_DB_ID,
query: { "source-table": ORDERS_ID },
},
visualization_settings: {
"graph.metrics": ["TAX"],
"graph.dimensions": ["SUBTOTAL"],
},
});
stabilizeScatterChart();
H.cartesianChartCircle().first().realHover();
H.assertEChartsTooltip({
header: "15.69",
rows: allTooltipRows,
});
H.openVizSettingsSidebar();
// Resizing animation due to the sidebar
cy.wait(200);
const columnsToRemove = allTooltipRows.slice(2).map((row) => row.name);
H.leftSidebar().within(() => {
cy.findByText("Display").click();
columnsToRemove.map((columnName) => {
cy.findByRole("textbox", { name: "Enter column names" })
.parent()
.findByText(columnName)
.siblings("button")
.click();
});
});
stabilizeScatterChart();
H.cartesianChartCircle().first().realHover();
H.assertEChartsTooltip({
header: "15.69",
rows: allTooltipRows.slice(0, 2),
});
H.assertEChartsTooltipNotContain(columnsToRemove);
});
it("should render scatter plot with native query data (metabase#55880)", () => {
H.visitQuestionAdhoc({
visualization_settings: {
"graph.dimensions": ["X"],
"graph.metrics": ["Y"],
},
dataset_query: {
type: "native",
native: {
query: `select * from (
select 1415 x, 1 y
union all select 20, 2
union all select 900, 3
union all select 115, 4
) as subquery
where x < {{param}}`,
"template-tags": {
param: {
type: "number",
name: "param",
id: "144103a1-ebd4-4477-a7fa-f08cfd808d5e",
"display-name": "Param",
required: true,
default: "30",
},
},
},
database: SAMPLE_DB_ID,
},
display: "scatter",
});
// Renders a scatter chart with numeric x-axis
H.chartPathWithFillColor("#88BF4D").should("have.length", 1);
H.echartsContainer().findByText("20");
H.saveQuestion("55880");
// Change filter value so values include numbers that can be parsed as valid dates
cy.findByPlaceholderText("Param").clear().type("1500");
H.runNativeQuery();
// Still renders a scatter chart with numeric x-axis
H.echartsContainer().findByText("1,500");
H.chartPathWithFillColor("#88BF4D").should("have.length", 4);
});
});
// Hack that is needed because of the flakiness caused by adding throttle to the ExplicitSize component.
// Switching to the tabular view and back forces the scatter chart to re-render against an
// already-measured container, so its bubbles stop shifting under a hover before the tooltip fires.
// See: https://github.com/metabase/metabase/pull/15235
function stabilizeScatterChart() {
cy.findByTestId("view-footer").within(() => {
cy.findByLabelText("Switch to data").click(); // Switch to the tabular view...
cy.findByLabelText("Switch to visualization").click(); // ... and then back to the scatter visualization (that now seems to be stable enough to make assertions about)
});
}
function triggerPopoverForBubble(index = 13, force = false) {
stabilizeScatterChart();
// eslint-disable-next-line metabase/no-unsafe-element-filtering
H.cartesianChartCircle()
.eq(index) // Random bubble
.trigger("mousemove", { force });
}