echarts 3.5.1 → 3.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 (261) hide show
  1. package/LICENSE +21 -18
  2. package/README.md +10 -0
  3. package/dist/echarts.common.js +11010 -9830
  4. package/dist/echarts.common.min.js +13 -13
  5. package/dist/echarts.js +13291 -10852
  6. package/dist/echarts.min.js +22 -21
  7. package/dist/echarts.simple.js +9904 -8990
  8. package/dist/echarts.simple.min.js +9 -10
  9. package/index.js +1 -0
  10. package/lib/ExtensionAPI.js +2 -4
  11. package/lib/chart/bar/BarView.js +141 -49
  12. package/lib/chart/bar/BaseBarSeries.js +2 -6
  13. package/lib/chart/bar.js +1 -0
  14. package/lib/chart/boxplot/BoxplotSeries.js +1 -1
  15. package/lib/chart/boxplot/boxplotLayout.js +23 -7
  16. package/lib/chart/candlestick/CandlestickSeries.js +3 -22
  17. package/lib/chart/candlestick/candlestickLayout.js +23 -7
  18. package/lib/chart/custom.js +442 -0
  19. package/lib/chart/funnel/funnelLayout.js +10 -3
  20. package/lib/chart/gauge/GaugeView.js +1 -1
  21. package/lib/chart/graph/GraphView.js +15 -9
  22. package/lib/chart/graph/categoryVisual.js +3 -2
  23. package/lib/chart/heatmap/HeatmapLayer.js +1 -1
  24. package/lib/chart/heatmap/HeatmapView.js +75 -73
  25. package/lib/chart/helper/Symbol.js +8 -31
  26. package/lib/chart/helper/createListFromArray.js +15 -10
  27. package/lib/chart/helper/labelHelper.js +48 -0
  28. package/lib/chart/helper/whiskerBoxCommon.js +25 -44
  29. package/lib/chart/map/mapDataStatistic.js +9 -8
  30. package/lib/chart/parallel/ParallelSeries.js +2 -0
  31. package/lib/chart/parallel/ParallelView.js +13 -12
  32. package/lib/chart/parallel/parallelVisual.js +9 -1
  33. package/lib/chart/pie/pieLayout.js +25 -17
  34. package/lib/chart/radar/RadarSeries.js +1 -1
  35. package/lib/chart/sankey/sankeyLayout.js +1 -1
  36. package/lib/chart/scatter/ScatterSeries.js +2 -3
  37. package/lib/chart/themeRiver/ThemeRiverSeries.js +6 -5
  38. package/lib/chart/themeRiver/themeRiverVisual.js +1 -1
  39. package/lib/chart/treemap/TreemapSeries.js +3 -3
  40. package/lib/chart/treemap/TreemapView.js +1 -1
  41. package/lib/chart/treemap/treemapLayout.js +6 -1
  42. package/lib/component/axis/AxisBuilder.js +53 -34
  43. package/lib/component/axis/ParallelAxisView.js +45 -37
  44. package/lib/component/axisPointer/AxisPointerModel.js +1 -1
  45. package/lib/component/axisPointer/BaseAxisPointer.js +20 -15
  46. package/lib/component/axisPointer/CartesianAxisPointer.js +9 -6
  47. package/lib/component/axisPointer/PolarAxisPointer.js +10 -8
  48. package/lib/component/axisPointer/SingleAxisPointer.js +11 -7
  49. package/lib/component/axisPointer/axisTrigger.js +87 -72
  50. package/lib/component/axisPointer/viewHelper.js +6 -3
  51. package/lib/component/axisPointer.js +2 -2
  52. package/lib/component/brush/BrushModel.js +6 -4
  53. package/lib/component/brush/BrushView.js +1 -1
  54. package/lib/component/brush/visualEncoding.js +6 -4
  55. package/lib/component/calendar/CalendarView.js +5 -5
  56. package/lib/component/dataZoom/AxisProxy.js +76 -13
  57. package/lib/component/dataZoom/DataZoomModel.js +21 -5
  58. package/lib/component/dataZoom/InsideZoomModel.js +4 -1
  59. package/lib/component/dataZoom/InsideZoomView.js +17 -27
  60. package/lib/component/dataZoom/SliderZoomView.js +63 -26
  61. package/lib/component/dataZoom/roams.js +9 -4
  62. package/lib/component/graphic.js +13 -12
  63. package/lib/component/helper/BrushController.js +75 -114
  64. package/lib/component/helper/BrushTargetManager.js +16 -8
  65. package/lib/component/helper/MapDraw.js +25 -11
  66. package/lib/component/helper/RoamController.js +111 -139
  67. package/lib/component/helper/brushHelper.js +25 -213
  68. package/lib/component/helper/cursorHelper.js +21 -0
  69. package/lib/component/helper/roamHelper.js +54 -0
  70. package/lib/component/helper/selectableMixin.js +7 -7
  71. package/lib/component/helper/sliderMove.js +66 -37
  72. package/lib/component/legend/LegendView.js +6 -6
  73. package/lib/component/legend/legendAction.js +1 -1
  74. package/lib/component/marker/MarkAreaView.js +3 -6
  75. package/lib/component/marker/MarkLineView.js +3 -5
  76. package/lib/component/marker/MarkPointView.js +3 -5
  77. package/lib/component/marker/MarkerView.js +10 -12
  78. package/lib/component/marker/markerHelper.js +1 -1
  79. package/lib/component/parallel.js +94 -29
  80. package/lib/component/polar.js +5 -0
  81. package/lib/component/timeline/SliderTimelineView.js +1 -1
  82. package/lib/component/toolbox/feature/Brush.js +7 -0
  83. package/lib/component/toolbox/feature/DataZoom.js +17 -4
  84. package/lib/component/tooltip/TooltipView.js +92 -20
  85. package/lib/component/visualMap/ContinuousView.js +6 -4
  86. package/lib/coord/Axis.js +34 -2
  87. package/lib/coord/axisDefault.js +4 -1
  88. package/lib/coord/axisHelper.js +32 -26
  89. package/lib/coord/axisModelCommonMixin.js +1 -1
  90. package/lib/coord/calendar/Calendar.js +14 -17
  91. package/lib/coord/calendar/prepareCustom.js +31 -0
  92. package/lib/coord/cartesian/Axis2D.js +0 -12
  93. package/lib/coord/cartesian/Cartesian2D.js +1 -0
  94. package/lib/coord/cartesian/Grid.js +5 -2
  95. package/lib/coord/cartesian/prepareCustom.js +36 -0
  96. package/lib/coord/geo/Geo.js +9 -14
  97. package/lib/coord/geo/GeoModel.js +5 -5
  98. package/lib/coord/geo/geoCreator.js +3 -3
  99. package/lib/coord/geo/parseGeoJson.js +11 -4
  100. package/lib/coord/geo/prepareCustom.js +36 -0
  101. package/lib/coord/parallel/Parallel.js +225 -101
  102. package/lib/coord/parallel/ParallelModel.js +7 -1
  103. package/lib/coord/polar/Polar.js +2 -1
  104. package/lib/coord/polar/prepareCustom.js +53 -0
  105. package/lib/coord/single/Single.js +9 -8
  106. package/lib/coord/single/SingleAxis.js +0 -27
  107. package/lib/coord/single/prepareCustom.js +33 -0
  108. package/lib/data/DataDiffer.js +2 -1
  109. package/lib/data/Graph.js +11 -7
  110. package/lib/data/List.js +59 -20
  111. package/lib/data/helper/completeDimensions.js +184 -23
  112. package/lib/echarts.js +68 -36
  113. package/lib/helper.js +1 -8
  114. package/lib/layout/barGrid.js +91 -19
  115. package/lib/layout/barPolar.js +286 -0
  116. package/lib/layout/points.js +22 -16
  117. package/lib/model/Global.js +34 -31
  118. package/lib/model/Series.js +41 -29
  119. package/lib/model/globalDefault.js +4 -1
  120. package/lib/model/mixin/colorPalette.js +2 -1
  121. package/lib/model/mixin/textStyle.js +7 -13
  122. package/lib/scale/Interval.js +46 -76
  123. package/lib/scale/Log.js +5 -7
  124. package/lib/scale/Scale.js +10 -1
  125. package/lib/scale/Time.js +34 -12
  126. package/lib/scale/helper.js +93 -0
  127. package/lib/util/format.js +20 -9
  128. package/lib/util/graphic.js +70 -8
  129. package/lib/util/layout.js +7 -3
  130. package/lib/util/model.js +63 -7
  131. package/lib/util/number.js +59 -19
  132. package/lib/util/throttle.js +14 -3
  133. package/map/js/world.js +1 -1
  134. package/map/json/world.json +1 -1
  135. package/package.json +3 -3
  136. package/src/ExtensionAPI.js +2 -4
  137. package/src/chart/bar/BarView.js +141 -49
  138. package/src/chart/bar/BaseBarSeries.js +2 -6
  139. package/src/chart/bar.js +1 -0
  140. package/src/chart/boxplot/BoxplotSeries.js +1 -1
  141. package/src/chart/boxplot/boxplotLayout.js +23 -7
  142. package/src/chart/candlestick/CandlestickSeries.js +3 -22
  143. package/src/chart/candlestick/candlestickLayout.js +23 -7
  144. package/src/chart/custom.js +442 -0
  145. package/src/chart/funnel/funnelLayout.js +10 -4
  146. package/src/chart/gauge/GaugeView.js +1 -1
  147. package/src/chart/graph/GraphView.js +15 -9
  148. package/src/chart/graph/categoryVisual.js +3 -2
  149. package/src/chart/heatmap/HeatmapLayer.js +1 -1
  150. package/src/chart/heatmap/HeatmapView.js +75 -73
  151. package/src/chart/helper/Symbol.js +8 -31
  152. package/src/chart/helper/createListFromArray.js +15 -10
  153. package/src/chart/helper/labelHelper.js +49 -0
  154. package/src/chart/helper/whiskerBoxCommon.js +25 -44
  155. package/src/chart/map/mapDataStatistic.js +9 -8
  156. package/src/chart/parallel/ParallelSeries.js +2 -0
  157. package/src/chart/parallel/ParallelView.js +13 -12
  158. package/src/chart/parallel/parallelVisual.js +9 -1
  159. package/src/chart/pie/pieLayout.js +25 -17
  160. package/src/chart/radar/RadarSeries.js +1 -1
  161. package/src/chart/sankey/sankeyLayout.js +1 -1
  162. package/src/chart/scatter/ScatterSeries.js +2 -3
  163. package/src/chart/themeRiver/ThemeRiverSeries.js +6 -5
  164. package/src/chart/themeRiver/themeRiverVisual.js +1 -1
  165. package/src/chart/treemap/TreemapSeries.js +3 -3
  166. package/src/chart/treemap/TreemapView.js +1 -1
  167. package/src/chart/treemap/treemapLayout.js +6 -1
  168. package/src/component/axis/AxisBuilder.js +53 -34
  169. package/src/component/axis/ParallelAxisView.js +45 -37
  170. package/src/component/axisPointer/AxisPointerModel.js +1 -1
  171. package/src/component/axisPointer/BaseAxisPointer.js +20 -15
  172. package/src/component/axisPointer/CartesianAxisPointer.js +9 -6
  173. package/src/component/axisPointer/PolarAxisPointer.js +10 -8
  174. package/src/component/axisPointer/SingleAxisPointer.js +11 -7
  175. package/src/component/axisPointer/axisTrigger.js +87 -72
  176. package/src/component/axisPointer/viewHelper.js +6 -3
  177. package/src/component/axisPointer.js +2 -2
  178. package/src/component/brush/BrushModel.js +6 -4
  179. package/src/component/brush/BrushView.js +1 -1
  180. package/src/component/brush/visualEncoding.js +6 -4
  181. package/src/component/calendar/CalendarView.js +5 -5
  182. package/src/component/dataZoom/AxisProxy.js +76 -13
  183. package/src/component/dataZoom/DataZoomModel.js +21 -5
  184. package/src/component/dataZoom/InsideZoomModel.js +4 -1
  185. package/src/component/dataZoom/InsideZoomView.js +17 -27
  186. package/src/component/dataZoom/SliderZoomView.js +63 -26
  187. package/src/component/dataZoom/roams.js +9 -4
  188. package/src/component/graphic.js +13 -12
  189. package/src/component/helper/BrushController.js +75 -114
  190. package/src/component/helper/BrushTargetManager.js +16 -8
  191. package/src/component/helper/MapDraw.js +25 -11
  192. package/src/component/helper/RoamController.js +111 -139
  193. package/src/component/helper/brushHelper.js +41 -0
  194. package/src/component/helper/cursorHelper.js +22 -0
  195. package/src/component/helper/roamHelper.js +55 -0
  196. package/src/component/helper/selectableMixin.js +7 -7
  197. package/src/component/helper/sliderMove.js +66 -37
  198. package/src/component/legend/LegendView.js +6 -6
  199. package/src/component/legend/legendAction.js +1 -1
  200. package/src/component/marker/MarkAreaView.js +3 -6
  201. package/src/component/marker/MarkLineView.js +3 -5
  202. package/src/component/marker/MarkPointView.js +3 -5
  203. package/src/component/marker/MarkerView.js +10 -12
  204. package/src/component/marker/markerHelper.js +1 -1
  205. package/src/component/parallel.js +94 -29
  206. package/src/component/polar.js +5 -0
  207. package/src/component/timeline/SliderTimelineView.js +1 -1
  208. package/src/component/toolbox/feature/Brush.js +7 -0
  209. package/src/component/toolbox/feature/DataZoom.js +17 -4
  210. package/src/component/tooltip/TooltipView.js +92 -20
  211. package/src/component/visualMap/ContinuousView.js +6 -4
  212. package/src/coord/Axis.js +34 -2
  213. package/src/coord/axisDefault.js +4 -1
  214. package/src/coord/axisHelper.js +32 -26
  215. package/src/coord/axisModelCommonMixin.js +1 -1
  216. package/src/coord/calendar/Calendar.js +14 -17
  217. package/src/coord/calendar/prepareCustom.js +32 -0
  218. package/src/coord/cartesian/Axis2D.js +0 -12
  219. package/src/coord/cartesian/Cartesian2D.js +1 -0
  220. package/src/coord/cartesian/Grid.js +5 -2
  221. package/src/coord/cartesian/prepareCustom.js +37 -0
  222. package/src/coord/geo/Geo.js +9 -14
  223. package/src/coord/geo/GeoModel.js +5 -5
  224. package/src/coord/geo/geoCreator.js +3 -3
  225. package/src/coord/geo/parseGeoJson.js +11 -4
  226. package/src/coord/geo/prepareCustom.js +37 -0
  227. package/src/coord/parallel/Parallel.js +225 -101
  228. package/src/coord/parallel/ParallelModel.js +7 -1
  229. package/src/coord/polar/Polar.js +2 -1
  230. package/src/coord/polar/prepareCustom.js +54 -0
  231. package/src/coord/single/Single.js +9 -8
  232. package/src/coord/single/SingleAxis.js +0 -27
  233. package/src/coord/single/prepareCustom.js +34 -0
  234. package/src/data/DataDiffer.js +2 -1
  235. package/src/data/Graph.js +11 -7
  236. package/src/data/List.js +59 -20
  237. package/src/data/helper/completeDimensions.js +184 -23
  238. package/src/echarts.js +68 -36
  239. package/src/helper.js +1 -8
  240. package/src/layout/barGrid.js +91 -19
  241. package/src/layout/barPolar.js +287 -0
  242. package/src/layout/points.js +22 -16
  243. package/src/model/Global.js +34 -31
  244. package/src/model/Series.js +41 -29
  245. package/src/model/globalDefault.js +4 -1
  246. package/src/model/mixin/colorPalette.js +2 -1
  247. package/src/model/mixin/textStyle.js +7 -13
  248. package/src/scale/Interval.js +46 -76
  249. package/src/scale/Log.js +5 -7
  250. package/src/scale/Scale.js +10 -1
  251. package/src/scale/Time.js +34 -12
  252. package/src/scale/helper.js +94 -0
  253. package/src/util/format.js +20 -9
  254. package/src/util/graphic.js +70 -8
  255. package/src/util/layout.js +7 -3
  256. package/src/util/model.js +63 -7
  257. package/src/util/number.js +59 -19
  258. package/src/util/throttle.js +14 -3
  259. package/src/coord/cartesian/axisLabelInterval.js +0 -26
  260. package/theme/default.js +0 -23
  261. package/theme/halloween.js +0 -528
