You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by su...@apache.org on 2020/03/17 00:40:03 UTC
[incubator-echarts] 04/04: ts: add and unify defaultOption
inheritance.
This is an automated email from the ASF dual-hosted git repository.
sushuang pushed a commit to branch typescript
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
commit a869e3385738e0e70586562dda25dad54e1f0103
Author: 100pah <su...@gmail.com>
AuthorDate: Tue Mar 17 08:38:52 2020 +0800
ts: add and unify defaultOption inheritance.
---
src/chart/bar/BarSeries.ts | 5 +++--
src/chart/bar/PictorialBarSeries.ts | 5 +++--
src/component/dataZoom/InsideZoomModel.ts | 5 +++--
src/component/dataZoom/SliderZoomModel.ts | 5 +++--
src/component/legend/ScrollableLegendModel.ts | 5 ++---
src/component/visualMap/ContinuousModel.ts | 5 ++---
src/component/visualMap/PiecewiseModel.ts | 5 ++---
src/model/Component.ts | 6 +++---
src/util/component.ts | 5 +++++
src/util/model.ts | 6 ------
10 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/src/chart/bar/BarSeries.ts b/src/chart/bar/BarSeries.ts
index 7f756c9..50c8653 100644
--- a/src/chart/bar/BarSeries.ts
+++ b/src/chart/bar/BarSeries.ts
@@ -22,6 +22,7 @@ import SeriesModel from '../../model/Series';
import { ItemStyleOption, OptionDataValue, LabelOption, SeriesStackOptionMixin } from '../../util/types';
import type Cartesian2D from '../../coord/cartesian/Cartesian2D';
import type Polar from '../../coord/polar/Polar';
+import { inheritDefaultOption } from '../../util/component';
type BarDataValue = OptionDataValue | OptionDataValue[]
@@ -112,7 +113,7 @@ class BarSeriesModel extends BaseBarSeriesModel<BarSeriesOption> {
return progressiveThreshold;
}
- static defaultOption: BarSeriesOption = {
+ static defaultOption: BarSeriesOption = inheritDefaultOption(BaseBarSeriesModel.defaultOption, {
// If clipped
// Only available on cartesian2d
clip: true,
@@ -132,7 +133,7 @@ class BarSeriesModel extends BaseBarSeriesModel<BarSeriesOption> {
shadowOffsetY: 0,
opacity: 1
}
- }
+ });
}
diff --git a/src/chart/bar/PictorialBarSeries.ts b/src/chart/bar/PictorialBarSeries.ts
index b09dfb4..92eae94 100644
--- a/src/chart/bar/PictorialBarSeries.ts
+++ b/src/chart/bar/PictorialBarSeries.ts
@@ -27,6 +27,7 @@ import {
SeriesStackOptionMixin
} from '../../util/types';
import type Cartesian2D from '../../coord/cartesian/Cartesian2D';
+import { inheritDefaultOption } from '../../util/component';
interface PictorialBarSeriesSymbolOption {
/**
@@ -123,7 +124,7 @@ class PictorialBarSeriesModel extends BaseBarSeriesModel<PictorialBarSeriesOptio
coordinateSystem: Cartesian2D
- static defaultOption: PictorialBarSeriesOption = {
+ static defaultOption: PictorialBarSeriesOption = inheritDefaultOption(BaseBarSeriesModel.defaultOption, {
symbol: 'circle', // Customized bar shape
symbolSize: null, //
@@ -146,7 +147,7 @@ class PictorialBarSeriesModel extends BaseBarSeriesModel<PictorialBarSeriesOptio
// Disable progressive
progressive: 0,
hoverAnimation: false // Open only when needed.
- }
+ });
getInitialData(option: PictorialBarSeriesOption) {
// Disable stack.
diff --git a/src/component/dataZoom/InsideZoomModel.ts b/src/component/dataZoom/InsideZoomModel.ts
index 2a67dd4..c9880ac 100644
--- a/src/component/dataZoom/InsideZoomModel.ts
+++ b/src/component/dataZoom/InsideZoomModel.ts
@@ -19,6 +19,7 @@
import DataZoomModel, {DataZoomOption} from './DataZoomModel';
import ComponentModel from '../../model/Component';
+import { inheritDefaultOption } from '../../util/component';
interface InsideDataZoomOption extends DataZoomOption {
@@ -51,14 +52,14 @@ class InsideZoomModel extends DataZoomModel<InsideDataZoomOption> {
static readonly type = 'dataZoom.inside'
type = InsideZoomModel.type
- static defaultOption: InsideDataZoomOption = {
+ static defaultOption: InsideDataZoomOption = inheritDefaultOption(DataZoomModel.defaultOption, {
disabled: false,
zoomLock: false,
zoomOnMouseWheel: true,
moveOnMouseMove: true,
moveOnMouseWheel: false,
preventDefaultMouseMove: true
- }
+ });
}
ComponentModel.registerClass(InsideZoomModel);
diff --git a/src/component/dataZoom/SliderZoomModel.ts b/src/component/dataZoom/SliderZoomModel.ts
index bed625b..67948a1 100644
--- a/src/component/dataZoom/SliderZoomModel.ts
+++ b/src/component/dataZoom/SliderZoomModel.ts
@@ -27,6 +27,7 @@ import {
ItemStyleOption,
LabelOption
} from '../../util/types';
+import { inheritDefaultOption } from '../../util/component';
interface SliderDataZoomOption extends DataZoomOption, BoxLayoutOptionMixin {
@@ -96,7 +97,7 @@ class SliderZoomModel extends DataZoomModel<SliderDataZoomOption> {
static readonly layoutMode = 'box'
- static defaultOption: SliderDataZoomOption = {
+ static defaultOption: SliderDataZoomOption = inheritDefaultOption(DataZoomModel.defaultOption, {
show: true,
// deault value can only be drived in view stage.
@@ -141,7 +142,7 @@ class SliderZoomModel extends DataZoomModel<SliderDataZoomOption> {
textStyle: {
color: '#333'
}
- }
+ });
}
ComponentModel.registerClass(SliderZoomModel);
diff --git a/src/component/legend/ScrollableLegendModel.ts b/src/component/legend/ScrollableLegendModel.ts
index 04bf2ed..e4c2d4e 100644
--- a/src/component/legend/ScrollableLegendModel.ts
+++ b/src/component/legend/ScrollableLegendModel.ts
@@ -27,6 +27,7 @@ import Model from '../../model/Model';
import ComponentModel from '../../model/Component';
import GlobalModel from '../../model/Global';
import * as zrUtil from 'zrender/src/core/util';
+import { inheritDefaultOption } from '../../util/component';
export interface ScrollableLegendOption extends LegendOption {
scrollDataIndex?: number
@@ -86,9 +87,7 @@ class ScrollableLegendModel extends LegendModel<ScrollableLegendOption> {
mergeAndNormalizeLayoutParams(this, this.option, option);
}
- static defaultOption: ScrollableLegendOption = zrUtil.merge(
- zrUtil.clone(LegendModel.defaultOption),
- {
+ static defaultOption: ScrollableLegendOption = inheritDefaultOption(LegendModel.defaultOption, {
scrollDataIndex: 0,
pageButtonItemGap: 5,
pageButtonGap: null,
diff --git a/src/component/visualMap/ContinuousModel.ts b/src/component/visualMap/ContinuousModel.ts
index 85bdff1..17bc3d1 100644
--- a/src/component/visualMap/ContinuousModel.ts
+++ b/src/component/visualMap/ContinuousModel.ts
@@ -22,6 +22,7 @@ import VisualMapModel, { VisualMapOption, VisualMeta } from './VisualMapModel';
import * as numberUtil from '../../util/number';
import ComponentModel from '../../model/Component';
import { VisualMappingOption } from '../../visual/VisualMapping';
+import { inheritDefaultOption } from '../../util/component';
// Constant
var DEFAULT_BAR_BOUND = [20, 140];
@@ -259,9 +260,7 @@ class ContinuousModel extends VisualMapModel<ContinousVisualMapOption> {
};
}
- static defaultOption = zrUtil.merge(
- zrUtil.clone(VisualMapModel.defaultOption),
- {
+ static defaultOption = inheritDefaultOption(VisualMapModel.defaultOption, {
align: 'auto', // 'auto', 'left', 'right', 'top', 'bottom'
calculable: false,
hoverLink: true
diff --git a/src/component/visualMap/PiecewiseModel.ts b/src/component/visualMap/PiecewiseModel.ts
index a156c86..af8f21d 100644
--- a/src/component/visualMap/PiecewiseModel.ts
+++ b/src/component/visualMap/PiecewiseModel.ts
@@ -26,6 +26,7 @@ import {reformIntervals} from '../../util/number';
import { VisualOptionPiecewise, BuiltinVisualProperty } from '../../util/types';
import { Dictionary } from 'zrender/src/core/types';
import ComponentModel from '../../model/Component';
+import { inheritDefaultOption } from '../../util/component';
interface VisualPiece extends VisualOptionPiecewise {
@@ -408,9 +409,7 @@ class PiecewiseModel extends VisualMapModel<PiecewiseVisualMapOption> {
}
- static defaultOption = zrUtil.merge(
- zrUtil.clone(VisualMapModel.defaultOption),
- {
+ static defaultOption = inheritDefaultOption(VisualMapModel.defaultOption, {
selected: null,
minOpen: false, // Whether include values that smaller than `min`.
maxOpen: false, // Whether include values that bigger than `max`.
diff --git a/src/model/Component.ts b/src/model/Component.ts
index ada5ac9..9c910f1 100644
--- a/src/model/Component.ts
+++ b/src/model/Component.ts
@@ -194,15 +194,15 @@ class ComponentModel<Opt extends ComponentOption = ComponentOption> extends Mode
* Component.registerClass(XxxModel);
* ```
* ```ts
- * import {mergeOption} from '../model/util';
+ * import {inheritDefaultOption} from '../util/component';
* import {XxxModel, XxxOption} from './XxxModel';
* export interface XxxSubOption extends XxxOption {
* bbb: number
* }
* class XxxSubModel extends XxxModel {
- * readonly defaultOption: XxxSubOption = mergeOption({
+ * static defaultOption: XxxSubOption = inheritDefaultOption(XxxModel.defaultOption, {
* bbb: 456
- * }, XxxModel.prototype.defaultOption)
+ * })
* fn() {
* var opt = this.getDefaultOption();
* // opt is {aaa: 123, bbb: 456}
diff --git a/src/util/component.ts b/src/util/component.ts
index c1b3855..8a54d4c 100644
--- a/src/util/component.ts
+++ b/src/util/component.ts
@@ -216,3 +216,8 @@ export function enableTopologicalTravel<T>(
}
}
+
+export function inheritDefaultOption<T, K>(superOption: T, subOption: K): K {
+ // See also `model/Component.ts#getDefaultOption`
+ return zrUtil.merge(zrUtil.merge({}, superOption, true), subOption, true);
+}
diff --git a/src/util/model.ts b/src/util/model.ts
index be9e3e9..e9f3f71 100644
--- a/src/util/model.ts
+++ b/src/util/model.ts
@@ -21,7 +21,6 @@ import {
each,
isObject,
isArray,
- merge,
createHashMap,
HashMap,
map,
@@ -669,8 +668,3 @@ export function groupData<T, R extends string | number>(
buckets: buckets
};
}
-
-export function mergeOption<T, K>(option1: T, option2: K): T & K {
- // See also `model/Component.ts#getDefaultOption`
- return merge(merge({}, option1, true), option2, true);
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org