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] Text labels: can't set prop to false/0 with multiple labels #2354

Merged
merged 4 commits into from
Oct 3, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/constants/src/default-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,11 @@ export const MAP_CONTROLS = keyMirror({
*/
export const PROJECTED_PIXEL_SIZE_MULTIPLIER = 2 / 3;

/**
* Maximum value for text outline width
*/
export const TEXT_OUTLINE_MULTIPLIER = 5;

export const dataTestIds: Record<string, string> = {
infoIcon: 'info-icon',
warningIcon: 'warning-icon',
Expand Down
5 changes: 3 additions & 2 deletions src/layers/src/base-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ import {
UNKNOWN_COLOR_KEY,
DEFAULT_HIGHLIGHT_COLOR,
DEFAULT_LAYER_LABEL,
PROJECTED_PIXEL_SIZE_MULTIPLIER
PROJECTED_PIXEL_SIZE_MULTIPLIER,
TEXT_OUTLINE_MULTIPLIER
} from '@kepler.gl/constants';

import {
Expand Down Expand Up @@ -1370,7 +1371,7 @@ class Layer {
getTextAnchor: textLabel[i].anchor,
getAlignmentBaseline: textLabel[i].alignment,
getColor: textLabel[i].color,
outlineWidth: textLabel[i].outlineWidth,
outlineWidth: textLabel[i].outlineWidth * TEXT_OUTLINE_MULTIPLIER,
outlineColor: textLabel[i].outlineColor,
background,
getBackgroundColor: textLabel[i].backgroundColor,
Expand Down
6 changes: 3 additions & 3 deletions src/reducers/src/vis-state-updaters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,11 +575,11 @@ function updateTextLabelPropAndValue(idx, prop, value, textLabel) {

let newTextLabel = textLabel.slice();

if (prop && (value || textLabel.length === 1)) {
newTextLabel = textLabel.map((tl, i) => (i === idx ? {...tl, [prop]: value} : tl));
} else if (prop === 'field' && value === null && textLabel.length > 1) {
if (prop === 'field' && value === null && textLabel.length > 1) {
// remove label when field value is set to null
newTextLabel.splice(idx, 1);
} else if (prop) {
newTextLabel = textLabel.map((tl, i) => (i === idx ? {...tl, [prop]: value} : tl));
}

return newTextLabel;
Expand Down