[incubator-echarts] branch next updated: feature: enable media query and timeline declared without `baseOption` in echarts option.

2020-08-18 Thread sushuang
This is an automated email from the ASF dual-hosted git repository.

sushuang pushed a commit to branch next
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git


The following commit(s) were added to refs/heads/next by this push:
 new 2deacbd  feature: enable media query and timeline declared without 
`baseOption` in echarts option.
2deacbd is described below

commit 2deacbd5203701ef836a15e99d8c059df7a4782b
Author: 100pah 
AuthorDate: Tue Aug 18 15:03:16 2020 +0800

feature: enable media query and timeline declared without `baseOption` in 
echarts option.
---
 package.json|   1 +
 src/model/OptionManager.ts  | 130 +--
 src/util/types.ts   |   8 +-
 test/media-pie.html | 292 
 test/ut/spec/model/timelineMediaOptions.test.js | 430 
 test/ut/spec/model/timelineOptions.test.js  | 178 --
 6 files changed, 674 insertions(+), 365 deletions(-)

diff --git a/package.json b/package.json
index 186f1f0..fdfc853 100644
--- a/package.json
+++ b/package.json
@@ -28,6 +28,7 @@
 "test:visual": "node test/runTest/server.js",
 "test:visual:report": "node test/runTest/genReport.js",
 "test": "node build/build.js --prepublish && jest --config 
test/ut/jest.config.js",
+"test:single": "jest --config test/ut/jest.config.js --coverage=false -t",
 "mktest": "node test/build/mktest.js",
 "mktest:help": "node test/build/mktest.js -h",
 "lint": "./node_modules/.bin/eslint src/**/*.ts extension-src/**/*.ts",
diff --git a/src/model/OptionManager.ts b/src/model/OptionManager.ts
index b92d5b4..850a29f 100644
--- a/src/model/OptionManager.ts
+++ b/src/model/OptionManager.ts
@@ -235,34 +235,105 @@ class OptionManager {
 
 }
 
