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
@@ -181,7 +181,7 @@
181
181
  * @return {Array.<string>} dimensions on the axis.
182
182
  */
183
183
  coordDimToDataDim: function (coordDim) {
184
- return [coordDim];
184
+ return modelUtil.coordDimToDataDim(this.getData(), coordDim);
185
185
  },
186
186
 
187
187
  /**
@@ -191,7 +191,7 @@
191
191
  * @return {string}
192
192
  */
193
193
  dataDimToCoordDim: function (dataDim) {
194
- return dataDim;
194
+ return modelUtil.dataDimToCoordDim(this.getData(), dataDim);
195
195
  },
196
196
 
197
197
  /**
@@ -215,35 +215,46 @@
215
215
  */
216
216
  formatTooltip: function (dataIndex, multipleSeries, dataType) {
217
217
  function formatArrayValue(value) {
218
- var result = [];
219
-
220
- zrUtil.each(value, function (val, idx) {
221
- var dimInfo = data.getDimensionInfo(idx);
222
- var dimType = dimInfo && dimInfo.type;
223
- var valStr;
218
+ var vertially = zrUtil.reduce(value, function (vertially, val, idx) {
219
+ var dimItem = data.getDimensionInfo(idx);
220
+ return vertially |= dimItem.tooltip !== false && dimItem.tooltipName != null;
221
+ }, 0);
224
222
 
225
- if (dimType === 'ordinal') {
226
- valStr = val + '';
227
- }
228
- else if (dimType === 'time') {
229
- valStr = multipleSeries ? '' : formatUtil.formatTime('yyyy/MM/dd hh:mm:ss', val);
230
- }
231
- else {
232
- valStr = addCommas(val);
223
+ var result = [];
224
+ var tooltipDims = modelUtil.otherDimToDataDim(data, 'tooltip');
225
+
226
+ tooltipDims.length
227
+ ? zrUtil.each(tooltipDims, function (dimIdx) {
228
+ setEachItem(data.get(dimIdx, dataIndex), dimIdx);
229
+ })
230
+ // By default, all dims is used on tooltip.
231
+ : zrUtil.each(value, setEachItem);
232
+
233
+ function setEachItem(val, dimIdx) {
234
+ var dimInfo = data.getDimensionInfo(dimIdx);
235
+ // If `dimInfo.tooltip` is not set, show tooltip.
236
+ if (!dimInfo || dimInfo.otherDims.tooltip === false) {
237
+ return;
233
238
  }
239
+ var dimType = dimInfo.type;
240
+ var valStr = (vertially ? '- ' + (dimInfo.tooltipName || dimInfo.name) + ': ' : '')
241
+ + (dimType === 'ordinal'
242
+ ? val + ''
243
+ : dimType === 'time'
244
+ ? (multipleSeries ? '' : formatUtil.formatTime('yyyy/MM/dd hh:mm:ss', val))
245
+ : addCommas(val)
246
+ );
247
+ valStr && result.push(encodeHTML(valStr));
248
+ }
234
249
 
235
- valStr && result.push(valStr);
236
- });
237
-
238
- return result.join(', ');
250
+ return (vertially ? '<br/>' : '') + result.join(vertially ? '<br/>' : ', ');
239
251
  }
240
252
 
241
253
  var data = get(this, 'data');
242
254
 
243
255
  var value = this.getRawValue(dataIndex);
244
- var formattedValue = encodeHTML(
245
- zrUtil.isArray(value) ? formatArrayValue(value) : addCommas(value)
246
- );
256
+ var formattedValue = zrUtil.isArray(value)
257
+ ? formatArrayValue(value) : encodeHTML(addCommas(value));
247
258
  var name = data.getName(dataIndex);
248
259
 
249
260
  var color = data.getItemVisual(dataIndex, 'color');
@@ -252,8 +263,7 @@
252
263
  }
253
264
  color = color || 'transparent';
254
265
 
255
- var colorEl = '<span style="display:inline-block;margin-right:5px;'
256
- + 'border-radius:10px;width:9px;height:9px;background-color:' + encodeHTML(color) + '"></span>';
266
+ var colorEl = formatUtil.getTooltipMarker(color);
257
267
 
258
268
  var seriesName = this.name;
259
269
  // FIXME
@@ -261,14 +271,16 @@
261
271
  // Not show '-'
262
272
  seriesName = '';
263
273
  }
