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

feat(label): support align for min/max labels #19228

Merged
merged 2 commits into from
Dec 26, 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
38 changes: 32 additions & 6 deletions src/component/axis/AxisBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
* under the License.
*/

import {retrieve, defaults, extend, each, isObject, map, isString, isNumber, isFunction} from 'zrender/src/core/util';
import {
retrieve, defaults, extend, each, isObject, map, isString, isNumber, isFunction, retrieve2
} from 'zrender/src/core/util';
import * as graphic from '../../util/graphic';
import {getECData} from '../../util/innerStore';
import {createTextStyle} from '../../label/labelStyle';
Expand Down Expand Up @@ -776,6 +778,29 @@ function buildAxisLabel(

const tickCoord = axis.dataToCoord(tickValue);

const align = itemLabelModel.getShallow('align', true)
|| labelLayout.textAlign;
const alignMin = retrieve2(
itemLabelModel.getShallow('alignMinLabel', true),
align
);
const alignMax = retrieve2(
itemLabelModel.getShallow('alignMaxLabel', true),
align
);

const verticalAlign = itemLabelModel.getShallow('verticalAlign', true)
|| itemLabelModel.getShallow('baseline', true)
|| labelLayout.textVerticalAlign;
const verticalAlignMin = retrieve2(
itemLabelModel.getShallow('verticalAlignMinLabel', true),
verticalAlign
);
const verticalAlignMax = retrieve2(
itemLabelModel.getShallow('verticalAlignMaxLabel', true),
verticalAlign
);

const textEl = new graphic.Text({
x: tickCoord,
y: opt.labelOffset + opt.labelDirection * labelMargin,
Expand All @@ -784,11 +809,12 @@ function buildAxisLabel(
z2: 10 + (labelItem.level || 0),
style: createTextStyle(itemLabelModel, {
text: formattedLabel,
align: itemLabelModel.getShallow('align', true)
|| labelLayout.textAlign,
verticalAlign: itemLabelModel.getShallow('verticalAlign', true)
|| itemLabelModel.getShallow('baseline', true)
|| labelLayout.textVerticalAlign,
align: index === 0
? alignMin
: index === labels.length - 1 ? alignMax : align,
verticalAlign: index === 0
? verticalAlignMin
: index === labels.length - 1 ? verticalAlignMax : verticalAlign,
fill: isFunction(textColor)
? textColor(
// (1) In category axis with data zoom, tick is not the original
Expand Down
9 changes: 9 additions & 0 deletions src/coord/axisCommonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import { TextAlign, TextVerticalAlign } from 'zrender/src/core/types';
import {
TextCommonOption, LineStyleOption, OrdinalRawValue, ZRColor,
AreaStyleOption, ComponentOption, ColorString,
Expand Down Expand Up @@ -223,6 +224,14 @@ interface AxisLabelBaseOption extends Omit<TextCommonOption, 'color'> {
showMinLabel?: boolean,
// true | false | null/undefined (auto)
showMaxLabel?: boolean,
// 'left' | 'center' | 'right' | null/undefined (auto)
alignMinLabel?: TextAlign,
// 'left' | 'center' | 'right' | null/undefined (auto)
alignMaxLabel?: TextAlign,
// 'top' | 'middle' | 'bottom' | null/undefined (auto)
verticalAlignMinLabel?: TextVerticalAlign,
// 'top' | 'middle' | 'bottom' | null/undefined (auto)
verticalAlignMaxLabel?: TextVerticalAlign,
margin?: number,
rich?: Dictionary<TextCommonOption>
/**
Expand Down
150 changes: 150 additions & 0 deletions test/axis-align-lastLabel.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.