diff --git a/e2e/screenshots/all.test.ts-snapshots/baselines/waffle-alpha/simple-chrome-linux.png b/e2e/screenshots/all.test.ts-snapshots/baselines/waffle-alpha/simple-chrome-linux.png index 914c223356..27da5970db 100644 Binary files a/e2e/screenshots/all.test.ts-snapshots/baselines/waffle-alpha/simple-chrome-linux.png and b/e2e/screenshots/all.test.ts-snapshots/baselines/waffle-alpha/simple-chrome-linux.png differ diff --git a/e2e/screenshots/all.test.ts-snapshots/baselines/waffle-alpha/test-chrome-linux.png b/e2e/screenshots/all.test.ts-snapshots/baselines/waffle-alpha/test-chrome-linux.png index 0ef71ff879..9afa814cab 100644 Binary files a/e2e/screenshots/all.test.ts-snapshots/baselines/waffle-alpha/test-chrome-linux.png and b/e2e/screenshots/all.test.ts-snapshots/baselines/waffle-alpha/test-chrome-linux.png differ diff --git a/e2e/screenshots/waffle_stories.test.ts-snapshots/waffle/no-stroke-artifacts-when-using-semi-transparent-colors-chrome-linux.png b/e2e/screenshots/waffle_stories.test.ts-snapshots/waffle/no-stroke-artifacts-when-using-semi-transparent-colors-chrome-linux.png new file mode 100644 index 0000000000..519cfb5c19 Binary files /dev/null and b/e2e/screenshots/waffle_stories.test.ts-snapshots/waffle/no-stroke-artifacts-when-using-semi-transparent-colors-chrome-linux.png differ diff --git a/e2e/screenshots/waffle_stories.test.ts-snapshots/waffle/should-render-cells-in-ascending-order-chrome-linux.png b/e2e/screenshots/waffle_stories.test.ts-snapshots/waffle/should-render-cells-in-ascending-order-chrome-linux.png index 17f96f75df..b8b592dcee 100644 Binary files a/e2e/screenshots/waffle_stories.test.ts-snapshots/waffle/should-render-cells-in-ascending-order-chrome-linux.png and b/e2e/screenshots/waffle_stories.test.ts-snapshots/waffle/should-render-cells-in-ascending-order-chrome-linux.png differ diff --git a/e2e/tests/waffle_stories.test.ts b/e2e/tests/waffle_stories.test.ts index d9e81d26f3..e873ccc5ac 100644 --- a/e2e/tests/waffle_stories.test.ts +++ b/e2e/tests/waffle_stories.test.ts @@ -16,4 +16,9 @@ test.describe('Waffle', () => { 'http://localhost:9001/?path=/story/waffle-alpha--simple&globals=theme:light&knob-show table for debugging=&knob-ascending sort=true', ); }); + test('no stroke artifacts when using semi-transparent colors', async ({ page }) => { + await common.expectChartAtUrlToMatchScreenshot(page)( + 'http://localhost:9001/?path=/story/waffle-alpha--test&globals=toggles.showHeader:true;toggles.showChartTitle:false;toggles.showChartDescription:false;theme:light&knob-use alpha=true', + ); + }); }); diff --git a/packages/charts/src/chart_types/partition_chart/renderer/canvas/canvas_wrapped_renderers.ts b/packages/charts/src/chart_types/partition_chart/renderer/canvas/canvas_wrapped_renderers.ts index 6553135c2c..c5583bd8fc 100644 --- a/packages/charts/src/chart_types/partition_chart/renderer/canvas/canvas_wrapped_renderers.ts +++ b/packages/charts/src/chart_types/partition_chart/renderer/canvas/canvas_wrapped_renderers.ts @@ -41,23 +41,22 @@ export function renderWrappedPartitionCanvas2d( const fWidth = x1 - x0; const fPadding = Math.min(padding, MAX_PADDING_RATIO * fWidth); - const paintedWidth = fWidth - fPadding; - const paintedHeight = y1 - y0 - padding; - const cornerRadius = 2 * cornerRatio * Math.min(paintedWidth, paintedHeight); - const halfRadius = cornerRadius / 2; + const w = fWidth - fPadding; + const h = y1 - y0 - padding; + const x = x0 + fPadding; + const y = y0 + padding / 2; + const r = cornerRatio * Math.min(w, h); ctx.fillStyle = fillColor; - ctx.strokeStyle = fillColor; - ctx.lineWidth = cornerRadius; + ctx.beginPath(); - ctx.rect( - x0 + fPadding + halfRadius, - y0 + padding / 2 + halfRadius, - paintedWidth - cornerRadius, - paintedHeight - cornerRadius, - ); + ctx.moveTo(x + r, y); + ctx.arcTo(x + w, y, x + w, y + h, r); + ctx.arcTo(x + w, y + h, x, y + h, r); + ctx.arcTo(x, y + h, x, y, r); + ctx.arcTo(x, y, x + w, y, r); + ctx.closePath(); ctx.fill(); - ctx.stroke(); }); ctx.restore(); diff --git a/storybook/stories/waffle/2_test.story.tsx b/storybook/stories/waffle/2_test.story.tsx index f952204f10..9d58a3d9ad 100644 --- a/storybook/stories/waffle/2_test.story.tsx +++ b/storybook/stories/waffle/2_test.story.tsx @@ -6,6 +6,7 @@ * Side Public License, v 1. */ +import { boolean } from '@storybook/addon-knobs'; import React from 'react'; import { Chart, Datum, Partition, PartitionLayout, Settings } from '@elastic/charts'; @@ -15,6 +16,7 @@ import { useBaseTheme } from '../../use_base_theme'; import { colorBrewerCategoricalStark9, discreteColor, productPriceLookup } from '../utils/utils'; export const Example: ChartsStory = (_, { title, description }) => { + const useOpaqueColor = boolean('use alpha', false); return ( { groupByRollup: (d: Datum) => d.products_price, nodeLabel: (d: Datum) => productPriceLookup[d].name, shape: { - fillColor: (nodeKey, sortIndex) => discreteColor(colorBrewerCategoricalStark9.slice(1))(sortIndex), + fillColor: (nodeKey, sortIndex) => + discreteColor(colorBrewerCategoricalStark9.slice(1), useOpaqueColor ? 0.5 : 1)(sortIndex), }, }, ]}