diff --git a/api/charts.api.md b/api/charts.api.md index b5e2b3c648..ea6014ba78 100644 --- a/api/charts.api.md +++ b/api/charts.api.md @@ -666,7 +666,7 @@ export type DisplayValueStyle = Omit & { } | { textInvertible: boolean; textContrast?: number | boolean; - textBorder?: number | boolean; + textBorder?: number; }; alignment?: { horizontal: Exclude; diff --git a/integration/tests/__image_snapshots__/styles-test-ts-styles-should-hide-the-value-label-with-0-border-width-1-snap.png b/integration/tests/__image_snapshots__/styles-test-ts-styles-should-hide-the-value-label-with-0-border-width-1-snap.png new file mode 100644 index 0000000000..e2ac14c406 Binary files /dev/null and b/integration/tests/__image_snapshots__/styles-test-ts-styles-should-hide-the-value-label-with-0-border-width-1-snap.png differ diff --git a/integration/tests/__image_snapshots__/styles-test-ts-styles-should-hide-the-value-label-with-0-text-border-1-snap.png b/integration/tests/__image_snapshots__/styles-test-ts-styles-should-hide-the-value-label-with-0-text-border-1-snap.png new file mode 100644 index 0000000000..068597f191 Binary files /dev/null and b/integration/tests/__image_snapshots__/styles-test-ts-styles-should-hide-the-value-label-with-0-text-border-1-snap.png differ diff --git a/integration/tests/styles.test.ts b/integration/tests/styles.test.ts new file mode 100644 index 0000000000..93bda72805 --- /dev/null +++ b/integration/tests/styles.test.ts @@ -0,0 +1,33 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { common } from '../page_objects/common'; + +describe('Styles', () => { + it('should hide the value label with 0 borderWidth', async () => { + await common.expectChartAtUrlToMatchScreenshot( + 'http://localhost:9001/?path=/story/bar-chart--with-value-label-advanced&knob-show value label=true&knob-alternating value label=&knob-contain value label within bar element=&knob-hide clipped value=&knob-debug=&knob-textInverted=&knob-value color=rgba(0,0,0,1)&knob-value border color=rgba(0,0,0,1)&knob-value border width=0&knob-Fixed font size=10&knob-Use fixed font size=&knob-Max font size=25&knob-Min font size=10&knob-offsetX=0&knob-offsetY=0&knob-data volume size=s&knob-split series=&knob-stacked series=&knob-chartRotation=0', + ); + }); + it('should hide the value label with 0 textBorder', async () => { + await common.expectChartAtUrlToMatchScreenshot( + 'http://localhost:9001/?path=/story/bar-chart--with-value-label-advanced&knob-show value label=true&knob-alternating value label=&knob-contain value label within bar element=&knob-hide clipped value=&knob-debug=&knob-textInverted=true&knob-value color=rgba(0,0,0,1)&knob-value border color=rgba(0,0,0,1)&knob-value border width=0&knob-Fixed font size=10&knob-Use fixed font size=&knob-Max font size=25&knob-Min font size=10&knob-offsetX=0&knob-offsetY=0&knob-data volume size=s&knob-split series=&knob-stacked series=&knob-chartRotation=0', + ); + }); +}); diff --git a/src/chart_types/xy_chart/renderer/canvas/primitives/text.ts b/src/chart_types/xy_chart/renderer/canvas/primitives/text.ts index f5994dc2c0..475aea1cc1 100644 --- a/src/chart_types/xy_chart/renderer/canvas/primitives/text.ts +++ b/src/chart_types/xy_chart/renderer/canvas/primitives/text.ts @@ -56,13 +56,12 @@ export function renderText( } ctx.translate(origin.x, origin.y); ctx.scale(scale, scale); - if (font.shadow) { + const shadowSize = font.shadowSize ?? 0; + if (font.shadow && shadowSize > 0) { ctx.lineJoin = 'round'; - const prevLineWidth = ctx.lineWidth; - ctx.lineWidth = font.shadowSize || 1.5; + ctx.lineWidth = shadowSize; ctx.strokeStyle = font.shadow; ctx.strokeText(text, 0, 0); - ctx.lineWidth = prevLineWidth; } ctx.fillText(text, 0, 0); }); diff --git a/src/chart_types/xy_chart/renderer/canvas/values/bar.ts b/src/chart_types/xy_chart/renderer/canvas/values/bar.ts index 47cb84ae2b..de79df4cdd 100644 --- a/src/chart_types/xy_chart/renderer/canvas/values/bar.ts +++ b/src/chart_types/xy_chart/renderer/canvas/values/bar.ts @@ -414,7 +414,7 @@ function getTextBorderSize(fill: ValueFillDefinition): number { return DEFAULT_BORDER_WIDTH; } if ('borderWidth' in fill) { - return Math.min(fill.borderWidth || DEFAULT_BORDER_WIDTH, MAX_BORDER_WIDTH); + return Math.min(fill.borderWidth ?? DEFAULT_BORDER_WIDTH, MAX_BORDER_WIDTH); } const borderWidth = 'textBorder' in fill && typeof fill.textBorder === 'number' ? fill.textBorder : DEFAULT_BORDER_WIDTH; diff --git a/src/utils/themes/theme.ts b/src/utils/themes/theme.ts index 6ddbb10b2e..7574ec4749 100644 --- a/src/utils/themes/theme.ts +++ b/src/utils/themes/theme.ts @@ -317,7 +317,7 @@ export type DisplayValueStyle = Omit & { | { textInvertible: boolean; textContrast?: number | boolean; - textBorder?: number | boolean; + textBorder?: number; }; alignment?: { horizontal: Exclude;