diff --git a/src/legacy/dataSelectAction.ts b/src/legacy/dataSelectAction.ts index e1a68c6afd..9a543ceb51 100644 --- a/src/legacy/dataSelectAction.ts +++ b/src/legacy/dataSelectAction.ts @@ -17,9 +17,9 @@ * under the License. */ -import { Payload, SelectChangedPayload } from '../util/types'; +import { Dictionary, Payload, SelectChangedPayload } from '../util/types'; import SeriesModel from '../model/Series'; -import { extend, each, isArray } from 'zrender/src/core/util'; +import { extend, each, isArray, isString } from 'zrender/src/core/util'; import GlobalModel from '../model/Global'; import { deprecateReplaceLog, deprecateLog } from '../util/log'; import Eventful from 'zrender/src/core/Eventful'; @@ -77,6 +77,7 @@ function handleSeriesLegacySelectEvents( mainType: 'series', subType: 'pie' }, function (seriesModel: SeriesModel) { const seriesIndex = seriesModel.seriesIndex; + const selectedMap = seriesModel.option.selectedMap; const selected = payload.selected; for (let i = 0; i < selected.length; i++) { if (selected[i].seriesIndex === seriesIndex) { @@ -86,7 +87,7 @@ function handleSeriesLegacySelectEvents( type: legacyEventName, seriesId: seriesModel.id, name: isArray(dataIndex) ? data.getName(dataIndex[0]) : data.getName(dataIndex), - selected: extend({}, seriesModel.option.selectedMap) + selected: isString(selectedMap) ? selectedMap : extend({}, selectedMap) }); } } diff --git a/src/model/Series.ts b/src/model/Series.ts index 5fbce936d6..dc97df40c5 100644 --- a/src/model/Series.ts +++ b/src/model/Series.ts @@ -29,7 +29,8 @@ import { SeriesDataType, SeriesEncodeOptionMixin, OptionEncodeValue, - ColorBy + ColorBy, + StatesOptionMixin } from '../util/types'; import ComponentModel, { ComponentModelConstructor } from './Component'; import {PaletteMixin} from './mixin/palette'; @@ -178,7 +179,6 @@ class SeriesModel extends ComponentMode // Props about data selection // --------------------------------------- private _selectedDataIndicesMap: Dictionary = {}; - readonly preventUsingHoverLayer: boolean; static protoInitialize = (function () { @@ -519,7 +519,15 @@ class SeriesModel extends ComponentMode if (!selectedMap) { return; } + const selectedMode = this.option.selectedMode; + const data = this.getData(dataType); + if (selectedMode === 'series' || selectedMap === 'all') { + this.option.selectedMap = {}; + this._selectedDataIndicesMap = {}; + return; + } + for (let i = 0; i < innerDataIndices.length; i++) { const dataIndex = innerDataIndices[i]; const nameOrId = getSelectionKey(data, dataIndex); @@ -539,6 +547,9 @@ class SeriesModel extends ComponentMode } getSelectedDataIndices(): number[] { + if (this.option.selectedMap === 'all') { + return [].slice.call(this.getData().getIndices()); + } const selectedDataIndicesMap = this._selectedDataIndicesMap; const nameOrIds = zrUtil.keys(selectedDataIndicesMap); const dataIndices = []; @@ -558,8 +569,9 @@ class SeriesModel extends ComponentMode } const data = this.getData(dataType); - const nameOrId = getSelectionKey(data, dataIndex); - return selectedMap[nameOrId] || false; + + return (selectedMap === 'all' || selectedMap[getSelectionKey(data, dataIndex)]) + && !data.getItemModel>(dataIndex).get(['select', 'disabled']) } isUniversalTransitionEnabled(): boolean { @@ -582,14 +594,21 @@ class SeriesModel extends ComponentMode } private _innerSelect(data: SeriesData, innerDataIndices: number[]) { - const selectedMode = this.option.selectedMode; + const option = this.option; + const selectedMode = option.selectedMode; const len = innerDataIndices.length; if (!selectedMode || !len) { return; } - if (selectedMode === 'multiple') { - const selectedMap = this.option.selectedMap || (this.option.selectedMap = {}); + if (selectedMode === 'series') { + option.selectedMap = 'all'; + } + else if (selectedMode === 'multiple') { + if (!zrUtil.isObject(option.selectedMap)) { + option.selectedMap = {}; + } + const selectedMap = option.selectedMap; for (let i = 0; i < len; i++) { const dataIndex = innerDataIndices[i]; // TODO diffrent types of data share same object. @@ -601,7 +620,7 @@ class SeriesModel extends ComponentMode else if (selectedMode === 'single' || selectedMode === true) { const lastDataIndex = innerDataIndices[len - 1]; const nameOrId = getSelectionKey(data, lastDataIndex); - this.option.selectedMap = { + option.selectedMap = { [nameOrId]: true }; this._selectedDataIndicesMap = { diff --git a/src/util/types.ts b/src/util/types.ts index 95e5b5027d..3f374bdadc 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -1500,7 +1500,9 @@ export interface StatesOptionMixin< /** * Select states */ - select?: StateOption & StatesMixin['select'] + select?: StateOption & StatesMixin['select'] & { + disabled?: boolean + } /** * Blur states. */ @@ -1609,8 +1611,8 @@ export interface SeriesOption< * Map of selected data * key is name or index of data. */ - selectedMap?: Dictionary - selectedMode?: 'single' | 'multiple' | boolean + selectedMap?: Dictionary | 'all' + selectedMode?: 'single' | 'multiple' | 'series' | boolean } export interface SeriesOnCartesianOptionMixin { diff --git a/test/bar2.html b/test/bar2.html index a0f0e6c59d..b7f600769e 100644 --- a/test/bar2.html +++ b/test/bar2.html @@ -52,6 +52,7 @@

