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(value_labels): zero as valid value for textBorder and borderWidth #1182

Merged
merged 3 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion api/charts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ export type DisplayValueStyle = Omit<TextStyle, 'fill' | 'fontSize'> & {
} | {
textInvertible: boolean;
textContrast?: number | boolean;
textBorder?: number | boolean;
textBorder?: number;
};
alignment?: {
horizontal: Exclude<HorizontalAlignment, 'far' | 'near'>;
Expand Down
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.
33 changes: 33 additions & 0 deletions integration/tests/styles.test.ts
Original file line number Diff line number Diff line change
@@ -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',
);
});
});
9 changes: 5 additions & 4 deletions src/chart_types/xy_chart/renderer/canvas/primitives/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ 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.save();
markov00 marked this conversation as resolved.
Show resolved Hide resolved
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.restore();
}
ctx.fillText(text, 0, 0);
});
Expand Down
2 changes: 1 addition & 1 deletion src/chart_types/xy_chart/renderer/canvas/values/bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/themes/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export type DisplayValueStyle = Omit<TextStyle, 'fill' | 'fontSize'> & {
| {
textInvertible: boolean;
textContrast?: number | boolean;
textBorder?: number | boolean;
textBorder?: number;
};
alignment?: {
horizontal: Exclude<HorizontalAlignment, 'far' | 'near'>;
Expand Down