Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(waffle): remove alpha artifacts #2139

Merged
merged 3 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions e2e/tests/waffle_stories.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
markov00 marked this conversation as resolved.
Show resolved Hide resolved
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();
Expand Down
5 changes: 4 additions & 1 deletion storybook/stories/waffle/2_test.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 (
<Chart title={title} description={description} className="story-chart">
<Settings
Expand Down Expand Up @@ -45,7 +47,8 @@ export const Example: ChartsStory = (_, { title, description }) => {
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),
},
},
]}
Expand Down