Narrow grid

+
+ + \ No newline at end of file diff --git a/test/geo-map.html b/test/geo-map.html index 56f43a1f02..dfe1fca0c4 100644 --- a/test/geo-map.html +++ b/test/geo-map.html @@ -542,7 +542,7 @@ }] }, data:[ - {name: '北京',value: Math.round(Math.random()*1000)}, + {name: '北京',value: Math.round(Math.random()*1000), select: {disabled: true}}, {name: '天津',value: Math.round(Math.random()*1000)}, {name: '上海',value: Math.round(Math.random()*1000)}, {name: '重庆',value: Math.round(Math.random()*1000)}, @@ -550,7 +550,7 @@ {name: '河南',value: Math.round(Math.random()*1000)}, {name: '云南',value: Math.round(Math.random()*1000)}, {name: '辽宁',value: Math.round(Math.random()*1000)}, - {name: '黑龙江',value: Math.round(Math.random()*1000)}, + {name: '黑龙江',value: Math.round(Math.random()*1000), select: {disabled: true}}, {name: '湖南',value: Math.round(Math.random()*1000)}, {name: '安徽',value: Math.round(Math.random()*1000)}, {name: '山东',value: Math.round(Math.random()*1000)}, @@ -562,7 +562,7 @@ {name: '广西',value: Math.round(Math.random()*1000)}, {name: '甘肃',value: Math.round(Math.random()*1000)}, {name: '山西',value: Math.round(Math.random()*1000)}, - {name: '内蒙古',value: Math.round(Math.random()*1000)}, + {name: '内蒙古',value: Math.round(Math.random()*1000), select: {disabled: true}}, {name: '陕西',value: Math.round(Math.random()*1000)}, {name: '吉林',value: Math.round(Math.random()*1000)}, {name: '福建',value: Math.round(Math.random()*1000)}, @@ -621,9 +621,9 @@ ] }); - chart.on('click', function (param) { - alert('asdf'); - }); + // chart.on('click', function (param) { + // alert('asdf'); + // }); // setTimeout(function () { // chart.setOption({ // series: [{ diff --git a/test/pie.html b/test/pie.html index 4a0b6718c7..10ca6440af 100644 --- a/test/pie.html +++ b/test/pie.html @@ -331,7 +331,7 @@ }, series: { type: 'pie', - selectedMode: 'multiply' + selectedMode: 'multiple' } };