echarts 4.5.0 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/dist/echarts-en.common.js +1790 -774
  2. package/dist/echarts-en.common.min.js +1 -1
  3. package/dist/echarts-en.js +2029 -849
  4. package/dist/echarts-en.js.map +1 -1
  5. package/dist/echarts-en.min.js +1 -1
  6. package/dist/echarts-en.simple.js +1676 -691
  7. package/dist/echarts-en.simple.min.js +1 -1
  8. package/dist/echarts.common.js +1790 -774
  9. package/dist/echarts.common.min.js +1 -1
  10. package/dist/echarts.js +2029 -849
  11. package/dist/echarts.js.map +1 -1
  12. package/dist/echarts.min.js +1 -1
  13. package/dist/echarts.simple.js +1676 -691
  14. package/dist/echarts.simple.min.js +1 -1
  15. package/lib/chart/bar/BarView.js +11 -1
  16. package/lib/chart/bar/BaseBarSeries.js +3 -1
  17. package/lib/chart/effectScatter/EffectScatterSeries.js +3 -1
  18. package/lib/chart/funnel/FunnelSeries.js +15 -5
  19. package/lib/chart/gauge/GaugeSeries.js +0 -2
  20. package/lib/chart/graph/GraphSeries.js +9 -4
  21. package/lib/chart/graph/GraphView.js +28 -8
  22. package/lib/chart/heatmap/HeatmapView.js +4 -4
  23. package/lib/chart/helper/createListFromArray.js +14 -8
  24. package/lib/chart/helper/whiskerBoxCommon.js +22 -16
  25. package/lib/chart/line/LineSeries.js +3 -1
  26. package/lib/chart/line/LineView.js +8 -2
  27. package/lib/chart/map/MapSeries.js +8 -1
  28. package/lib/chart/pie/PieSeries.js +27 -6
  29. package/lib/chart/pie/PieView.js +1 -1
  30. package/lib/chart/pie/labelLayout.js +102 -19
  31. package/lib/chart/pie/pieLayout.js +19 -7
  32. package/lib/chart/radar/RadarSeries.js +3 -3
  33. package/lib/chart/sankey/SankeyView.js +28 -9
  34. package/lib/chart/scatter/ScatterSeries.js +3 -1
  35. package/lib/chart/themeRiver/ThemeRiverSeries.js +3 -3
  36. package/lib/chart/tree/TreeSeries.js +15 -1
  37. package/lib/component/axis/AngleAxisView.js +64 -7
  38. package/lib/component/axis/AxisBuilder.js +63 -24
  39. package/lib/component/axis/CartesianAxisView.js +55 -11
  40. package/lib/component/axis/RadiusAxisView.js +36 -4
  41. package/lib/component/dataZoom/SliderZoomView.js +4 -10
  42. package/lib/component/helper/BrushController.js +33 -43
  43. package/lib/component/legend/LegendModel.js +3 -3
  44. package/lib/component/legend/LegendView.js +17 -13
  45. package/lib/component/toolbox/ToolboxView.js +5 -1
  46. package/lib/component/toolbox/feature/MagicType.js +19 -14
  47. package/lib/coord/Axis.js +30 -2
  48. package/lib/coord/axisDefault.js +21 -2
  49. package/lib/data/DataDimensionInfo.js +157 -0
  50. package/lib/data/List.js +25 -19
  51. package/lib/data/Tree.js +2 -1
  52. package/lib/data/helper/completeDimensions.js +43 -32
  53. package/lib/data/helper/createDimensions.js +2 -0
  54. package/lib/data/helper/sourceHelper.js +214 -114
  55. package/lib/echarts.js +2 -2
  56. package/lib/layout/barGrid.js +2 -3
  57. package/lib/model/Series.js +3 -3
  58. package/lib/model/referHelper.js +40 -12
  59. package/lib/scale/Interval.js +87 -2
  60. package/lib/scale/Log.js +9 -2
  61. package/lib/scale/helper.js +1 -43
  62. package/lib/theme/dark.js +3 -0
  63. package/lib/util/graphic.js +1 -2
  64. package/lib/visual/LegendVisualProvider.js +75 -0
  65. package/lib/visual/dataColor.js +2 -12
  66. package/lib/visual/seriesColor.js +15 -7
  67. package/map/json/province/tianjin.json +1 -1
  68. package/package.json +3 -2
  69. package/src/chart/bar/BarView.js +12 -2
  70. package/src/chart/bar/BaseBarSeries.js +1 -1
  71. package/src/chart/effectScatter/EffectScatterSeries.js +1 -1
  72. package/src/chart/funnel/FunnelSeries.js +11 -4
  73. package/src/chart/gauge/GaugeSeries.js +0 -1
  74. package/src/chart/graph/GraphSeries.js +8 -3
  75. package/src/chart/graph/GraphView.js +26 -8
  76. package/src/chart/heatmap/HeatmapView.js +4 -4
  77. package/src/chart/helper/createListFromArray.js +13 -8
  78. package/src/chart/helper/whiskerBoxCommon.js +21 -16
  79. package/src/chart/line/LineSeries.js +1 -1
  80. package/src/chart/line/LineView.js +6 -1
  81. package/src/chart/map/MapSeries.js +5 -1
  82. package/src/chart/pie/PieSeries.js +26 -5
  83. package/src/chart/pie/PieView.js +1 -1
  84. package/src/chart/pie/labelLayout.js +114 -22
  85. package/src/chart/pie/pieLayout.js +20 -7
  86. package/src/chart/radar/RadarSeries.js +5 -3
  87. package/src/chart/sankey/SankeyView.js +26 -9
  88. package/src/chart/scatter/ScatterSeries.js +1 -1
  89. package/src/chart/themeRiver/ThemeRiverSeries.js +4 -3
  90. package/src/chart/tree/TreeSeries.js +12 -1
  91. package/src/component/axis/AngleAxisView.js +75 -7
  92. package/src/component/axis/AxisBuilder.js +78 -33
  93. package/src/component/axis/CartesianAxisView.js +58 -11
  94. package/src/component/axis/RadiusAxisView.js +37 -4
  95. package/src/component/dataZoom/SliderZoomView.js +4 -9
  96. package/src/component/helper/BrushController.js +40 -47
  97. package/src/component/legend/LegendModel.js +3 -3
  98. package/src/component/legend/LegendView.js +18 -12
  99. package/src/component/toolbox/ToolboxView.js +5 -0
  100. package/src/component/toolbox/feature/MagicType.js +18 -13
  101. package/src/coord/Axis.js +29 -2
  102. package/src/coord/axisDefault.js +25 -1
  103. package/src/data/DataDimensionInfo.js +135 -0
  104. package/src/data/List.js +29 -16
  105. package/src/data/Tree.js +3 -1
  106. package/src/data/helper/completeDimensions.js +49 -30
  107. package/src/data/helper/createDimensions.js +2 -0
  108. package/src/data/helper/sourceHelper.js +216 -124
  109. package/src/echarts.js +2 -2
  110. package/src/layout/barGrid.js +6 -3
  111. package/src/model/Series.js +3 -3
  112. package/src/model/referHelper.js +34 -11
  113. package/src/scale/Interval.js +84 -4
  114. package/src/scale/Log.js +9 -2
  115. package/src/scale/helper.js +1 -39
  116. package/src/theme/dark.js +3 -0
  117. package/src/util/graphic.js +1 -2
  118. package/src/visual/LegendVisualProvider.js +55 -0
  119. package/src/visual/dataColor.js +0 -13
  120. package/src/visual/seriesColor.js +13 -7
  121. package/theme/azul.js +163 -0
  122. package/theme/bee-inspired.js +178 -0
  123. package/theme/blue.js +178 -0
  124. package/theme/caravan.js +178 -0
  125. package/theme/carp.js +163 -0
  126. package/theme/cool.js +180 -0
  127. package/theme/dark-blue.js +168 -0
  128. package/theme/dark-bold.js +168 -0
  129. package/theme/dark-digerati.js +168 -0
  130. package/theme/dark-fresh-cut.js +168 -0
  131. package/theme/dark-mushroom.js +168 -0
  132. package/theme/dark.js +69 -62
  133. package/theme/eduardo.js +178 -0
  134. package/theme/forest.js +163 -0
  135. package/theme/fresh-cut.js +163 -0
  136. package/theme/fruit.js +178 -0
  137. package/theme/gray.js +220 -0
  138. package/theme/green.js +222 -0
  139. package/theme/helianthus.js +263 -0
  140. package/theme/infographic.js +72 -57
  141. package/theme/inspired.js +163 -0
  142. package/theme/jazz.js +163 -0
  143. package/theme/london.js +163 -0
  144. package/theme/macarons.js +80 -57
  145. package/theme/macarons2.js +251 -0
  146. package/theme/mint.js +155 -0
  147. package/theme/red-velvet.js +163 -0
  148. package/theme/red.js +225 -0
  149. package/theme/roma.js +55 -22
  150. package/theme/royal.js +163 -0
  151. package/theme/sakura.js +140 -0
  152. package/theme/shine.js +52 -45
  153. package/theme/tech-blue.js +180 -0
  154. package/theme/vintage.js +37 -23
