diff --git a/frontend/src/metabase/visualizations/lib/LineAreaBarRenderer.js b/frontend/src/metabase/visualizations/lib/LineAreaBarRenderer.js index 893d5f7fdc551c338985ba6907c1f45f00be141c..b8b1657613928e0880d8d26356e9a6c14d308af0 100644 --- a/frontend/src/metabase/visualizations/lib/LineAreaBarRenderer.js +++ b/frontend/src/metabase/visualizations/lib/LineAreaBarRenderer.js @@ -684,41 +684,47 @@ function addTrendlineChart( const insights = rawSeries[0].data.insights || []; for (const insight of insights) { - if (insight.slope != null && insight.offset != null) { - const index = findSeriesIndexForColumnName(series, insight.col); - const seriesSettings = settings.series(series[index]); - const color = lighten(seriesSettings.color, 0.25); - - const points = Math.round(parent.width() / TREND_LINE_POINT_SPACING); - const trendData = getTrendDataPointsFromInsight(insight, xDomain, points); - const trendDimension = crossfilter(trendData).dimension(d => d[0]); - - // Take the last point rather than summing in case xDomain[0] === xDomain[1], e.x. when the chart - // has just a single row / datapoint - const trendGroup = trendDimension.group().reduce( - (p, d) => d[1], - (p, d) => p, - () => 0, - ); - const trendIndex = charts.length; - - const trendChart = dc - .lineChart(parent) - .dimension(trendDimension) - .group(trendGroup) - .on("renderlet", function(chart) { - // remove "sub" class so the trend is not used in voronoi computation - chart - .select(".sub._" + trendIndex) - .classed("sub", false) - .classed("trend", true); - }) - .colors([color]) - .useRightYAxis(yAxisSplit.length > 1 && yAxisSplit[1].includes(index)) - .interpolate("cardinal"); - - charts.push(trendChart); + const index = findSeriesIndexForColumnName(series, insight.col); + + const shouldShowSeries = index !== -1; + const hasTrendLineData = insight.slope != null && insight.offset != null; + + if (!shouldShowSeries || !hasTrendLineData) { + continue; } + + const seriesSettings = settings.series(series[index]); + const color = lighten(seriesSettings.color, 0.25); + + const points = Math.round(parent.width() / TREND_LINE_POINT_SPACING); + const trendData = getTrendDataPointsFromInsight(insight, xDomain, points); + const trendDimension = crossfilter(trendData).dimension(d => d[0]); + + // Take the last point rather than summing in case xDomain[0] === xDomain[1], e.x. when the chart + // has just a single row / datapoint + const trendGroup = trendDimension.group().reduce( + (p, d) => d[1], + (p, d) => p, + () => 0, + ); + const trendIndex = charts.length; + + const trendChart = dc + .lineChart(parent) + .dimension(trendDimension) + .group(trendGroup) + .on("renderlet", function(chart) { + // remove "sub" class so the trend is not used in voronoi computation + chart + .select(".sub._" + trendIndex) + .classed("sub", false) + .classed("trend", true); + }) + .colors([color]) + .useRightYAxis(yAxisSplit.length > 1 && yAxisSplit[1].includes(index)) + .interpolate("cardinal"); + + charts.push(trendChart); } } diff --git a/frontend/test/metabase/scenarios/visualizations/trendline.cy.spec.js b/frontend/test/metabase/scenarios/visualizations/trendline.cy.spec.js index 228e2f6207bf36777172b8d8db4765e1f686ca5d..462b40ac5bd0bd3cd3541cb95d10450cb9dc6797 100644 --- a/frontend/test/metabase/scenarios/visualizations/trendline.cy.spec.js +++ b/frontend/test/metabase/scenarios/visualizations/trendline.cy.spec.js @@ -11,7 +11,7 @@ describe("scenarios > question > trendline", () => { cy.signInAsNormalUser(); }); - it.skip("displays trendline when there are multiple numeric outputs (for simple question) (metabase#12781)", () => { + it("displays trendline when there are multiple numeric outputs (for simple question) (metabase#12781)", () => { // Create question: orders summarized with "Average of Subtotal" and "Sum of Total" by CreatedAt:Year openOrdersTable(); cy.icon("notebook").click();