Skip to content
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

Feat: new selectedMode: series and select.disabled #15534

Merged
merged 17 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/legacy/dataSelectAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
});
}
}
Expand Down
35 changes: 27 additions & 8 deletions src/model/Series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import {
SeriesDataType,
SeriesEncodeOptionMixin,
OptionEncodeValue,
ColorBy
ColorBy,
StatesOptionMixin
} from '../util/types';
import ComponentModel, { ComponentModelConstructor } from './Component';
import {PaletteMixin} from './mixin/palette';
Expand Down Expand Up @@ -178,7 +179,6 @@ class SeriesModel<Opt extends SeriesOption = SeriesOption> extends ComponentMode
// Props about data selection
// ---------------------------------------
private _selectedDataIndicesMap: Dictionary<number> = {};

readonly preventUsingHoverLayer: boolean;

static protoInitialize = (function () {
Expand Down Expand Up @@ -519,7 +519,15 @@ class SeriesModel<Opt extends SeriesOption = SeriesOption> 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);
Expand All @@ -539,6 +547,9 @@ class SeriesModel<Opt extends SeriesOption = SeriesOption> 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 = [];
Expand All @@ -558,8 +569,9 @@ class SeriesModel<Opt extends SeriesOption = SeriesOption> 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<StatesOptionMixin<unknown, unknown>>(dataIndex).get(['select', 'disabled'])
}

isUniversalTransitionEnabled(): boolean {
Expand All @@ -582,14 +594,21 @@ class SeriesModel<Opt extends SeriesOption = SeriesOption> 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.
Expand All @@ -601,7 +620,7 @@ class SeriesModel<Opt extends SeriesOption = SeriesOption> 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 = {
Expand Down
8 changes: 5 additions & 3 deletions src/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,9 @@ export interface StatesOptionMixin<
/**
* Select states
*/
select?: StateOption & StatesMixin['select']
select?: StateOption & StatesMixin['select'] & {
disabled?: boolean
}
/**
* Blur states.
*/
Expand Down Expand Up @@ -1609,8 +1611,8 @@ export interface SeriesOption<
* Map of selected data
* key is name or index of data.
*/
selectedMap?: Dictionary<boolean>
selectedMode?: 'single' | 'multiple' | boolean
selectedMap?: Dictionary<boolean> | 'all'
selectedMode?: 'single' | 'multiple' | 'series' | boolean
}

export interface SeriesOnCartesianOptionMixin {
Expand Down
141 changes: 140 additions & 1 deletion test/bar2.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions test/geo-map.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/pie.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.