274
+ seriesName = seriesName
275
+ ? encodeHTML(seriesName) + (!multipleSeries ? '<br/>' : ': ')
276
+ : '';
264
277
  return !multipleSeries
265
- ? ((seriesName && encodeHTML(seriesName) + '<br />') + colorEl
278
+ ? seriesName + colorEl
266
279
  + (name
267
- ? encodeHTML(name) + ' : ' + formattedValue
280
+ ? encodeHTML(name) + ': ' + formattedValue
268
281
  : formattedValue
269
282
  )
270
- )
271
- : (colorEl + encodeHTML(this.name) + ' : ' + formattedValue);
283
+ : colorEl + seriesName + formattedValue;
272
284
  },
273
285
 
274
286
  /**
@@ -51,5 +51,8 @@
51
51
  // `progressiveThreshold`, otherwise hover will cause restart of progressive,
52
52
  // which is unexpected.
53
53
  // see example <echarts/test/heatmap-large.html>.
54
- hoverLayerThreshold: 3000
54
+ hoverLayerThreshold: 3000,
55
+
56
+ // See: module:echarts/scale/Time
57
+ useUTC: false
55
58
  };
@@ -14,7 +14,8 @@
14
14
  scope = scope || this;
15
15
  var colorIdx = get(scope, 'colorIdx') || 0;
16
16
  var colorNameMap = get(scope, 'colorNameMap') || set(scope, 'colorNameMap', {});
17
- if (colorNameMap[name]) {
17
+ // Use `hasOwnProperty` to avoid conflict with Object.prototype.
18
+ if (colorNameMap.hasOwnProperty(name)) {
18
19
  return colorNameMap[name];
19
20
  }
20
21
  var colorPalette = this.get('color', true) || [];
@@ -1,10 +1,7 @@
1
1
 
2
2
 
3
3
  var textContain = require('zrender/lib/contain/text');
4
-
5
- function getShallow(model, path) {
6
- return model && model.getShallow(path);
7
- }
4
+ var graphicUtil = require('../../util/graphic');
8
5
 
9
6
  module.exports = {
10
7
  /**
@@ -22,15 +19,12 @@
22
19
  * @return {string}
23
20
  */
24
21
  getFont: function () {
25
- var ecModel = this.ecModel;
26
- var gTextStyleModel = ecModel && ecModel.getModel('textStyle');
27
- return [
28
- // FIXME in node-canvas fontWeight is before fontStyle
29
- this.getShallow('fontStyle') || getShallow(gTextStyleModel, 'fontStyle'),
30
- this.getShallow('fontWeight') || getShallow(gTextStyleModel, 'fontWeight'),
31
- (this.getShallow('fontSize') || getShallow(gTextStyleModel, 'fontSize') || 12) + 'px',
32
- this.getShallow('fontFamily') || getShallow(gTextStyleModel, 'fontFamily') || 'sans-serif'
33
- ].join(' ');
22
+ return graphicUtil.getFont({
23
+ fontStyle: this.getShallow('fontStyle'),
24
+ fontWeight: this.getShallow('fontWeight'),
25
+ fontSize: this.getShallow('fontSize'),
26
+ fontFamily: this.getShallow('fontFamily')
27
+ }, this.ecModel);
34
28
  },
35
29
 