package/lib/coord/Axis.js CHANGED
@@ -111,7 +111,7 @@ Axis.prototype = {
111
111
  * @return {boolean}
112
112
  */
113
113
  containData: function (data) {
114
- return this.contain(this.dataToCoord(data));
114
+ return this.scale.contain(data);
115
115
  },
116
116
 
117
117
  /**
@@ -194,7 +194,7 @@ Axis.prototype = {
194
194
  * `axis.getTicksCoords` considers `onBand`, which is used by
195
195
  * `boundaryGap:true` of category axis and splitLine and splitArea.
196
196
  * @param {Object} [opt]
197
- * @param {number} [opt.tickModel=axis.model.getModel('axisTick')]
197
+ * @param {Model} [opt.tickModel=axis.model.getModel('axisTick')]
198
198
  * @param {boolean} [opt.clamp] If `true`, the first and the last
199
199
  * tick must be at the axis end points. Otherwise, clip ticks
200
200
  * that outside the axis extent.
@@ -219,6 +219,34 @@ Axis.prototype = {
219
219
  return ticksCoords;
220
220
  },
221
221
 
222
+ /**
223
+ * @return {Array.<Array.<Object>>} [{ coord: ..., tickValue: ...}]
224
+ */
225
+ getMinorTicksCoords: function () {
226
+ if (this.scale.type === 'ordinal') {
227
+ // Category axis doesn't support minor ticks
228
+ return [];
229
+ }
230
+
231
+ var minorTickModel = this.model.getModel('minorTick');
232
+ var splitNumber = minorTickModel.get('splitNumber'); // Protection.
233
+
234
+ if (!(splitNumber > 0 && splitNumber < 100)) {
235
+ splitNumber = 5;
236
+ }
237
+
238
+ var minorTicks = this.scale.getMinorTicks(splitNumber);
239
+ var minorTicksCoords = map(minorTicks, function (minorTicksGroup) {
240
+ return map(minorTicksGroup, function (minorTick) {
241
+ return {
242
+ coord: this.dataToCoord(minorTick),
243
+ tickValue: minorTick
244
+ };
245
+ }, this);
246
+ }, this);
247
+ return minorTicksCoords;
248
+ },
249
+
222
250
  /**
223
251
  * @return {Array.<Object>} [{
224
252
  * formattedLabel: string,
@@ -170,13 +170,32 @@ axisDefault.valueAxis = zrUtil.merge({
170
170
  // + `true`: the extent do not consider value 0.
171
171
  // scale: false,
172
172
  // AxisTick and axisLabel and splitLine are caculated based on splitNumber.
173
- splitNumber: 5 // Interval specifies the span of the ticks is mandatorily.
173
+ splitNumber: 5,
174
+ // Interval specifies the span of the ticks is mandatorily.
174
175
  // interval: null
175
176
  // Specify min interval when auto calculate tick interval.
176
177
  // minInterval: null
177
178
  // Specify max interval when auto calculate tick interval.
178
179
  // maxInterval: null
179
-
180
+ minorTick: {
181
+ // Minor tick, not available for cateogry axis.
182
+ show: false,
183
+ // Split number of minor ticks. The value should be in range of (0, 100)
184
+ splitNumber: 5,
185
+ // Lenght of minor tick
186
+ length: 3,
187
+ // Same inside with axisTick
188
+ // Line style
189
+ lineStyle: {// Default to be same with axisTick
190
+ }
191
+ },
192
+ minorSplitLine: {
193
+ show: false,
194
+ lineStyle: {
195
+ color: '#eee',
196
+ width: 1
197
+ }
198
+ }
180
199
  }, defaultOption);
181
200
  axisDefault.timeAxis = zrUtil.defaults({
182
201
  scale: true,
@@ -0,0 +1,157 @@
1
+
2
+ /*
3
+ * Licensed to the Apache Software Foundation (ASF) under one
4
+ * or more contributor license agreements. See the NOTICE file
5
+ * distributed with this work for additional information
6
+ * regarding copyright ownership. The ASF licenses this file
7
+ * to you under the Apache License, Version 2.0 (the
8
+ * "License"); you may not use this file except in compliance
9
+ * with the License. You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing,
14
+ * software distributed under the License is distributed on an
15
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ * KIND, either express or implied. See the License for the
17
+ * specific language governing permissions and limitations
18
+ * under the License.
19
+ */
20
+
21
+ var zrUtil = require("zrender/lib/core/util");
22
+
23
+ /*
24
+ * Licensed to the Apache Software Foundation (ASF) under one
25
+ * or more contributor license agreements. See the NOTICE file
26
+ * distributed with this work for additional information
27
+ * regarding copyright ownership. The ASF licenses this file
28
+ * to you under the Apache License, Version 2.0 (the
29
+ * "License"); you may not use this file except in compliance
30
+ * with the License. You may obtain a copy of the License at
31
+ *
32
+ * http://www.apache.org/licenses/LICENSE-2.0
33
+ *
34
+ * Unless required by applicable law or agreed to in writing,
35
+ * software distributed under the License is distributed on an
36
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
37
+ * KIND, either express or implied. See the License for the
38
+ * specific language governing permissions and limitations
39
+ * under the License.
40
+ */
41
+
42
+ /**
43
+ * @class
44
+ * @param {Object|DataDimensionInfo} [opt] All of the fields will be shallow copied.
45
+ */
46
+ function DataDimensionInfo(opt) {
47
+ if (opt != null) {
48
+ zrUtil.extend(this, opt);
49
+ }
50
+ /**
51
+ * Dimension name.
52
+ * Mandatory.
53
+ * @type {string}
54
+ */
55
+ // this.name;
56
+
57
+ /**
58
+ * The origin name in dimsDef, see source helper.
59
+ * If displayName given, the tooltip will displayed vertically.
60
+ * Optional.
61
+ * @type {string}
62
+ */
63
+ // this.displayName;
64
+
65
+ /**
66
+ * Which coordSys dimension this dimension mapped to.
67
+ * A `coordDim` can be a "coordSysDim" that the coordSys required
68
+ * (for example, an item in `coordSysDims` of `model/referHelper#CoordSysInfo`),
69
+ * or an generated "extra coord name" if does not mapped to any "coordSysDim"
70
+ * (That is determined by whether `isExtraCoord` is `true`).
71
+ * Mandatory.
72
+ * @type {string}
73
+ */
74
+ // this.coordDim;
75
+
76
+ /**
77
+ * The index of this dimension in `series.encode[coordDim]`.
78
+ * Mandatory.
79
+ * @type {number}
80
+ */
81
+ // this.coordDimIndex;
82
+
83
+ /**
84
+ * Dimension type. The enumerable values are the key of
85
+ * `dataCtors` of `data/List`.
86
+ * Optional.
87
+ * @type {string}
88
+ */
89
+ // this.type;
90
+
91
+ /**
92
+ * This index of this dimension info in `data/List#_dimensionInfos`.
93
+ * Mandatory after added to `data/List`.
94
+ * @type {number}
95
+ */
96
+ // this.index;
97
+
98
+ /**
99
+ * The format of `otherDims` is:
100
+ * ```js
101
+ * {
102
+ * tooltip: number optional,
103
+ * label: number optional,
104
+ * itemName: number optional,
105
+ * seriesName: number optional,
106
+ * }
107
+ * ```
108
+ *
109
+ * A `series.encode` can specified these fields:
110
+ * ```js
111
+ * encode: {
112
+ * // "3, 1, 5" is the index of data dimension.
113
+ * tooltip: [3, 1, 5],
114
+ * label: [0, 3],
115
+ * ...
116
+ * }
117
+ * ```
118
+ * `otherDims` is the parse result of the `series.encode` above, like:
119
+ * ```js
120
+ * // Suppose the index of this data dimension is `3`.
121
+ * this.otherDims = {
122
+ * // `3` is at the index `0` of the `encode.tooltip`
123
+ * tooltip: 0,
124
+ * // `3` is at the index `1` of the `encode.tooltip`
125
+ * label: 1
126
+ * };
127
+ * ```
128
+ *
129
+ * This prop should never be `null`/`undefined` after initialized.
130
+ * @type {Object}
131
+ */
132
+
133
+
134
+ this.otherDims = {};
135
+ /**
136
+ * Be `true` if this dimension is not mapped to any "coordSysDim" that the
137
+ * "coordSys" required.
138
+ * Mandatory.
139
+ * @type {boolean}
140
+ */
141
+ // this.isExtraCoord;
142
+
143
+ /**
144
+ * @type {module:data/OrdinalMeta}
145
+ */
146
+ // this.ordinalMeta;
147
+
148
+ /**
149
+ * Whether to create inverted indices.
150
+ * @type {boolean}
151
+ */
152
+ // this.createInvertedIndices;
153
+ }
154
+
155
+ ;
156
+ var _default = DataDimensionInfo;
157
+ module.exports = _default;
package/lib/data/List.js CHANGED
@@ -39,6 +39,8 @@ var _dimensionHelper = require("./helper/dimensionHelper");
39
39
 
40
40
  var summarizeDimensions = _dimensionHelper.summarizeDimensions;
41
41
 
42
+ var DataDimensionInfo = require("./DataDimensionInfo");
43
+
42
44
  /*
43
45
  * Licensed to the Apache Software Foundation (ASF) under one
44
46
  * or more contributor license agreements. See the NOTICE file
@@ -114,13 +116,9 @@ function transferProperties(target, source) {
114
116
  * @constructor
115
117
  * @alias module:echarts/data/List
116
118
  *
117
- * @param {Array.<string|Object>} dimensions
119
+ * @param {Array.<string|Object|module:data/DataDimensionInfo>} dimensions
118
120
  * For example, ['someDimName', {name: 'someDimName', type: 'someDimType'}, ...].
119
121
  * Dimensions should be concrete names like x, y, z, lng, lat, angle, radius
120
- * Spetial fields: {
121
- * ordinalMeta: <module:echarts/data/OrdinalMeta>
122
- * createInvertedIndices: <boolean>
123
- * }
124
122
  * @param {module:echarts/model/Model} hostModel
125
123
  */
126
124
 
@@ -136,9 +134,11 @@ var List = function (dimensions, hostModel) {
136
134
  var dimensionInfo = dimensions[i];
137
135
 
138
136
  if (zrUtil.isString(dimensionInfo)) {
139
- dimensionInfo = {
137
+ dimensionInfo = new DataDimensionInfo({
140
138
  name: dimensionInfo
141
- };
139
+ });
140
+ } else if (!(dimensionInfo instanceof DataDimensionInfo)) {
141
+ dimensionInfo = new DataDimensionInfo(dimensionInfo);
142
142
  }
143
143
 
144
144
  var dimensionName = dimensionInfo.name;
@@ -1182,7 +1182,8 @@ listProto.indexOfRawIndex = function (rawIndex) {
1182
1182
  * @param {string} dim
1183
1183
  * @param {number} value
1184
1184
  * @param {number} [maxDistance=Infinity]
1185
- * @return {Array.<number>} Considere multiple points has the same value.
1185
+ * @return {Array.<number>} If and only if multiple indices has
1186
+ * the same value, they are put to the result.
1186
1187
  */
1187
1188
 
1188
1189
 
@@ -1199,29 +1200,34 @@ listProto.indicesOfNearest = function (dim, value, maxDistance) {
1199
1200
  maxDistance = Infinity;
1200
1201
  }
1201
1202
 
1202
- var minDist = Number.MAX_VALUE;
1203
+ var minDist = Infinity;
1203
1204
  var minDiff = -1;
1205
+ var nearestIndicesLen = 0; // Check the test case of `test/ut/spec/data/List.js`.
1204
1206
 
1205
1207
  for (var i = 0, len = this.count(); i < len; i++) {
1206
- var diff = value - this.get(dim, i
1207
- /*, stack */
1208
- );
1208
+ var diff = value - this.get(dim, i);
1209
1209
  var dist = Math.abs(diff);
1210
1210
 
1211
- if (diff <= maxDistance && dist <= minDist) {
1212
- // For the case of two data are same on xAxis, which has sequence data.
1213
- // Show the nearest index
1214
- // https://github.com/ecomfe/echarts/issues/2869
1215
- if (dist < minDist || diff >= 0 && minDiff < 0) {
1211
+ if (dist <= maxDistance) {
1212
+ // When the `value` is at the middle of `this.get(dim, i)` and `this.get(dim, i+1)`,
1213
+ // we'd better not push both of them to `nearestIndices`, otherwise it is easy to
1214
+ // get more than one item in `nearestIndices` (more specifically, in `tooltip`).
1215
+ // So we chose the one that `diff >= 0` in this csae.
1216
+ // But if `this.get(dim, i)` and `this.get(dim, j)` get the same value, both of them
1217
+ // should be push to `nearestIndices`.
1218
+ if (dist < minDist || dist === minDist && diff >= 0 && minDiff < 0) {
1216
1219
  minDist = dist;
1217
1220
  minDiff = diff;
1218
- nearestIndices.length = 0;
1221
+ nearestIndicesLen = 0;
1219
1222
  }
1220
1223
 
1221
- nearestIndices.push(i);
1224
+ if (diff === minDiff) {
1225
+ nearestIndices[nearestIndicesLen++] = i;
1226
+ }
1222
1227
  }
1223
1228
  }
1224
1229
 
1230
+ nearestIndices.length = nearestIndicesLen;
1225
1231
  return nearestIndices;
1226
1232
  };
1227
1233
  /**
package/lib/data/Tree.js CHANGED
@@ -507,7 +507,7 @@ Tree.prototype = {
507
507
  * @return module:echarts/data/Tree
508
508
  */
509
509
 
510
- Tree.createTree = function (dataRoot, hostModel, treeOptions) {
510
+ Tree.createTree = function (dataRoot, hostModel, treeOptions, beforeLink) {
511
511
  var tree = new Tree(hostModel, treeOptions.levels, treeOptions.leaves);
512
512
  var listData = [];
513
513
  var dimMax = 1;
@@ -544,6 +544,7 @@ Tree.createTree = function (dataRoot, hostModel, treeOptions) {
544
544
  structAttr: 'tree'
545
545
  });
546
546
  tree.update();
547
+ beforeLink && beforeLink(list);
547
548
  return tree;
548
549
  };
549
550
  /**
@@ -35,6 +35,7 @@ var normalizeToArray = _model.normalizeToArray;
35
35
  var _sourceHelper = require("./sourceHelper");
36
36
 
37
37
  var guessOrdinal = _sourceHelper.guessOrdinal;
38
+ var BE_ORDINAL = _sourceHelper.BE_ORDINAL;
38
39
 
39
40
  var Source = require("../Source");
40
41
 
@@ -42,6 +43,8 @@ var _dimensionHelper = require("./dimensionHelper");
42
43
 
43
44
  var OTHER_DIMENSIONS = _dimensionHelper.OTHER_DIMENSIONS;
44
45
 
46
+ var DataDimensionInfo = require("../DataDimensionInfo");
47
+
45
48
  /*
46
49
  * Licensed to the Apache Software Foundation (ASF) under one
47
50
  * or more contributor license agreements. See the NOTICE file
@@ -69,8 +72,12 @@ var OTHER_DIMENSIONS = _dimensionHelper.OTHER_DIMENSIONS;
69
72
  /**
70
73
  * @see {module:echarts/test/ut/spec/data/completeDimensions}
71
74
  *
72
- * Complete the dimensions array, by user defined `dimension` and `encode`,
73
- * and guessing from the data structure.
75
+ * This method builds the relationship between:
76
+ * + "what the coord sys or series requires (see `sysDims`)",
77
+ * + "what the user defines (in `encode` and `dimensions`, see `opt.dimsDef` and `opt.encodeDef`)"
78
+ * + "what the data source provids (see `source`)".
79
+ *
80
+ * Some guess strategy will be adapted if user does not define something.
74
81
  * If no 'value' dimension specified, the first no-named dimension will be
75
82
  * named as 'value'.
76
83
  *
@@ -86,32 +93,20 @@ var OTHER_DIMENSIONS = _dimensionHelper.OTHER_DIMENSIONS;
86
93
  * @param {Array.<Object|string>} [opt.dimsDef] option.series.dimensions User defined dimensions
87
94
  * For example: ['asdf', {name, type}, ...].
88
95
  * @param {Object|HashMap} [opt.encodeDef] option.series.encode {x: 2, y: [3, 1], tooltip: [1, 2], label: 3}
96
+ * @param {Function} [opt.encodeDefaulter] Called if no `opt.encodeDef` exists.
97
+ * If not specified, auto find the next available data dim.
98
+ * param source {module:data/Source}
99
+ * param dimCount {number}
100
+ * return {Object} encode Never be `null/undefined`.
89
101
  * @param {string} [opt.generateCoord] Generate coord dim with the given name.
90
- * If not specified, extra dim names will be:
91
- * 'value', 'value0', 'value1', ...
102
+ * If not specified, extra dim names will be:
103
+ * 'value', 'value0', 'value1', ...
92
104
  * @param {number} [opt.generateCoordCount] By default, the generated dim name is `generateCoord`.
93
- * If `generateCoordCount` specified, the generated dim names will be:
94
- * `generateCoord` + 0, `generateCoord` + 1, ...
95
- * can be Infinity, indicate that use all of the remain columns.
105
+ * If `generateCoordCount` specified, the generated dim names will be:
106
+ * `generateCoord` + 0, `generateCoord` + 1, ...
107
+ * can be Infinity, indicate that use all of the remain columns.
96
108
  * @param {number} [opt.dimCount] If not specified, guess by the first data item.
97
- * @param {number} [opt.encodeDefaulter] If not specified, auto find the next available data dim.
98
- * @return {Array.<Object>} [{
99
- * name: string mandatory,
100
- * displayName: string, the origin name in dimsDef, see source helper.
101
- * If displayName given, the tooltip will displayed vertically.
102
- * coordDim: string mandatory,
103
- * coordDimIndex: number mandatory,
104
- * type: string optional,
105
- * otherDims: { never null/undefined
106
- * tooltip: number optional,
107
- * label: number optional,
108
- * itemName: number optional,
109
- * seriesName: number optional,
110
- * },
111
- * isExtraCoord: boolean true if coord is generated
112
- * (not specified in encode and not series specified)
113
- * other props ...
114
- * }]
109
+ * @return {Array.<module:data/DataDimensionInfo>}
115
110
  */
116
111
  function completeDimensions(sysDims, source, opt) {
117
112
  if (!Source.isInstance(source)) {
@@ -121,7 +116,6 @@ function completeDimensions(sysDims, source, opt) {
121
116
  opt = opt || {};
122
117
  sysDims = (sysDims || []).slice();
123
118
  var dimsDef = (opt.dimsDef || []).slice();
124
- var encodeDef = createHashMap(opt.encodeDef);
125
119
  var dataDimNameMap = createHashMap();
126
120
  var coordDimNameMap = createHashMap(); // var valueCandidate;
127
121
 
@@ -133,9 +127,7 @@ function completeDimensions(sysDims, source, opt) {
133
127
  name: dimsDef[i]
134
128
  });
135
129
  var userDimName = dimDefItem.name;
136
- var resultItem = result[i] = {
137
- otherDims: {}
138
- }; // Name will be applied later for avoiding duplication.
130
+ var resultItem = result[i] = new DataDimensionInfo(); // Name will be applied later for avoiding duplication.
139
131
 
140
132
  if (userDimName != null && dataDimNameMap.get(userDimName) == null) {
141
133
  // Only if `series.dimensions` is defined in option
@@ -147,8 +139,15 @@ function completeDimensions(sysDims, source, opt) {
147
139
 
148
140
  dimDefItem.type != null && (resultItem.type = dimDefItem.type);
149
141
  dimDefItem.displayName != null && (resultItem.displayName = dimDefItem.displayName);
150
- } // Set `coordDim` and `coordDimIndex` by `encodeDef` and normalize `encodeDef`.
142
+ }
143
+
144
+ var encodeDef = opt.encodeDef;
145
+
146
+ if (!encodeDef && opt.encodeDefaulter) {
147
+ encodeDef = opt.encodeDefaulter(source, dimCount);
148
+ }
151
149
 
150
+ encodeDef = createHashMap(encodeDef); // Set `coordDim` and `coordDimIndex` by `encodeDef` and normalize `encodeDef`.
152
151
 
153
152
  encodeDef.each(function (dataDims, coordDim) {
154
153
  dataDims = normalizeToArray(dataDims).slice(); // Note: It is allowed that `dataDims.length` is `0`, e.g., options is
@@ -249,7 +248,7 @@ function completeDimensions(sysDims, source, opt) {
249
248
  var extra = generateCoord || 'value'; // Set dim `name` and other `coordDim` and other props.
250
249
 
251
250
  for (var resultDimIdx = 0; resultDimIdx < dimCount; resultDimIdx++) {
252
- var resultItem = result[resultDimIdx] = result[resultDimIdx] || {};
251
+ var resultItem = result[resultDimIdx] = result[resultDimIdx] || new DataDimensionInfo();
253
252
  var coordDim = resultItem.coordDim;
254
253
 
255
254
  if (coordDim == null) {
@@ -265,7 +264,19 @@ function completeDimensions(sysDims, source, opt) {
265
264
 
266
265
  resultItem.name == null && (resultItem.name = genName(resultItem.coordDim, dataDimNameMap));
267
266
 
268
- if (resultItem.type == null && guessOrdinal(source, resultDimIdx, resultItem.name)) {
267
+ if (resultItem.type == null && (guessOrdinal(source, resultDimIdx, resultItem.name) === BE_ORDINAL.Must // Consider the case:
268
+ // {
269
+ // dataset: {source: [
270
+ // ['2001', 123],
271
+ // ['2002', 456],
272
+ // ...
273
+ // ['The others', 987],
274
+ // ]},
275
+ // series: {type: 'pie'}
276
+ // }
277
+ // The first colum should better be treated as a "ordinal" although it
278
+ // might not able to be detected as an "ordinal" by `guessOrdinal`.
279
+ || resultItem.isExtraCoord && (resultItem.otherDims.itemName != null || resultItem.otherDims.seriesName != null))) {
269
280
  resultItem.type = 'ordinal';
270
281
  }
271
282
  }
@@ -53,6 +53,7 @@ var completeDimensions = require("./completeDimensions");
53
53
  * @param {string} [opt.generateCoordCount]
54
54
  * @param {Array.<string|Object>} [opt.dimensionsDefine=source.dimensionsDefine] Overwrite source define.
55
55
  * @param {Object|HashMap} [opt.encodeDefine=source.encodeDefine] Overwrite source define.
56
+ * @param {Function} [opt.encodeDefaulter] Make default encode if user not specified.
56
57
  * @return {Array.<Object>} dimensionsInfo
57
58
  */
58
59
  function _default(source, opt) {
@@ -61,6 +62,7 @@ function _default(source, opt) {
61
62
  dimsDef: opt.dimensionsDefine || source.dimensionsDefine,
62
63
  encodeDef: opt.encodeDefine || source.encodeDefine,
63
64
  dimCount: opt.dimensionsCount,
65
+ encodeDefaulter: opt.encodeDefaulter,
64
66
  generateCoord: opt.generateCoord,
65
67
  generateCoordCount: opt.generateCoordCount
66
68
  });