-
Notifications
You must be signed in to change notification settings - Fork 19.7k
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
Changed calculated label gap to be passed from top #16825
Changes from all commits
0d220d8
ea4d9c7
45140f4
195afde
3c5406e
9af5af9
e0cd1c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,9 @@ import {createTextStyle} from '../../label/labelStyle'; | |
import Model from '../../model/Model'; | ||
import {isRadianAroundZero, remRadian} from '../../util/number'; | ||
import {createSymbol, normalizeSymbolOffset} from '../../util/symbol'; | ||
import { estimateLabelUnionRect, shouldShowAllLabels } from '../../coord/axisHelper'; | ||
import * as matrixUtil from 'zrender/src/core/matrix'; | ||
import {applyTransform as v2ApplyTransform} from 'zrender/src/core/vector'; | ||
import {shouldShowAllLabels} from '../../coord/axisHelper'; | ||
import { AxisBaseModel } from '../../coord/AxisBaseModel'; | ||
import { ZRTextVerticalAlign, ZRTextAlign, ECElement, ColorString } from '../../util/types'; | ||
import { AxisBaseOption } from '../../coord/axisCommonTypes'; | ||
|
@@ -234,7 +234,8 @@ interface AxisElementsBuilder { | |
opt: AxisBuilderCfg, | ||
axisModel: AxisBaseModel, | ||
group: graphic.Group, | ||
transformGroup: graphic.Group | ||
transformGroup: graphic.Group, | ||
labelGap?: number | ||
):void | ||
} | ||
|
||
|
@@ -365,29 +366,47 @@ const builders: Record<'axisLine' | 'axisTickLabel' | 'axisName', AxisElementsBu | |
}, | ||
|
||
axisName(opt, axisModel, group, transformGroup) { | ||
function calcDistanceToAxis() { | ||
const defaultMargin = 10; | ||
const axis = axisModel.axis; | ||
const isHorizontal = axis.isHorizontal(); | ||
const labelUnionRect = estimateLabelUnionRect(axis); | ||
if (!labelUnionRect) { | ||
return 0; | ||
} | ||
const dim = isHorizontal ? 'height' : 'width'; | ||
const margin = axisModel.getModel('axisLabel').get('margin'); | ||
return labelUnionRect[dim] + margin + defaultMargin; | ||
} | ||
const name = retrieve(opt.axisName, axisModel.get('name')); | ||
|
||
if (!name) { | ||
return; | ||
} | ||
|
||
const isOutside = name === 'outsideStart' || name === 'outsideMiddle' || name === 'outsideEnd'; | ||
const labelGap = isOutside ? calcDistanceToAxis() : 0; | ||
const nameLocation = axisModel.get('nameLocation'); | ||
const nameDirection = opt.nameDirection; | ||
const textStyleModel = axisModel.getModel('nameTextStyle'); | ||
const gap = axisModel.get('nameGap') || 0; | ||
|
||
const gap = (axisModel.get('nameGap') || 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const nameGap = axisModel.get('nameGap') || 0;
const gap = isOutside ? calcDistanceToAxis(nameGap) : nameGap; And |
||
const extent = axisModel.axis.getExtent(); | ||
const gapSignal = extent[0] > extent[1] ? -1 : 1; | ||
|
||
const pos = [ | ||
nameLocation === 'start' | ||
? extent[0] - gapSignal * gap | ||
: nameLocation === 'outsideStart' | ||
? extent[0] + gapSignal * (gap) + (nameDirection * labelGap) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
: nameLocation === 'end' | ||
? extent[1] + gapSignal * gap | ||
: (extent[0] + extent[1]) / 2, // 'middle' | ||
: nameLocation === 'outsideEnd' | ||
? extent[1] - gapSignal * (gap) - (nameDirection * labelGap) | ||
: (extent[0] + extent[1]) / 2, // 'middle' or 'outsideMiddle' | ||
// Reuse labelOffset. | ||
isNameLocationCenter(nameLocation) ? opt.labelOffset + nameDirection * gap : 0 | ||
isNameLocationCenter(nameLocation) | ||
? opt.labelOffset + nameDirection * (gap + (isNameLocationOutside(nameLocation) ? labelGap : 0)) | ||
: isNameLocationOutside(nameLocation) ? nameDirection * (gap + labelGap) : 0 | ||
]; | ||
|
||
let labelLayout; | ||
|
||
let nameRotation = axisModel.get('nameRotate'); | ||
|
@@ -475,15 +494,16 @@ const builders: Record<'axisLine' | 'axisTickLabel' | 'axisName', AxisElementsBu | |
|
||
}; | ||
|
||
function endTextLayout( | ||
rotation: number, textPosition: 'start' | 'middle' | 'end', textRotate: number, extent: number[] | ||
) { | ||
function endTextLayout(rotation: number, | ||
textPosition: 'start' | 'middle' | 'end' | 'outsideStart' | 'outsideMiddle' | 'outsideEnd', | ||
textRotate: number, extent: number[]) { | ||
const rotationDiff = remRadian(textRotate - rotation); | ||
let textAlign: ZRTextAlign; | ||
let textVerticalAlign: ZRTextVerticalAlign; | ||
const inverse = extent[0] > extent[1]; | ||
const onLeft = (textPosition === 'start' && !inverse) | ||
|| (textPosition !== 'start' && inverse); | ||
const textIsStart = textPosition === 'start' || textPosition === 'outsideStart'; | ||
const onLeft = ((textIsStart) && !inverse) | ||
|| (!textIsStart && inverse); | ||
|
||
if (isRadianAroundZero(rotationDiff - PI / 2)) { | ||
textVerticalAlign = onLeft ? 'bottom' : 'top'; | ||
|
@@ -600,9 +620,12 @@ function isTwoLabelOverlapped( | |
} | ||
|
||
function isNameLocationCenter(nameLocation: string) { | ||
return nameLocation === 'middle' || nameLocation === 'center'; | ||
return nameLocation === 'middle' || nameLocation === 'center' || nameLocation === 'outsideMiddle'; | ||
} | ||
|
||
function isNameLocationOutside(nameLocation: string) { | ||
return nameLocation === 'outsideStart' || nameLocation === 'outsideMiddle' || nameLocation === 'outsideEnd'; | ||
} | ||
|
||
function createTicks( | ||
ticksCoords: TickCoord[], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ export interface AxisBaseOptionCommon extends ComponentOption, | |
inverse?: boolean; | ||
// Axis name displayed. | ||
name?: string; | ||
nameLocation?: 'start' | 'middle' | 'end'; | ||
nameLocation?: 'start' | 'middle' | 'end' | 'outsideStart' | 'outsideMiddle' | 'outsideEnd'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this a new type and export it so that it can be used in |
||
// By degree. | ||
nameRotate?: number; | ||
nameTruncate?: { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably use xAxis.nameGap instead. The document can be updated so that when the
nameLocation
isoutsideXXX
, it means the distance between the axis name and the axis labels.