36
30
  getTextRect: function (text) {
@@ -8,12 +8,10 @@
8
8
  var numberUtil = require('../util/number');
9
9
  var formatUtil = require('../util/format');
10
10
  var Scale = require('./Scale');
11
+ var helper = require('./helper');
11
12
 
12
- var mathFloor = Math.floor;
13
- var mathCeil = Math.ceil;
13
+ var roundNumber = numberUtil.round;
14
14
 
15
- var getPrecisionSafe = numberUtil.getPrecisionSafe;
16
- var roundingErrorFix = numberUtil.round;
17
15
  /**
18
16
  * @alias module:echarts/coord/scale/Interval
19
17
  * @constructor
@@ -49,8 +47,10 @@
49
47
  * Get interval
50
48
  */
51
49
  getInterval: function () {
52
- if (!this._interval) {
53
- this.niceTicks();
50
+ if (__DEV__) {
51
+ if (this._interval == null) {
52
+ throw new Error('`nice` should be called firstly' );
53
+ }
54
54
  }
55
55
  return this._interval;
56
56
  },
@@ -69,43 +69,14 @@
69
69
  * @return {Array.<number>}
70
70
  */
71
71
  getTicks: function () {
72
- if (!this._interval) {
73
- this.niceTicks();
74
- }
75
- var interval = this._interval;
76
- var extent = this._extent;
77
- var ticks = [];
78
-
79
- // Consider this case: using dataZoom toolbox, zoom and zoom.
80
- var safeLimit = 10000;
81
-
82
- if (interval) {
83
- var niceExtent = this._niceExtent;
84
- var precision = this._intervalPrecision = getPrecisionSafe(interval);
85
- // FIXME
86
- precision += 2;
87
-
88
- if (extent[0] < niceExtent[0]) {
89
- ticks.push(extent[0]);
90
- }
91
- var tick = niceExtent[0];
92
-
93
- while (tick <= niceExtent[1]) {
94
- ticks.push(tick);
95
- // Avoid rounding error
96
- tick = roundingErrorFix(tick + interval, precision);
97
- if (ticks.length > safeLimit) {
98
- return [];
99
- }
100
- }
101
- // Consider this case: the last item of ticks is smaller
102
- // than niceExtent[1] and niceExtent[1] === extent[1].
103
- if (extent[1] > (ticks.length ? ticks[ticks.length - 1] : niceExtent[1])) {
104
- ticks.push(extent[1]);
72
+ if (__DEV__) {
73
+ if (this._interval == null) {
74
+ throw new Error('`nice` should be called firstly' );
105
75
  }
106
76
  }
107
-
108
- return ticks;
77
+ return helper.intervalScaleGetTicks(
78
+ this._interval, this._extent, this._niceExtent, this._intervalPrecision
79
+ );
109
80
  },
110
81
 
111
82
  /**
@@ -125,15 +96,27 @@
125
96
  * @param {Object} [opt]
126
97
  * @param {number|string} [opt.precision] If 'auto', use nice presision.
127
98
  * @param {boolean} [opt.pad] returns 1.50 but not 1.5 if precision is 2.
128
- * @return {number}
99
+ * @return {string}
129
100
  */
130
101
  getLabel: function (data, opt) {
102
+ if (data == null) {
103
+ return '';
104
+ }
105
+
131
106
  var precision = opt && opt.precision;
132
- if (data != null && precision != null) {
107
+
108
+ if (precision == null) {
109
+ precision = numberUtil.getPrecisionSafe(data) || 0;
110
+ }
111
+ else if (precision === 'auto') {
133
112
  // Should be more precise then tick.
134
- precision === 'auto' && (precision = this._intervalPrecision + 2);
135
- data = roundingErrorFix(data, precision, opt && opt.pad);
113
+ precision = this._intervalPrecision;
136
114
  }
115
+
116
+ // (1) If `precision` is set, 12.005 should be display as '12.00500'.
117
+ // (2) Use roundNumber (toFixed) to avoid scientific notation like '3.5e-7'.
118
+ data = roundNumber(data, precision, true);
119
+
137
120
  return formatUtil.addCommas(data);
138
121
  },
139
122
 
@@ -141,8 +124,9 @@
141
124
  * Update interval and extent of intervals for nice ticks
142
125
  *
143
126
  * @param {number} [splitNumber = 5] Desired number of ticks
127
+ * @param {number} [minInterval]
144
128
  */
145
- niceTicks: function (splitNumber) {
129
+ niceTicks: function (splitNumber, minInterval) {
146
130
  splitNumber = splitNumber || 5;
147
131
  var extent = this._extent;
148
132
  var span = extent[1] - extent[0];
@@ -156,36 +140,22 @@
156
140
  extent.reverse();
157
141
  }
158
142
 
159
- // From "Nice Numbers for Graph Labels" of Graphic Gems
160
- // var niceSpan = numberUtil.nice(span, false);
161
- var step = roundingErrorFix(
162
- numberUtil.nice(span / splitNumber, true),
163
- Math.max(
164
- getPrecisionSafe(extent[0]),
165
- getPrecisionSafe(extent[1])
166
- // extent may be [0, 1], and step should have 1 more digits.
167
- // To make it safe we add 2 more digits
168
- ) + 2
169
- );
170
-
171
- var precision = getPrecisionSafe(step) + 2;
172
- // Niced extent inside original extent
173
- var niceExtent = [
174
- roundingErrorFix(mathCeil(extent[0] / step) * step, precision),
175
- roundingErrorFix(mathFloor(extent[1] / step) * step, precision)
176
- ];
143
+ var result = helper.intervalScaleNiceTicks(extent, splitNumber, minInterval);
177
144
 
178
- this._interval = step;
179
- this._niceExtent = niceExtent;
145
+ this._intervalPrecision = result.intervalPrecision;
146
+ this._interval = result.interval;
147
+ this._niceExtent = result.niceTickExtent;
180
148
  },
181
149
 
182
150
  /**
183
151
  * Nice extent.
184
- * @param {number} [splitNumber = 5] Given approx tick number
185
- * @param {boolean} [fixMin=false]
186
- * @param {boolean} [fixMax=false]
152
+ * @param {Object} opt
153
+ * @param {number} [opt.splitNumber = 5] Given approx tick number
154
+ * @param {boolean} [opt.fixMin=false]
155
+ * @param {boolean} [opt.fixMax=false]
156
+ * @param {boolean} [opt.minInterval=false]
187
157
  */
188
- niceExtent: function (splitNumber, fixMin, fixMax) {
158
+ niceExtent: function (opt) {
189
159
  var extent = this._extent;
190
160
  // If extent start and end are same, expand them
191
161
  if (extent[0] === extent[1]) {
@@ -197,7 +167,7 @@
197
167
  // Plus data are all 100 and axis extent are [100, 100].
198
168
  // Extend to the both side will cause expanded max is larger than fixed max.
199
169
  // So only expand to the smaller side.
200
- if (!fixMax) {
170
+ if (!opt.fixMax) {
201
171
  extent[1] += expandSize / 2;
202
172
  extent[0] -= expandSize / 2;
203
173
  }
@@ -216,16 +186,16 @@
216
186
  extent[1] = 1;
217
187
  }
218
188
 
219
- this.niceTicks(splitNumber);
189
+ this.niceTicks(opt.splitNumber, opt.minInterval);
220
190
 
221
191
  // var extent = this._extent;
222
192
  var interval = this._interval;
223
193
 
224
- if (!fixMin) {
225
- extent[0] = roundingErrorFix(mathFloor(extent[0] / interval) * interval);
194
+ if (!opt.fixMin) {
195
+ extent[0] = roundNumber(Math.floor(extent[0] / interval) * interval);
226
196
  }
227
- if (!fixMax) {
228
- extent[1] = roundingErrorFix(mathCeil(extent[1] / interval) * interval);
197
+ if (!opt.fixMax) {
198
+ extent[1] = roundNumber(Math.ceil(extent[1] / interval) * interval);
229
199
  }
230
200
  }
231
201
  });
package/lib/scale/Log.js CHANGED
@@ -158,16 +158,14 @@
158
158
 
159
159
  /**
160
160
  * Nice extent.
161
- * @param {number} [approxTickNum = 10] Given approx tick number
162
- * @param {boolean} [fixMin=false]
163
- * @param {boolean} [fixMax=false]
161
+ * @override
164
162
  */
165
- niceExtent: function (splitNumber, fixMin, fixMax) {
166
- intervalScaleProto.niceExtent.call(this, splitNumber, fixMin, fixMax);
163
+ niceExtent: function (opt) {
164
+ intervalScaleProto.niceExtent.call(this, opt);
167
165
 
168
166
  var originalScale = this._originalScale;
169
- originalScale.__fixMin = fixMin;
170
- originalScale.__fixMax = fixMax;
167
+ originalScale.__fixMin = opt.fixMin;
168
+ originalScale.__fixMax = opt.fixMax;
171
169
  }
172
170
 
173
171
  });
@@ -6,7 +6,12 @@
6
6
 
7
7
  var clazzUtil = require('../util/clazz');
8
8
 
9
- function Scale() {
9
+ /**
10
+ * @param {Object} [setting]
11
+ */
12
+ function Scale(setting) {
13
+ this._setting = setting || {};
14
+
10
15
  /**
11
16
  * Extent
12
17
  * @type {Array.<number>}
@@ -39,6 +44,10 @@
39
44
  return val;
40
45
  };
41
46
 
47
+ scaleProto.getSetting = function (name) {
48
+ return this._setting[name];
49
+ };
50
+
42
51
  scaleProto.contain = function (val) {
43
52
  var extent = this._extent;
44
53
  return val >= extent[0] && val <= extent[1];
package/lib/scale/Time.js CHANGED
@@ -5,9 +5,20 @@
5
5
 
6
6
 
7
7
 
8
+ // [About UTC and local time zone]:
9
+ // In most cases, `number.parseDate` will treat input data string as local time
10
+ // (except time zone is specified in time string). And `format.formateTime` returns
11
+ // local time by default. option.useUTC is false by default. This design have
12
+ // concidered these common case:
13
+ // (1) Time that is persistent in server is in UTC, but it is needed to be diplayed
14
+ // in local time by default.
15
+ // (2) By default, the input data string (e.g., '2011-01-02') should be displayed
16
+ // as its original time, without any time difference.
17
+
8
18
  var zrUtil = require('zrender/lib/core/util');
9
19
  var numberUtil = require('../util/number');
10
20
  var formatUtil = require('../util/format');
21
+ var scaleHelper = require('./helper');
11
22
 
12
23
  var IntervalScale = require('./Interval');
13
24
 
@@ -41,17 +52,21 @@
41
52
  var TimeScale = IntervalScale.extend({
42
53
  type: 'time',
43
54
 
44
- // Overwrite
55
+ /**
56
+ * @override
57
+ */
45
58
  getLabel: function (val) {
46
59
  var stepLvl = this._stepLvl;
47
60
 
48
61
  var date = new Date(val);
49
62
 
50
- return formatUtil.formatTime(stepLvl[0], date);
63
+ return formatUtil.formatTime(stepLvl[0], date, this.getSetting('useUTC'));
51
64
  },
52
65
 
53
- // Overwrite
54
- niceExtent: function (approxTickNum, fixMin, fixMax) {
66
+ /**
67
+ * @override
68
+ */
69
+ niceExtent: function (opt) {
55
70
  var extent = this._extent;
56
71
  // If extent start and end are same, expand them
57
72
  if (extent[0] === extent[1]) {
@@ -66,21 +81,25 @@
66
81
  extent[0] = extent[1] - ONE_DAY;
67
82
  }
68
83
 
69
- this.niceTicks(approxTickNum);
84
+ this.niceTicks(opt.splitNumber);
70
85
 
71
86
  // var extent = this._extent;
72
87
  var interval = this._interval;
73
88
 
74
- if (!fixMin) {
89
+ if (!opt.fixMin) {
75
90
  extent[0] = numberUtil.round(mathFloor(extent[0] / interval) * interval);
76
91
  }
77
- if (!fixMax) {
92
+ if (!opt.fixMax) {
78
93
  extent[1] = numberUtil.round(mathCeil(extent[1] / interval) * interval);
79
94
  }
80
95
  },
81
96
 
82
- // Overwrite
97
+ /**
98
+ * @override
99
+ */
83
100
  niceTicks: function (approxTickNum) {
101
+ var timezoneOffset = this.getSetting('useUTC')
102
+ ? 0 : numberUtil.getTimezoneOffset() * 60 * 1000;
84
103
  approxTickNum = approxTickNum || 10;
85
104
 
86
105
  var extent = this._extent;
@@ -103,10 +122,12 @@
103
122
  }
104
123
 
105
124
  var niceExtent = [
106
- mathCeil(extent[0] / interval) * interval,
107
- mathFloor(extent[1] / interval) * interval
125
+ Math.round(mathCeil((extent[0] - timezoneOffset) / interval) * interval + timezoneOffset),
126
+ Math.round(mathFloor((extent[1] - timezoneOffset)/ interval) * interval + timezoneOffset)
108
127
  ];
109
128
 
129
+ scaleHelper.fixExtent(niceExtent, extent);
130
+
110
131
  this._stepLvl = level;
111
132
  // Interval will be used in getTicks
112
133
  this._interval = interval;
@@ -151,10 +172,11 @@
151
172
  ];
152
173
 
153
174
  /**
175
+ * @param {module:echarts/model/Model}
154
176
  * @return {module:echarts/scale/Time}
155
177
  */
156
- TimeScale.create = function () {
157
- return new TimeScale();
178
+ TimeScale.create = function (model) {
179
+ return new TimeScale({useUTC: model.ecModel.get('useUTC')});
158
180
  };
159
181
 
160
182
  module.exports = TimeScale;
@@ -0,0 +1,93 @@
1
+ /**
2
+ * For testable.
3
+ */
4
+
5
+
6
+ var numberUtil = require('../util/number');
7
+
8
+ var roundNumber = numberUtil.round;
9
+
10
+ var helper = {};
11
+
12
+ /**
13
+ * @param {Array.<number>} extent Both extent[0] and extent[1] should be valid number.
14
+ * Should be extent[0] < extent[1].
15
+ * @param {number} splitNumber splitNumber should be >= 1.
16
+ * @param {number} [minInterval]
17
+ * @return {Object} {interval, intervalPrecision, niceTickExtent}
18
+ */
19
+ helper.intervalScaleNiceTicks = function (extent, splitNumber, minInterval) {
20
+ var result = {};
21
+ var span = extent[1] - extent[0];
22
+
23
+ var interval = result.interval = numberUtil.nice(span / splitNumber, true);
24
+ if (minInterval != null && interval < minInterval) {
25
+ interval = result.interval = minInterval;
26
+ }
27
+ // Tow more digital for tick.
28
+ var precision = result.intervalPrecision = numberUtil.getPrecisionSafe(interval) + 2;
29
+ // Niced extent inside original extent
30
+ var niceTickExtent = result.niceTickExtent = [
31
+ roundNumber(Math.ceil(extent[0] / interval) * interval, precision),
32
+ roundNumber(Math.floor(extent[1] / interval) * interval, precision)
33
+ ];
34
+
35
+ helper.fixExtent(niceTickExtent, extent);
36
+
37
+ return result;
38
+ };
39
+
40
+ function clamp(niceTickExtent, idx, extent) {
41
+ niceTickExtent[idx] = Math.max(Math.min(niceTickExtent[idx], extent[1]), extent[0]);
42
+ }
43
+
44
+ // In some cases (e.g., splitNumber is 1), niceTickExtent may be out of extent.
45
+ helper.fixExtent = function (niceTickExtent, extent) {
46
+ !isFinite(niceTickExtent[0]) && (niceTickExtent[0] = extent[0]);
47
+ !isFinite(niceTickExtent[1]) && (niceTickExtent[1] = extent[1]);
48
+ clamp(niceTickExtent, 0, extent);
49
+ clamp(niceTickExtent, 1, extent);
50
+ if (niceTickExtent[0] > niceTickExtent[1]) {
51
+ niceTickExtent[0] = niceTickExtent[1];
52
+ }
53
+ };
54
+
55
+ helper.intervalScaleGetTicks = function (interval, extent, niceTickExtent, intervalPrecision) {
56
+ var ticks = [];
57
+
58
+ // If interval is 0, return [];
59
+ if (!interval) {
60
+ return ticks;
61
+ }
62
+
63
+ // Consider this case: using dataZoom toolbox, zoom and zoom.
64
+ var safeLimit = 10000;
65
+
66
+ if (extent[0] < niceTickExtent[0]) {
67
+ ticks.push(extent[0]);
68
+ }
69
+ var tick = niceTickExtent[0];
70
+
71
+ while (tick <= niceTickExtent[1]) {
72
+ ticks.push(tick);
73
+ // Avoid rounding error
74
+ tick = roundNumber(tick + interval, intervalPrecision);
75
+ if (tick === ticks[ticks.length - 1]) {
76
+ // Consider out of safe float point, e.g.,
77
+ // -3711126.9907707 + 2e-10 === -3711126.9907707
78
+ break;
79
+ }
80
+ if (ticks.length > safeLimit) {
81
+ return [];
82
+ }
83
+ }
84
+ // Consider this case: the last item of ticks is smaller
85
+ // than niceTickExtent[1] and niceTickExtent[1] === extent[1].
86
+ if (extent[1] > (ticks.length ? ticks[ticks.length - 1] : niceTickExtent[1])) {
87
+ ticks.push(extent[1]);
88
+ }
89
+
90
+ return ticks;
91
+ };
92
+
93
+ module.exports = helper;
@@ -5,9 +5,11 @@
5
5
  var textContain = require('zrender/lib/contain/text');
6
6
 
7
7
  var formatUtil = {};
8
+
8
9
  /**
9
10
  * 每三位默认加,格式化
10
- * @type {string|number} x
11
+ * @param {string|number} x
12
+ * @return {string}
11
13
  */
12
14
  formatUtil.addCommas = function (x) {
13
15
  if (isNaN(x)) {
@@ -127,6 +129,18 @@
127
129
  return tpl;
128
130
  };
129
131
 
132
+ /**
133
+ * @param {string} color
134
+ * @param {string} [extraCssText]
135
+ * @return {string}
136
+ */
137
+ formatUtil.getTooltipMarker = function (color, extraCssText) {
138
+ return color
139
+ ? '<span style="display:inline-block;margin-right:5px;'
140
+ + 'border-radius:10px;width:9px;height:9px;background-color:'
141
+ + formatUtil.encodeHTML(color) + ';' + (extraCssText || '') + '"></span>'
142
+ : '';
143
+ };
130
144
 
131
145
  /**
132
146
  * @param {string} str
@@ -141,15 +155,12 @@
141
155
  * ISO Date format
142
156
  * @param {string} tpl
143
157
  * @param {number} value
144
- * @param {boolean} [isLocal=false] Default use UTC
145
- * Why default UTC? In most case, time provided by user is
146
- * understood in UTC. For example, new Date('2012-01-01')
147
- * or a string '2012-01-01' or a timestamp. So it is
148
- * recommended to format time in UTC.
149
- * (see `echarts/util/number.js#parseDate`);
158
+ * @param {boolean} [isUTC=false] Default in local time.
159
+ * see `module:echarts/scale/Time`
160
+ * and `module:echarts/util/number#parseDate`.
150
161
  * @inner
151
162
  */
152
- formatUtil.formatTime = function (tpl, value, isLocal) {
163
+ formatUtil.formatTime = function (tpl, value, isUTC) {
153
164
  if (tpl === 'week'
154
165
  || tpl === 'month'
155
166
  || tpl === 'quarter'
@@ -160,7 +171,7 @@
160
171
  }
161
172
 
162
173
  var date = numberUtil.parseDate(value);
163
- var utc = isLocal ? '' : 'UTC';
174
+ var utc = isUTC ? 'UTC' : '';
164
175
  var y = date['get' + utc + 'FullYear']();
165
176
  var M = date['get' + utc + 'Month']() + 1;
166
177
  var d = date['get' + utc + 'Date']();