+/**
+ * [RAW_OPTION_PATTERNS]
+ * (Note: "series: []" represents all other props in `ECUnitOption`)
+ *
+ * (1) No prop "baseOption" declared:
+ * Root option is used as "baseOption" (except prop "options" and "media").
+ * ```js
+ * option = {
+ * series: [],
+ * timeline: {},
+ * options: [],
+ * };
+ * option = {
+ * series: [],
+ * media: {},
+ * };
+ * option = {
+ * series: [],
+ * timeline: {},
+ * options: [],
+ * media: {},
+ * }
+ * ```
+ *
+ * (2) Prop "baseOption" declared:
+ * If "baseOption" declared, `ECUnitOption` props can only be declared
+ * inside "baseOption" except prop "timeline" (compat ec2).
+ * ```js
+ * option = {
+ * baseOption: {
+ * timeline: {},
+ * series: [],
+ * },
+ * options: []
+ * };
+ * option = {
+ * baseOption: {
+ * series: [],
+ * },
+ * media: []
+ * };
+ * option = {
+ * baseOption: {
+ * timeline: {},
+ * series: [],
+ * },
+ * options: []
+ * media: []
+ * };
+ * option = {
+ * // ec3 compat ec2: allow (only) `timeline` declared
+ * // outside baseOption. Keep this setting for compat.
+ * timeline: {},
+ * baseOption: {
+ * series: [],
+ * },
+ * options: [],
+ * media: []
+ * };
+ * ```
+ */
 function parseRawOption(
+// `rawOption` May be modified
 rawOption: ECOption,
 optionPreprocessorFuncs: OptionPreprocessor[],
 isNew: boolean
 ): ParsedRawOption {
-let timelineOptions: ECUnitOption[] = [];
 const mediaList: MediaUnit[] = [];
 let mediaDefault: MediaUnit;
 let baseOption: ECUnitOption;
 
-// Compatible with ec2.
-const timelineOpt = rawOption.timeline;
+const declaredBaseOption = rawOption.baseOption;
+// Compatible with ec2, [RAW_OPTION_PATTERNS] above.
+const timelineOnRoot = rawOption.timeline;
+const timelineOptionsOnRoot = rawOption.options;
+const mediaOnRoot = rawOption.media;
+const hasMedia = !!rawOption.media;
+const hasTimeline = !!(
+timelineOptionsOnRoot || timelineOnRoot || (declaredBaseOption && 
declaredBaseOption.timeline)
+);
 
-if (rawOption.baseOption) {
-baseOption = rawOption.baseOption;
+if (declaredBaseOption) {
+baseOption = declaredBaseOption;
+// For merge option.
+if (!baseOption.timeline) {
+baseOption.timeline = timelineOnRoot;
+}
 }
-
-// For timeline
-if (timelineOpt || rawOption.options) {
-baseOption = baseOption || {} as ECUnitOption;
-timelineOptions = (rawOption.options || []).slice();
+// For convenience, enable to use the root option as the `baseOption`:
+// `{ ...normalOptionProps, media: [{ ... }, { ... }] }`
+else {
+if (hasTimeline || hasMedia) {
+rawOption.options = rawOption.media = null;
+}
+baseOption = rawOption;
 }
 
-// For media query
-if (rawOption.media) {
-baseOption = baseOption || {} as ECUnitOption;
-const media = rawOption.media;
-each(media, function (singleMedia) {
+if (hasMedia) {
+ 

[incubator-echarts] branch next updated: feature: enable media query and timeline declared without `baseOption` in echarts option.

2020-08-18 Thread sushuang
This is an automated email from the ASF dual-hosted git repository.

sushuang pushed a commit to branch next
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git


The following commit(s) were added to refs/heads/next by this push:
 new 2deacbd  feature: enable media query and timeline declared without 
`baseOption` in echarts option.
2deacbd is described below

commit 2deacbd5203701ef836a15e99d8c059df7a4782b
Author: 100pah 
AuthorDate: Tue Aug 18 15:03:16 2020 +0800

feature: enable media query and timeline declared without `baseOption` in 
echarts option.
---
 package.json|   1 +
 src/model/OptionManager.ts  | 130 +--
 src/util/types.ts   |   8 +-
 test/media-pie.html | 292 
 test/ut/spec/model/timelineMediaOptions.test.js | 430 
 test/ut/spec/model/timelineOptions.test.js  | 178 --
 6 files changed, 674 insertions(+), 365 deletions(-)

diff --git a/package.json b/package.json
index 186f1f0..fdfc853 100644
--- a/package.json
+++ b/package.json
@@ -28,6 +28,7 @@
 "test:visual": "node test/runTest/server.js",
 "test:visual:report": "node test/runTest/genReport.js",
 "test": "node build/build.js --prepublish && jest --config 
test/ut/jest.config.js",
+"test:single": "jest --config test/ut/jest.config.js --coverage=false -t",
 "mktest": "node test/build/mktest.js",
 "mktest:help": "node test/build/mktest.js -h",
 "lint": "./node_modules/.bin/eslint src/**/*.ts extension-src/**/*.ts",
diff --git a/src/model/OptionManager.ts b/src/model/OptionManager.ts
index b92d5b4..850a29f 100644
--- a/src/model/OptionManager.ts
+++ b/src/model/OptionManager.ts
@@ -235,34 +235,105 @@ class OptionManager {
 
 }
 
+/**
+ * [RAW_OPTION_PATTERNS]
+ * (Note: "series: []" represents all other props in `ECUnitOption`)
+ *
+ * (1) No prop "baseOption" declared:
+ * Root option is used as "baseOption" (except prop "options" and "media").
+ * ```js
+ * option = {
+ * series: [],
+ * timeline: {},
+ * options: [],
+ * };
+ * option = {
+ * series: [],
+ * media: {},
+ * };
+ * option = {
+ * series: [],
+ * timeline: {},
+ * options: [],
+ * media: {},
+ * }
+ * ```
+ *
+ * (2) Prop "baseOption" declared:
+ * If "baseOption" declared, `ECUnitOption` props can only be declared
+ * inside "baseOption" except prop "timeline" (compat ec2).
+ * ```js
+ * option = {
+ * baseOption: {
+ * timeline: {},
+ * series: [],
+ * },
+ * options: []
+ * };
+ * option = {
+ * baseOption: {
+ * series: [],
+ * },
+ * media: []
+ * };
+ * option = {
+ * baseOption: {
+ * timeline: {},
+ * series: [],
+ * },
+ * options: []
+ * media: []
+ * };
+ * option = {
+ * // ec3 compat ec2: allow (only) `timeline` declared
+ * // outside baseOption. Keep this setting for compat.
+ * timeline: {},
+ * baseOption: {
+ * series: [],
+ * },
+ * options: [],
+ * media: []
+ * };
+ * ```
+ */
 function parseRawOption(
+// `rawOption` May be modified
 rawOption: ECOption,
 optionPreprocessorFuncs: OptionPreprocessor[],
 isNew: boolean
 ): ParsedRawOption {
-let timelineOptions: ECUnitOption[] = [];
 const mediaList: MediaUnit[] = [];
 let mediaDefault: MediaUnit;
 let baseOption: ECUnitOption;
 
-// Compatible with ec2.
-const timelineOpt = rawOption.timeline;
+const declaredBaseOption = rawOption.baseOption;
+// Compatible with ec2, [RAW_OPTION_PATTERNS] above.
+const timelineOnRoot = rawOption.timeline;
+const timelineOptionsOnRoot = rawOption.options;
+const mediaOnRoot = rawOption.media;
+const hasMedia = !!rawOption.media;
+const hasTimeline = !!(
+timelineOptionsOnRoot || timelineOnRoot || (declaredBaseOption && 
declaredBaseOption.timeline)
+);
 
-if (rawOption.baseOption) {
-baseOption = rawOption.baseOption;
+if (declaredBaseOption) {
+baseOption = declaredBaseOption;
+// For merge option.
+if (!baseOption.timeline) {
+baseOption.timeline = timelineOnRoot;
+}
 }
-
-// For timeline
-if (timelineOpt || rawOption.options) {
-baseOption = baseOption || {} as ECUnitOption;
-timelineOptions = (rawOption.options || []).slice();
+// For convenience, enable to use the root option as the `baseOption`:
+// `{ ...normalOptionProps, media: [{ ... }, { ... }] }`
+else {
+if (hasTimeline || hasMedia) {
+rawOption.options = rawOption.media = null;
+}
+baseOption = rawOption;
 }
 
-// For media query
-if (rawOption.media) {
-baseOption = baseOption || {} as ECUnitOption;
-const media = rawOption.media;
-each(media, function (singleMedia) {
+if (hasMedia) {
+