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(visualMap): handle label collides with horizontal size visualMap #20249

Merged
merged 4 commits into from
Oct 17, 2024
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
14 changes: 13 additions & 1 deletion src/component/visualMap/ContinuousView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import GlobalModel from '../../model/Global';
import ExtensionAPI from '../../core/ExtensionAPI';
import Element, { ElementEvent } from 'zrender/src/Element';
import { TextVerticalAlign, TextAlign } from 'zrender/src/core/types';
import { ColorString, Payload } from '../../util/types';
import { ColorString, Payload, VerticalAlign } from '../../util/types';
import { parsePercent } from 'zrender/src/contain/text';
import { setAsHighDownDispatcher } from '../../util/states';
import { createSymbol } from '../../util/symbol';
Expand Down Expand Up @@ -601,6 +601,7 @@ class ContinuousView extends VisualMapView {
const handleLabels = shapes.handleLabels;
const itemSize = visualMapModel.itemSize;
const dataExtent = visualMapModel.getExtent();
const align = this._applyTransform('left', shapes.mainGroup);

each([0, 1], function (handleIndex) {
const handleThumb = handleThumbs[handleIndex];
Expand All @@ -618,6 +619,17 @@ class ContinuousView extends VisualMapView {
shapes.handleLabelPoints[handleIndex],
graphic.getTransform(handleThumb, this.group)
);

if (this._orient === 'horizontal') {
// If visualMap controls symbol size, an additional offset needs to be added to labels to avoid collision at minimum size.
// Offset reaches value of 0 at "maximum" position, so maximum position is not altered at all.
const minimumOffset = align === 'left' || align === 'top'
? (itemSize[0] - symbolSize) / 2
: (itemSize[0] - symbolSize) / -2;

textPoint[1] += minimumOffset;
}

handleLabels[handleIndex].setStyle({
x: textPoint[0],
y: textPoint[1],
Expand Down
Loading
Loading