* See more info in `setTextStyleCommon`. * @param {Object|module:zrender/graphic/Style} normalStyle * @param {Object} emphasisStyle * @param {module:echarts/model/Model} normalModel * @param {module:echarts/model/Model} emphasisModel * @param {Object} opt Check `opt` of `setTextStyleCommon` to
(
normalStyle, emphasisStyle,
normalModel, emphasisModel,
opt,
normalSpecified, emphasisSpecified
)
| 17473 | * @param {Object} [emphasisSpecified] |
| 17474 | */ |
| 17475 | function setLabelStyle( |
| 17476 | normalStyle, emphasisStyle, |
| 17477 | normalModel, emphasisModel, |
| 17478 | opt, |
| 17479 | normalSpecified, emphasisSpecified |
| 17480 | ) { |
| 17481 | opt = opt || EMPTY_OBJ; |
| 17482 | var labelFetcher = opt.labelFetcher; |
| 17483 | var labelDataIndex = opt.labelDataIndex; |
| 17484 | var labelDimIndex = opt.labelDimIndex; |
| 17485 | var labelProp = opt.labelProp; |
| 17486 | |
| 17487 | // This scenario, `label.normal.show = true; label.emphasis.show = false`, |
| 17488 | // is not supported util someone requests. |
| 17489 | |
| 17490 | var showNormal = normalModel.getShallow('show'); |
| 17491 | var showEmphasis = emphasisModel.getShallow('show'); |
| 17492 | |
| 17493 | // Consider performance, only fetch label when necessary. |
| 17494 | // If `normal.show` is `false` and `emphasis.show` is `true` and `emphasis.formatter` is not set, |
| 17495 | // label should be displayed, where text is fetched by `normal.formatter` or `opt.defaultText`. |
| 17496 | var baseText; |
| 17497 | if (showNormal || showEmphasis) { |
| 17498 | if (labelFetcher) { |
| 17499 | baseText = labelFetcher.getFormattedLabel(labelDataIndex, 'normal', null, labelDimIndex, labelProp); |
| 17500 | } |
| 17501 | if (baseText == null) { |
| 17502 | baseText = isFunction$1(opt.defaultText) ? opt.defaultText(labelDataIndex, opt) : opt.defaultText; |
| 17503 | } |
| 17504 | } |
| 17505 | var normalStyleText = showNormal ? baseText : null; |
| 17506 | var emphasisStyleText = showEmphasis |
| 17507 | ? retrieve2( |
| 17508 | labelFetcher |
| 17509 | ? labelFetcher.getFormattedLabel(labelDataIndex, 'emphasis', null, labelDimIndex, labelProp) |
| 17510 | : null, |
| 17511 | baseText |
| 17512 | ) |
| 17513 | : null; |
| 17514 | |
| 17515 | // Optimize: If style.text is null, text will not be drawn. |
| 17516 | if (normalStyleText != null || emphasisStyleText != null) { |
| 17517 | // Always set `textStyle` even if `normalStyle.text` is null, because default |
| 17518 | // values have to be set on `normalStyle`. |
| 17519 | // If we set default values on `emphasisStyle`, consider case: |
| 17520 | // Firstly, `setOption(... label: {normal: {text: null}, emphasis: {show: true}} ...);` |
| 17521 | // Secondly, `setOption(... label: {noraml: {show: true, text: 'abc', color: 'red'} ...);` |
| 17522 | // Then the 'red' will not work on emphasis. |
| 17523 | setTextStyle(normalStyle, normalModel, normalSpecified, opt); |
| 17524 | setTextStyle(emphasisStyle, emphasisModel, emphasisSpecified, opt, true); |
| 17525 | } |
| 17526 | |
| 17527 | normalStyle.text = normalStyleText; |
| 17528 | emphasisStyle.text = emphasisStyleText; |
| 17529 | } |
| 17530 | |
| 17531 | /** |
| 17532 | * Modify label style manually. |
no test coverage detected