package/src/echarts.js CHANGED
@@ -176,7 +176,7 @@ define(function (require) {
176
176
  * @type {module:echarts/ExtensionAPI}
177
177
  * @private
178
178
  */
179
- this._api = new ExtensionAPI(this, this._coordSysMgr);
179
+ this._api = createExtensionAPI(this);
180
180
 
181
181
  Eventful.call(this);
182
182
 
@@ -276,14 +276,7 @@ define(function (require) {
276
276
  ecModel.init(null, null, theme, optionManager);
277
277
  }
278
278
 
279
- // FIXME
280
- // ugly
281
- this.__lastOnlyGraphic = !!(option && option.graphic);
282
- zrUtil.each(option, function (o, mainType) {
283
- mainType !== 'graphic' && (this.__lastOnlyGraphic = false);
284
- }, this);
285
-
286
- this._model.setOption(option, optionPreprocessorFuncs, this.__lastOnlyGraphic);
279
+ this._model.setOption(option, optionPreprocessorFuncs);
287
280
 
288
281
  if (lazyUpdate) {
289
282
  this[OPTION_UPDATED] = {silent: silent};
@@ -809,21 +802,7 @@ define(function (require) {
809
802
 
810
803
  prepareView.call(this, 'chart', ecModel);
811
804
 
812
- // FIXME
813
- // ugly
814
- if (this.__lastOnlyGraphic) {
815
- each(this._componentsViews, function (componentView) {
816
- var componentModel = componentView.__model;
817
- if (componentModel && componentModel.mainType === 'graphic') {
818
- componentView.render(componentModel, ecModel, this._api, payload);
819
- updateZ(componentModel, componentView);
820
- }
821
- }, this);
822
- this.__lastOnlyGraphic = false;
823
- }
824
- else {
825
- updateMethods.update.call(this, payload);
826
- }
805
+ updateMethods.update.call(this, payload);
827
806
  }
828
807
  };
829
808
 
@@ -1140,7 +1119,7 @@ define(function (require) {
1140
1119
  }
1141
1120
 
1142
1121
  // Consider: id same and type changed.
1143
- var viewId = model.id + '_' + model.type;
1122
+ var viewId = '_ec_' + model.id + '_' + model.type;
1144
1123
  var view = viewMap[viewId];
1145
1124
  if (!view) {
1146
1125
  var classType = parseClassType(model.type);
@@ -1160,10 +1139,13 @@ define(function (require) {
1160
1139
  }
1161
1140
  }
1162
1141
 
1163
- model.__viewId = viewId;
1142
+ model.__viewId = view.__id = viewId;
1164
1143
  view.__alive = true;
1165
- view.__id = viewId;
1166
1144
  view.__model = model;
1145
+ view.group.__ecComponentInfo = {
1146
+ mainType: model.mainType,
1147
+ index: model.componentIndex
1148
+ };
1167
1149
  }, this);
1168
1150
 
1169
1151
  for (var i = 0; i < viewList.length;) {
@@ -1173,6 +1155,7 @@ define(function (require) {
1173
1155
  view.dispose(ecModel, this._api);
1174
1156
  viewList.splice(i, 1);
1175
1157
  delete viewMap[view.__id];
1158
+ view.__id = view.group.__ecComponentInfo = null;
1176
1159
  }
1177
1160
  else {
1178
1161
  i++;
@@ -1202,7 +1185,8 @@ define(function (require) {
1202
1185
  var data = series.getData();
1203
1186
  if (stack && data.type === 'list') {
1204
1187
  var previousStack = stackedDataMap[stack];
1205
- if (previousStack) {
1188
+ // Avoid conflict with Object.prototype
1189
+ if (stackedDataMap.hasOwnProperty(stack) && previousStack) {
1206
1190
  data.stackedOn = previousStack;
1207
1191
  }
1208
1192
  stackedDataMap[stack] = data;
@@ -1344,6 +1328,7 @@ define(function (require) {
1344
1328
  echartsProto.clear = function () {
1345
1329
  this.setOption({ series: [] }, true);
1346
1330
  };
1331
+
1347
1332
  /**
1348
1333
  * Dispose instance
1349
1334
  */
@@ -1390,6 +1375,7 @@ define(function (require) {
1390
1375
  });
1391
1376
  }
1392
1377
  }
1378
+
1393
1379
  /**
1394
1380
  * Update chart progressive and blend.
1395
1381
  * @param {module:echarts/model/Series|module:echarts/model/Component} model
@@ -1432,6 +1418,7 @@ define(function (require) {
1432
1418
  }
1433
1419
  });
1434
1420
  }
1421
+
1435
1422
  /**
1436
1423
  * @param {module:echarts/model/Series|module:echarts/model/Component} model
1437
1424
  * @param {module:echarts/view/Component|module:echarts/view/Chart} view
@@ -1447,6 +1434,26 @@ define(function (require) {
1447
1434
  }
1448
1435
  });
1449
1436
  }
1437
+
1438
+ function createExtensionAPI(ecInstance) {
1439
+ var coordSysMgr = ecInstance._coordSysMgr;
1440
+ return zrUtil.extend(new ExtensionAPI(ecInstance), {
1441
+ // Inject methods
1442
+ getCoordinateSystems: zrUtil.bind(
1443
+ coordSysMgr.getCoordinateSystems, coordSysMgr
1444
+ ),
1445
+ getComponentByElement: function (el) {
1446
+ while (el) {
1447
+ var modelInfo = el.__ecComponentInfo;
1448
+ if (modelInfo != null) {
1449
+ return ecInstance._model.getComponent(modelInfo.mainType, modelInfo.index);
1450
+ }
1451
+ el = el.parent;
1452
+ }
1453
+ }
1454
+ });
1455
+ }
1456
+
1450
1457
  /**
1451
1458
  * @type {Object} key: actionType.
1452
1459
  * @inner
@@ -1501,6 +1508,7 @@ define(function (require) {
1501
1508
  var idBase = new Date() - 0;
1502
1509
  var groupIdBase = new Date() - 0;
1503
1510
  var DOM_ATTRIBUTE_KEY = '_echarts_instance_';
1511
+
1504
1512
  /**
1505
1513
  * @alias module:echarts
1506
1514
  */
@@ -1508,9 +1516,9 @@ define(function (require) {
1508
1516
  /**
1509
1517
  * @type {number}
1510
1518
  */
1511
- version: '3.5.1',
1519
+ version: '3.6.0',
1512
1520
  dependencies: {
1513
- zrender: '3.4.1'
1521
+ zrender: '3.5.0'
1514
1522
  }
1515
1523
  };
1516
1524
 
@@ -1577,9 +1585,21 @@ define(function (require) {
1577
1585
  + echarts.dependencies.zrender + '+'
1578
1586
  );
1579
1587
  }
1588
+
1580
1589
  if (!dom) {
1581
1590
  throw new Error('Initialize failed: invalid dom.');
1582
1591
  }
1592
+ }
1593
+
1594
+ var existInstance = echarts.getInstanceByDom(dom);
1595
+ if (existInstance) {
1596
+ if (__DEV__) {
1597
+ console.warn('There is a chart instance already initialized on the dom.');
1598
+ }
1599
+ return existInstance;
1600
+ }
1601
+
1602
+ if (__DEV__) {
1583
1603
  if (zrUtil.isDom(dom)
1584
1604
  && dom.nodeName.toUpperCase() !== 'CANVAS'
1585
1605
  && (
@@ -1595,8 +1615,12 @@ define(function (require) {
1595
1615
  chart.id = 'ec_' + idBase++;
1596
1616
  instances[chart.id] = chart;
1597
1617
 
1598
- dom.setAttribute &&
1618
+ if (dom.setAttribute) {
1599
1619
  dom.setAttribute(DOM_ATTRIBUTE_KEY, chart.id);
1620
+ }
1621
+ else {
1622
+ dom[DOM_ATTRIBUTE_KEY] = chart.id;
1623
+ }
1600
1624
 
1601
1625
  enableConnect(chart);
1602
1626
 
@@ -1644,12 +1668,13 @@ define(function (require) {
1644
1668
  * @param {module:echarts~ECharts|HTMLDomElement|string} chart
1645
1669
  */
1646
1670
  echarts.dispose = function (chart) {
1647
- if (zrUtil.isDom(chart)) {
1648
- chart = echarts.getInstanceByDom(chart);
1649
- }
1650
- else if (typeof chart === 'string') {
1671
+ if (typeof chart === 'string') {
1651
1672
  chart = instances[chart];
1652
1673
  }
1674
+ else if (!(chart instanceof ECharts)){
1675
+ // Try to treat as dom
1676
+ chart = echarts.getInstanceByDom(chart);
1677
+ }
1653
1678
  if ((chart instanceof ECharts) && !chart.isDisposed()) {
1654
1679
  chart.dispose();
1655
1680
  }
@@ -1660,9 +1685,16 @@ define(function (require) {
1660
1685
  * @return {echarts~ECharts}
1661
1686
  */
1662
1687
  echarts.getInstanceByDom = function (dom) {
1663
- var key = dom.getAttribute(DOM_ATTRIBUTE_KEY);
1688
+ var key;
1689
+ if (dom.getAttribute) {
1690
+ key = dom.getAttribute(DOM_ATTRIBUTE_KEY);
1691
+ }
1692
+ else {
1693
+ key = dom[DOM_ATTRIBUTE_KEY];
1694
+ }
1664
1695
  return instances[key];
1665
1696
  };
1697
+
1666
1698
  /**
1667
1699
  * @param {string} key
1668
1700
  * @return {echarts~ECharts}
package/src/helper.js CHANGED
@@ -19,14 +19,7 @@ define(function (require) {
19
19
  },
20
20
 
21
21
  /**
22
- * Complete the dimensions array guessed from the data structure.
23
- * @param {Array.<string>} dimensions Necessary dimensions, like ['x', 'y']
24
- * @param {Array} data Data list. [[1, 2, 3], [2, 3, 4]]
25
- * @param {Object} [opt]
26
- * @param {Array.<string>} [opt.defaultNames] Default names to fill not necessary dimensions, like ['value']
27
- * @param {string} [opt.extraPrefix] Prefix of name when filling the left dimensions.
28
- * @param {number} [opt.dimCount] If not specified, guess by the first data item.
29
- * @return {Array.<string>}
22
+ * @see {module:echarts/data/helper/completeDimensions}
30
23
  */
31
24
  completeDimensions: require('./data/helper/completeDimensions'),
32
25
 
@@ -6,29 +6,96 @@ define(function(require) {
6
6
  var numberUtil = require('../util/number');
7
7
  var parsePercent = numberUtil.parsePercent;
8
8
 
9
+ var STACK_PREFIX = '__ec_stack_';
10
+
9
11
  function getSeriesStackId(seriesModel) {
10
- return seriesModel.get('stack') || '__ec_stack_' + seriesModel.seriesIndex;
12
+ return seriesModel.get('stack') || STACK_PREFIX + seriesModel.seriesIndex;
11
13
  }
12
14
 
13
15
  function getAxisKey(axis) {
14
16
  return axis.dim + axis.index;
15
17
  }
16
18
 
17
- function calBarWidthAndOffset(barSeries, api) {
18
- // Columns info on each category axis. Key is cartesian name
19
- var columnsMap = {};
19
+ /**
20
+ * @param {Object} opt
21
+ * @param {module:echarts/coord/Axis} opt.axis Only support category axis currently.
22
+ * @param {number} opt.count Positive interger.
23
+ * @param {number} [opt.barWidth]
24
+ * @param {number} [opt.barMaxWidth]
25
+ * @param {number} [opt.barGap]
26
+ * @param {number} [opt.barCategoryGap]
27
+ * @return {Object} {width, offset, offsetCenter} If axis.type is not 'category', return undefined.
28
+ */
29
+ function getLayoutOnAxis(opt, api) {
30
+ var params = [];
31
+ var baseAxis = opt.axis;
32
+ var axisKey = 'axis0';
33
+
34
+ if (baseAxis.type !== 'category') {
35
+ return;
36
+ }
37
+ var bandWidth = baseAxis.getBandWidth();
38
+
39
+ for (var i = 0; i < opt.count || 0; i++) {
40
+ params.push(zrUtil.defaults({
41
+ bandWidth: bandWidth,
42
+ axisKey: axisKey,
43
+ stackId: STACK_PREFIX + i
44
+ }, opt));
45
+ }
46
+ var widthAndOffsets = doCalBarWidthAndOffset(params, api);
47
+
48
+ var result = [];
49
+ for (var i = 0; i < opt.count; i++) {
50
+ var item = widthAndOffsets[axisKey][STACK_PREFIX + i];
51
+ item.offsetCenter = item.offset + item.width / 2;
52
+ result.push(item);
53
+ }
20
54
 
21
- zrUtil.each(barSeries, function (seriesModel, idx) {
55
+ return result;
56
+ }
57
+
58
+ function calBarWidthAndOffset(barSeries, api) {
59
+ var seriesInfoList = zrUtil.map(barSeries, function (seriesModel) {
22
60
  var data = seriesModel.getData();
23
61
  var cartesian = seriesModel.coordinateSystem;
24
-
25
62
  var baseAxis = cartesian.getBaseAxis();
26
63
  var axisExtent = baseAxis.getExtent();
27
64
  var bandWidth = baseAxis.type === 'category'
28
65
  ? baseAxis.getBandWidth()
29
66
  : (Math.abs(axisExtent[1] - axisExtent[0]) / data.count());
30
67
 
31
- var columnsOnAxis = columnsMap[getAxisKey(baseAxis)] || {
68
+ var barWidth = parsePercent(
69
+ seriesModel.get('barWidth'), bandWidth
70
+ );
71
+ var barMaxWidth = parsePercent(
72
+ seriesModel.get('barMaxWidth'), bandWidth
73
+ );
74
+ var barGap = seriesModel.get('barGap');
75
+ var barCategoryGap = seriesModel.get('barCategoryGap');
76
+
77
+ return {
78
+ bandWidth: bandWidth,
79
+ barWidth: barWidth,
80
+ barMaxWidth: barMaxWidth,
81
+ barGap: barGap,
82
+ barCategoryGap: barCategoryGap,
83
+ axisKey: getAxisKey(baseAxis),
84
+ stackId: getSeriesStackId(seriesModel)
85
+ };
86
+ });
87
+
88
+ return doCalBarWidthAndOffset(seriesInfoList, api);
89
+ }
90
+
91
+ function doCalBarWidthAndOffset(seriesInfoList, api) {
92
+ // Columns info on each category axis. Key is cartesian name
93
+ var columnsMap = {};
94
+
95
+ zrUtil.each(seriesInfoList, function (seriesInfo, idx) {
96
+ var axisKey = seriesInfo.axisKey;
97
+ var bandWidth = seriesInfo.bandWidth;
98
+ var columnsOnAxis = columnsMap[axisKey] || {
32
99
  bandWidth: bandWidth,
33
100
  remainedWidth: bandWidth,
34
101
  autoWidthCount: 0,
@@ -37,9 +104,9 @@ define(function(require) {
37
104
  stacks: {}
38
105
  };
39
106
  var stacks = columnsOnAxis.stacks;
40
- columnsMap[getAxisKey(baseAxis)] = columnsOnAxis;
107
+ columnsMap[axisKey] = columnsOnAxis;
41
108
 
42
- var stackId = getSeriesStackId(seriesModel);
109
+ var stackId = seriesInfo.stackId;
43
110
 
44
111
  if (!stacks[stackId]) {
45
112
  columnsOnAxis.autoWidthCount++;
@@ -49,29 +116,24 @@ define(function(require) {
49
116
  maxWidth: 0
50
117
  };
51
118
 
52
- var barWidth = parsePercent(
53
- seriesModel.get('barWidth'), bandWidth
54
- );
55
- var barMaxWidth = parsePercent(
56
- seriesModel.get('barMaxWidth'), bandWidth
57
- );
58
- var barGap = seriesModel.get('barGap');
59
- var barCategoryGap = seriesModel.get('barCategoryGap');
60
-
61
119
  // Caution: In a single coordinate system, these barGrid attributes
62
120
  // will be shared by series. Consider that they have default values,
63
121
  // only the attributes set on the last series will work.
64
122
  // Do not change this fact unless there will be a break change.
65
123
 
66
124
  // TODO
125
+ var barWidth = seriesInfo.barWidth;
67
126
  if (barWidth && !stacks[stackId].width) {
68
127
  barWidth = Math.min(columnsOnAxis.remainedWidth, barWidth);
69
128
  stacks[stackId].width = barWidth;
70
129
  columnsOnAxis.remainedWidth -= barWidth;
71
130
  }
72
131
 
132
+ var barMaxWidth = seriesInfo.barMaxWidth;
73
133
  barMaxWidth && (stacks[stackId].maxWidth = barMaxWidth);
134
+ var barGap = seriesInfo.barGap;
74
135
  (barGap != null) && (columnsOnAxis.gap = barGap);
136
+ var barCategoryGap = seriesInfo.barCategoryGap;
75
137
  (barCategoryGap != null) && (columnsOnAxis.categoryGap = barCategoryGap);
76
138
  });
77
139
 
@@ -95,8 +157,11 @@ define(function(require) {
95
157
  // Find if any auto calculated bar exceeded maxBarWidth
96
158
  zrUtil.each(stacks, function (column, stack) {
97
159
  var maxWidth = column.maxWidth;
98
- if (!column.width && maxWidth && maxWidth < autoWidth) {
160
+ if (maxWidth && maxWidth < autoWidth) {
99
161
  maxWidth = Math.min(maxWidth, remainedWidth);
162
+ if (column.width) {
163
+ maxWidth = Math.min(maxWidth, column.width);
164
+ }
100
165
  remainedWidth -= maxWidth;
101
166
  column.width = maxWidth;
102
167
  autoWidthCount--;
@@ -158,6 +223,11 @@ define(function(require) {
158
223
 
159
224
  ecModel.eachSeriesByType(seriesType, function (seriesModel) {
160
225
 
226
+ // Check series coordinate, do layout for cartesian2d only
227
+ if (seriesModel.coordinateSystem.type !== 'cartesian2d') {
228
+ return;
229
+ }
230
+
161
231
  var data = seriesModel.getData();
162
232
  var cartesian = seriesModel.coordinateSystem;
163
233
  var baseAxis = cartesian.getBaseAxis();
@@ -244,5 +314,7 @@ define(function(require) {
244
314
  }, this);
245
315
  }
246
316
 
317
+ barLayoutGrid.getLayoutOnAxis = getLayoutOnAxis;
318
+
247
319
  return barLayoutGrid;
248
320
  });