| 243 | } |
| 244 | |
| 245 | class LegendModel<Ops extends LegendOption = LegendOption> extends ComponentModel<Ops> { |
| 246 | static type = 'legend.plain'; |
| 247 | type = LegendModel.type; |
| 248 | |
| 249 | static readonly dependencies = ['series']; |
| 250 | |
| 251 | readonly layoutMode = { |
| 252 | type: 'box', |
| 253 | // legend.width/height are maxWidth/maxHeight actually, |
| 254 | // whereas real width/height is calculated by its content. |
| 255 | // (Setting {left: 10, right: 10} does not make sense). |
| 256 | // So consider the case: |
| 257 | // `setOption({legend: {left: 10});` |
| 258 | // then `setOption({legend: {right: 10});` |
| 259 | // The previous `left` should be cleared by setting `ignoreSize`. |
| 260 | ignoreSize: true |
| 261 | } as const; |
| 262 | |
| 263 | |
| 264 | private _data: Model<DataItem>[]; |
| 265 | private _availableNames: string[]; |
| 266 | |
| 267 | init(option: Ops, parentModel: Model, ecModel: GlobalModel) { |
| 268 | this.mergeDefaultAndTheme(option, ecModel); |
| 269 | |
| 270 | option.selected = option.selected || {}; |
| 271 | this._updateSelector(option); |
| 272 | } |
| 273 | |
| 274 | mergeOption(option: Ops, ecModel: GlobalModel) { |
| 275 | super.mergeOption(option, ecModel); |
| 276 | this._updateSelector(option); |
| 277 | } |
| 278 | |
| 279 | _updateSelector(option: Ops) { |
| 280 | let selector = option.selector; |
| 281 | const {ecModel} = this; |
| 282 | if (selector === true) { |
| 283 | selector = option.selector = ['all', 'inverse']; |
| 284 | } |
| 285 | if (zrUtil.isArray(selector)) { |
| 286 | zrUtil.each(selector, function (item, index) { |
| 287 | zrUtil.isString(item) && (item = {type: item}); |
| 288 | (selector as LegendSelectorButtonOption[])[index] = zrUtil.merge( |
| 289 | item, getDefaultSelectorOptions(ecModel, item.type) |
| 290 | ); |
| 291 | }); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | optionUpdated() { |
| 296 | this._updateData(this.ecModel); |
| 297 | |
| 298 | const legendData = this._data; |
| 299 | |
| 300 | // If selectedMode is single, try to select one |
| 301 | if (legendData[0] && this.get('selectedMode') === 'single') { |
| 302 | let hasSelected = false; |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…