(
targetEl: Element,
labelStatesModels: LabelStatesModels<LabelModel>,
opt?: SetLabelStyleOpt<TLabelDataIndex>,
stateSpecified?: Partial<Record<DisplayState, TextStyleProps>>
// TODO specified position?
)
| 210 | stateSpecified?: Partial<Record<DisplayState, TextStyleProps>> |
| 211 | ): void; |
| 212 | function setLabelStyle<TLabelDataIndex>( |
| 213 | targetEl: Element, |
| 214 | labelStatesModels: LabelStatesModels<LabelModel>, |
| 215 | opt?: SetLabelStyleOpt<TLabelDataIndex>, |
| 216 | stateSpecified?: Partial<Record<DisplayState, TextStyleProps>> |
| 217 | // TODO specified position? |
| 218 | ) { |
| 219 | opt = opt || EMPTY_OBJ; |
| 220 | const isSetOnText = targetEl instanceof ZRText; |
| 221 | let needsCreateText = false; |
| 222 | for (let i = 0; i < DISPLAY_STATES.length; i++) { |
| 223 | const stateModel = labelStatesModels[DISPLAY_STATES[i]]; |
| 224 | if (stateModel && stateModel.getShallow('show')) { |
| 225 | needsCreateText = true; |
| 226 | break; |
| 227 | } |
| 228 | } |
| 229 | let textContent = isSetOnText ? targetEl as ZRText : targetEl.getTextContent(); |
| 230 | if (needsCreateText) { |
| 231 | if (!isSetOnText) { |
| 232 | // Reuse the previous |
| 233 | if (!textContent) { |
| 234 | textContent = new ZRText(); |
| 235 | targetEl.setTextContent(textContent); |
| 236 | } |
| 237 | // Use same state proxy |
| 238 | if (targetEl.stateProxy) { |
| 239 | textContent.stateProxy = targetEl.stateProxy; |
| 240 | } |
| 241 | } |
| 242 | const labelStatesTexts = getLabelText(opt, labelStatesModels); |
| 243 | |
| 244 | const normalModel = labelStatesModels.normal; |
| 245 | const showNormal = !!normalModel.getShallow('show'); |
| 246 | const normalStyle = createTextStyle( |
| 247 | normalModel, stateSpecified && stateSpecified.normal, opt, false, !isSetOnText |
| 248 | ); |
| 249 | normalStyle.text = labelStatesTexts.normal; |
| 250 | if (!isSetOnText) { |
| 251 | // Always create new |
| 252 | targetEl.setTextConfig(createTextConfig(normalModel, opt, false)); |
| 253 | } |
| 254 | |
| 255 | for (let i = 0; i < SPECIAL_STATES.length; i++) { |
| 256 | const stateName = SPECIAL_STATES[i]; |
| 257 | const stateModel = labelStatesModels[stateName]; |
| 258 | |
| 259 | if (stateModel) { |
| 260 | const stateObj = textContent.ensureState(stateName); |
| 261 | const stateShow = !!retrieve2(stateModel.getShallow('show'), showNormal); |
| 262 | if (stateShow !== showNormal) { |
| 263 | stateObj.ignore = !stateShow; |
| 264 | } |
| 265 | stateObj.style = createTextStyle( |
| 266 | stateModel, stateSpecified && stateSpecified[stateName], opt, true, !isSetOnText |
| 267 | ); |
| 268 | stateObj.style.text = labelStatesTexts[stateName]; |
| 269 |
no test coverage detected
searching dependent graphs…