-
Notifications
You must be signed in to change notification settings - Fork 19.8k
fix(matrix): fix matrix label formatter does not work #21410
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
Changes from 1 commit
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 | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,7 +31,8 @@ import { LineShape } from 'zrender/src/graphic/shape/Line'; | |||||||||||||||||||||||||||||||||||||
| import { subPixelOptimize } from 'zrender/src/graphic/helper/subPixelOptimize'; | ||||||||||||||||||||||||||||||||||||||
| import { Group, Text, Rect, Line, XY, setTooltipConfig, expandOrShrinkRect } from '../../util/graphic'; | ||||||||||||||||||||||||||||||||||||||
| import { clearTmpModel, ListIterator } from '../../util/model'; | ||||||||||||||||||||||||||||||||||||||
| import { clone, retrieve2 } from 'zrender/src/core/util'; | ||||||||||||||||||||||||||||||||||||||
| import { clone, retrieve2, isFunction, isString } from 'zrender/src/core/util'; | ||||||||||||||||||||||||||||||||||||||
| import { formatTplSimple } from '../../util/format'; | ||||||||||||||||||||||||||||||||||||||
| import { invert } from 'zrender/src/core/matrix'; | ||||||||||||||||||||||||||||||||||||||
| import { MatrixBodyCorner, MatrixBodyOrCornerKind } from '../../coord/matrix/MatrixBodyCorner'; | ||||||||||||||||||||||||||||||||||||||
| import { setLabelStyle } from '../../label/labelStyle'; | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -289,12 +290,33 @@ function createMatrixCell( | |||||||||||||||||||||||||||||||||||||
| let cellText: Text | NullUndefined; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (textValue != null) { | ||||||||||||||||||||||||||||||||||||||
| const text = textValue + ''; | ||||||||||||||||||||||||||||||||||||||
| let text = textValue + ''; | ||||||||||||||||||||||||||||||||||||||
| _tmpCellLabelModel.option = cellOption ? cellOption.label : null; | ||||||||||||||||||||||||||||||||||||||
| _tmpCellLabelModel.parentModel = parentLabelModel; | ||||||||||||||||||||||||||||||||||||||
| // This is to accept `option.textStyle` as the default. | ||||||||||||||||||||||||||||||||||||||
| _tmpCellLabelModel.ecModel = ecModel; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const formatter = _tmpCellLabelModel.getShallow('formatter'); | ||||||||||||||||||||||||||||||||||||||
| if (formatter) { | ||||||||||||||||||||||||||||||||||||||
| const params = { | ||||||||||||||||||||||||||||||||||||||
| componentType: 'matrix' as const, | ||||||||||||||||||||||||||||||||||||||
| componentIndex: matrixModel.componentIndex, | ||||||||||||||||||||||||||||||||||||||
| name: text, | ||||||||||||||||||||||||||||||||||||||
| value: textValue as unknown, | ||||||||||||||||||||||||||||||||||||||
| xyLocator: xyLocator.slice() as MatrixXYLocator[], | ||||||||||||||||||||||||||||||||||||||
| $vars: ['name', 'value', 'xyLocator'] as const | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
| if (isFunction(formatter)) { | ||||||||||||||||||||||||||||||||||||||
| const formattedText = formatter(params); | ||||||||||||||||||||||||||||||||||||||
| if (formattedText != null) { | ||||||||||||||||||||||||||||||||||||||
| text = formattedText + ''; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| else if (isString(formatter)) { | ||||||||||||||||||||||||||||||||||||||
| text = formatTplSimple(formatter, params); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| if (isFunction(formatter)) { | |
| const formattedText = formatter(params); | |
| if (formattedText != null) { | |
| text = formattedText + ''; | |
| } | |
| } | |
| else if (isString(formatter)) { | |
| text = formatTplSimple(formatter, params); | |
| } | |
| if (isString(formatter)) { | |
| text = formatTplSimple(formatter, params); | |
| } | |
| else if (isFunction(formatter)) { | |
| const formattedText = formatter(params); | |
| if (formattedText != null) { | |
| text = formattedText + ''; | |
| } | |
| } |
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.
A nice-to-have suggestion. Not a must.
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.
done
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -195,6 +195,19 @@ export interface MatrixDimensionLevelOption { | |||||
| export interface MatrixDimensionModel extends Model<MatrixDimensionOption> { | ||||||
| } | ||||||
|
|
||||||
| export interface MatrixLabelOption extends LabelOption { | ||||||
| formatter?: string | ((params: MatrixLabelFormatterParams) => string); | ||||||
| } | ||||||
|
|
||||||
| export interface MatrixLabelFormatterParams { | ||||||
| componentType: 'matrix'; | ||||||
| componentIndex: number; | ||||||
| name: string; | ||||||
| value: unknown; | ||||||
| xyLocator: MatrixXYLocator[]; | ||||||
| $vars: readonly ['name', 'value', 'xyLocator']; | ||||||
|
||||||
| $vars: readonly ['name', 'value', 'xyLocator']; | |
| $vars: ['name', 'value', 'xyLocator']; |
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.
I see other places using readonly, although not $vars, and it's reasonable to use it here.
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.
I would suggest using
'coord'instead of'xyLocatoer'to align with MatrixBodyCornerCellOption.coord.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.
done