diff --git a/src/chart/funnel/FunnelSeries.js b/src/chart/funnel/FunnelSeries.js index f6efa8ffa41e8d0f980d7bab5a4837a493438ea1..f28e239d902c40f5fe1e836e7c3d378836aeffab 100644 --- a/src/chart/funnel/FunnelSeries.js +++ b/src/chart/funnel/FunnelSeries.js @@ -4,6 +4,7 @@ define(function(require) { var List = require('../../data/List'); var SeriesModel = require('../../model/Series'); + var modelUtil = require('../../util/model'); var FunnelSeries = SeriesModel.extend({ @@ -17,14 +18,8 @@ define(function(require) { this.legendDataProvider = function () { return this._dataBeforeProcessed; }; - // Extend labelLine emphasis - // this._defaultLabelLine(); - }, - - mergeOption: function (newOption) { - SeriesModel.prototype.mergeOption.call(this, newOption); - this._defaultLabelLine(); + this._defaultLabelLine(option); }, getInitialData: function (option, ecModel) { @@ -33,11 +28,10 @@ define(function(require) { return list; }, - _defaultLabelLine: function () { + _defaultLabelLine: function (option) { // Extend labelLine emphasis - this.defaultEmphasis('labelLine', ['show']); + modelUtil.defaultEmphasis(option.labelLine, ['show']); - var option = this.option; var labelLineNormalOpt = option.labelLine.normal; var labelLineEmphasisOpt = option.labelLine.emphasis; // Not show label line if `label.normal.show = false` diff --git a/src/chart/line/LineView.js b/src/chart/line/LineView.js index 97d46a15ba3bba43adea1abadcfed7426b45408e..ef5f198e65f16445fe2a386dc81f42ef487c3413 100644 --- a/src/chart/line/LineView.js +++ b/src/chart/line/LineView.js @@ -145,13 +145,13 @@ define(function(require) { ); } - // Always update, or it is wrong in the case turning on legend + // Always update, or it is wrong in the case turning on legend because points is not changed symbolDraw.updateData(data, api, isSymbolIgnore); // Stop symbol animation and sync with line points // FIXME performance? data.eachItemGraphicEl(function (el) { - el.stopAnimation(); + el.stopAnimation(true); }); // In the case data zoom triggerred refreshing frequently @@ -293,6 +293,7 @@ define(function(require) { /** * @private */ + // FIXME Two value axis _updateAnimation: function (data, stackedOnPoints, coordSys, api) { var polyline = this._polyline; var polygon = this._polygon; @@ -339,7 +340,7 @@ define(function(require) { } } - if (polyline.animators) { + if (polyline.animators && polyline.animators.length) { polyline.animators[0].during(function () { for (var i = 0; i < updatedDataInfo.length; i++) { var el = updatedDataInfo[i].el; diff --git a/src/chart/pie/PieSeries.js b/src/chart/pie/PieSeries.js index fb9135e9841d9a70179afdfbc91237a59de4dccf..a3ddd058bd116bdf5d31b20765999a6cbb99bde4 100644 --- a/src/chart/pie/PieSeries.js +++ b/src/chart/pie/PieSeries.js @@ -5,6 +5,7 @@ define(function(require) { var List = require('../../data/List'); var SeriesModel = require('../../model/Series'); var zrUtil = require('zrender/core/util'); + var modelUtil = require('../../util/model'); var dataSelectableMixin = require('../helper/dataSelectableMixin'); @@ -26,15 +27,13 @@ define(function(require) { this.updateSelectedMap(); - this._defaultLabelLine(); + this._defaultLabelLine(option); }, // Overwrite mergeOption: function (newOption) { seriesModelProto.mergeOption.call(this, newOption); this.updateSelectedMap(); - - this._defaultLabelLine(); }, getInitialData: function (option, ecModel) { @@ -54,11 +53,10 @@ define(function(require) { return params; }, - _defaultLabelLine: function () { + _defaultLabelLine: function (option) { // Extend labelLine emphasis - this.defaultEmphasis('labelLine', ['show']); + modelUtil.defaultEmphasis(option.labelLine, ['show']); - var option = this.option; var labelLineNormalOpt = option.labelLine.normal; var labelLineEmphasisOpt = option.labelLine.emphasis; // Not show label line if `label.normal.show = false` @@ -82,6 +80,8 @@ define(function(require) { minAngle: 0, // 选中是扇区偏移量 selectedOffset: 10, + + // If use strategy to avoid label overlapping avoidLabelOverlap: true, // 选择模式,默认关闭,可选single,multiple // selectedMode: false, diff --git a/src/chart/pie/PieView.js b/src/chart/pie/PieView.js index 7822640753630d8649a29468b2ede60e9dd9f666..bff36e7d03d81da894984cebcb809decacab43c1 100644 --- a/src/chart/pie/PieView.js +++ b/src/chart/pie/PieView.js @@ -93,6 +93,19 @@ define(function (require) { var piePieceProto = PiePiece.prototype; + function getLabelStyle(data, idx, state, labelModel) { + var textStyleModel = labelModel.getModel('textStyle'); + var position = labelModel.get('position'); + var isLabelInside = position === 'inside' || position === 'inner'; + return { + fill: textStyleModel.get('color') + || isLabelInside ? '#fff' : data.getItemVisual(idx, 'color'), + textFont: textStyleModel.getFont(), + text: data.hostModel.getFormattedLabel(idx, state) + || data.getName(idx) + }; + } + piePieceProto.updateData = function (data, idx, api, firstCreate) { var sector = this.childAt(0); @@ -167,17 +180,7 @@ define(function (require) { var labelLineModel = itemModel.getModel('labelLine.normal'); var labelLineHoverModel = itemModel.getModel('labelLine.emphasis'); - var textStyleModel = labelModel.getModel('textStyle'); - var labelPosition = labelModel.get('position'); - var isLabelInside = labelPosition === 'inside' || labelPosition === 'inner'; - - labelText.setStyle({ - fill: textStyleModel.get('color') - || isLabelInside ? '#fff' : visualColor, - text: seriesModel.getFormattedLabel(idx, 'normal') - || data.getName(idx), - textFont: textStyleModel.getFont() - }); + labelText.setStyle(getLabelStyle(data, idx, 'normal', labelModel)); labelText.ignore = labelText.normalIgnore = !labelModel.get('show'); labelText.hoverIgnore = !labelHoverModel.get('show'); @@ -189,7 +192,7 @@ define(function (require) { labelLine.setStyle({ stroke: visualColor }); - labelLine.setStyle(labelLineModel.getLineStyle()); + labelLine.setStyle(labelLineModel.getModel('lineStyle').getLineStyle()); sector.setStyle( zrUtil.extend( @@ -200,8 +203,8 @@ define(function (require) { ) ); sector.hoverStyle = itemStyleModel.getModel('emphasis').getItemStyle(); - labelText.hoverStyle = labelHoverModel.getModel('textStyle').getItemStyle(); - labelLine.hoverStyle = labelLineHoverModel.getLineStyle(); + labelText.hoverStyle = getLabelStyle(data, idx, 'emphasis', labelHoverModel); + labelLine.hoverStyle = labelLineHoverModel.getModel('lineStyle').getLineStyle(); graphic.setHoverStyle(this); diff --git a/src/chart/pie/labelLayout.js b/src/chart/pie/labelLayout.js index 112828273c843285408265fad6697855817724f8..2b56197a50d05e69297dd78e374c12ff1542ba17 100644 --- a/src/chart/pie/labelLayout.js +++ b/src/chart/pie/labelLayout.js @@ -216,7 +216,8 @@ define(function (require) { labelLayoutList.push(layout.label); }); - - !hasLabelRotate && avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight); + if (!hasLabelRotate && seriesModel.get('avoidLabelOverlap')) { + avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight); + } }; }); \ No newline at end of file diff --git a/src/component/marker/MarkPointView.js b/src/component/marker/MarkPointView.js index 33d20ffbe19a6897805da2eace815cdf696fe5ef..dfe9a5a2c9780af636e1da4a15158fcf357486a7 100644 --- a/src/component/marker/MarkPointView.js +++ b/src/component/marker/MarkPointView.js @@ -77,7 +77,7 @@ define(function (require) { } var mpData = createList(coordSys, seriesData, mpModel); - var dims = coordSys.dimensions; + var dims = coordSys && coordSys.dimensions; // Overwrite getRawValue // FIXME @@ -97,7 +97,7 @@ define(function (require) { if (xPx != null && yPx != null) { point = [xPx, yPx]; } - else { + else if (coordSys) { var x = mpData.get(dims[0], idx); var y = mpData.get(dims[1], idx); point = coordSys.dataToPoint([x, y]); @@ -129,7 +129,7 @@ define(function (require) { /** * @inner - * @param {module:echarts/coord/*} coordSys + * @param {module:echarts/coord/*} [coordSys] * @param {module:echarts/data/List} seriesData * @param {module:echarts/model/Model} mpModel */ diff --git a/src/component/marker/markerHelper.js b/src/component/marker/markerHelper.js index f1d56f2b24ab8362f3a01fd74b2f08f18ece1a59..ce33e4fadc148cdcf35b5bce070b7685bcc82867 100644 --- a/src/component/marker/markerHelper.js +++ b/src/component/marker/markerHelper.js @@ -62,10 +62,22 @@ define(function (require) { average: curry(markerTypeCalculatorWithExtent, 0.5) }; + /** + * Transform markPoint data item to format used in List by do the following + * 1. Calculate statistic like `max`, `min`, `average` + * 2. Convert `item.xAxis`, `item.yAxis` to `item.value` array + * @param {module:echarts/data/List} data + * @param {module:echarts/coord/*} [coordSys] + * @param {Object} item + * @return {Object} + */ var dataTransform = function (data, coordSys, item) { // 1. If not specify the position with pixel directly // 2. If value is not a data array. Which uses xAxis, yAxis to specify the value on each dimension - if (isNaN(item.x) || isNaN(item.y) && !zrUtil.isArray(item.value)) { + if (isNaN(item.x) || isNaN(item.y) + && !zrUtil.isArray(item.value) + && coordSys + ) { var valueAxisDim; var baseAxisDim; var valueAxis; @@ -113,11 +125,20 @@ define(function (require) { return item; }; - // Filter data which is out of coordinateSystem range + + /** + * Filter data which is out of coordinateSystem range + * [dataFilter description] + * @param {module:echarts/coord/*} [coordSys] + * @param {Array.} coordDataIdx + * @param {Object} item + * @return {boolean} + */ var dataFilter = function (coordSys, coordDataIdx, item) { var value = item.value; value = [value[coordDataIdx[0]], value[coordDataIdx[1]]]; - return coordSys.containData(value); + // Alwalys return true if there is no coordSys + return coordSys ? coordSys.containData(value) : true; }; return { diff --git a/src/data/List.js b/src/data/List.js index 8a405b3f9307cda6c36dda471ca685abfb80128e..775e74a2e19e7453863c6646b7f57ae7e72e4b6b 100644 --- a/src/data/List.js +++ b/src/data/List.js @@ -790,18 +790,17 @@ define(function (require) { /** * Create a data differ - * @param {module:echarts/data/List} oldList + * @param {module:echarts/data/List} otherList * @return {module:echarts/data/DataDiffer} */ - listProto.diff = function (oldList) { + listProto.diff = function (otherList) { var idList = this._idList; return new DataDiffer( - oldList ? oldList.indices : [], this.indices, function (idx) { + otherList ? otherList.indices : [], this.indices, function (idx) { return idList[idx] || (idx + ''); } ); }; - /** * Get visual property. * @param {string} key diff --git a/src/model/Series.js b/src/model/Series.js index e42b4f9476998c5bfc25a3eede2ddd67c672dabd..701b1a2ed507e8a178297f553c793d3a48c0b3ac 100644 --- a/src/model/Series.js +++ b/src/model/Series.js @@ -4,6 +4,7 @@ define(function(require) { var zrUtil = require('zrender/core/util'); var formatUtil = require('../util/format'); + var modelUtil = require('../util/model'); var ComponentModel = require('./Component'); var encodeHTML = formatUtil.encodeHTML; @@ -64,7 +65,7 @@ define(function(require) { zrUtil.merge(option, this.getDefaultOption()); // Default label emphasis `position` and `show` - this.defaultEmphasis('label'); + modelUtil.defaultEmphasis(option.label); }, mergeOption: function (newSeriesOption, ecModel) { @@ -76,25 +77,11 @@ define(function(require) { this._data = data; this._dataBeforeProcessed = data.cloneShallow(); } - - this.defaultEmphasis('label'); - }, - - /** - * Util for default emphasis option from normal option like `position` and `show` - * @param {string} optName - * @param {Array.} [subOpts=['position', 'show']] - */ - defaultEmphasis: function (optName, subOpts) { - var opt = this.get(optName); - if (opt && opt.normal) { - var emphasisOpt = opt.emphasis = opt.emphasis || {}; - - subOpts = subOpts || ['position', 'show']; - zrUtil.each(subOpts, function (subOptName) { - emphasisOpt[subOptName] = zrUtil.retrieve(emphasisOpt[subOptName], opt.normal[subOptName]); - }); - } + // FIXME + // Default label emphasis `position` and `show` + // Do it after option is merged. In case newSeriesOption only + // set the value in emphasis + // modelUtil.defaultNormalEmphasis(this.option.label); }, /** diff --git a/src/model/globalDefault.js b/src/model/globalDefault.js index e0897694ac0e0dd61e39feda53114adaef585ddc..6a4e17d8d1c0e5c4bc0ced5c00c0f25539e53106 100644 --- a/src/model/globalDefault.js +++ b/src/model/globalDefault.js @@ -18,7 +18,7 @@ define(function () { // 浅色 // color: ['#bcd3bb', '#e88f70', '#edc1a5', '#9dc5c8', '#e1e8c8', '#7b7c68', '#e5b5b5', '#f0b489', '#928ea8', '#bda29a'], // 深色 - color: ['#314656', '#61a0a8', '#c23531', '#dd8668', '#91c7ae', '#6e7074', '#61a0a8', '#bda29a', '#44525d', '#c4ccd3'], + color: ['#c23531', '#314656', '#61a0a8', '#dd8668', '#91c7ae', '#6e7074', '#61a0a8', '#bda29a', '#44525d', '#c4ccd3'], // color: ['#0088bb', '#a4d2aa', '#ea9695', '#eddf93', '#9bd6ec', '#f7c753', '#c78682', '#6bc3bc', '#e5362d', '#fbeabf'], // 默认需要 Grid 配置项 diff --git a/src/util/graphic.js b/src/util/graphic.js index 47b36a1e332cb5708c31d7c82fa35bf21b309f68..e491f2c20e797bec9a88c5061fa468369cd7e99b 100644 --- a/src/util/graphic.js +++ b/src/util/graphic.js @@ -302,15 +302,15 @@ define(function(require) { /** * Set text option in the style - * @param {Object} style + * @param {Object} textStyle * @param {module:echarts/model/Model} labelModel * @param {string} color */ - graphic.setText = function (style, labelModel, color) { + graphic.setText = function (textStyle, labelModel, color) { var labelPosition = labelModel.get('position') || 'inside'; var labelColor = labelPosition.indexOf('inside') >= 0 ? 'white' : color; var textStyleModel = labelModel.getModel('textStyle'); - zrUtil.extend(style, { + zrUtil.extend(textStyle, { textFont: textStyleModel.getFont(), textPosition: labelPosition, textFill: textStyleModel.get('color') || labelColor diff --git a/src/util/model.js b/src/util/model.js index 11bd7a0245ff9f412a73bd41da2b17b628cecb50..1d309de676d6d2fd385cd180b9d049d687e87cac 100644 --- a/src/util/model.js +++ b/src/util/model.js @@ -4,7 +4,7 @@ define(function(require) { var AXIS_DIMS = ['x', 'y', 'z', 'radius', 'angle']; - var util = {}; + var modelUtil = {}; /** * Create "each" method to iterate names. @@ -14,11 +14,11 @@ define(function(require) { * @param {Array.=} attrs * @return {Function} */ - util.createNameEach = function (names, attrs) { + modelUtil.createNameEach = function (names, attrs) { names = names.slice(); - var capitalNames = zrUtil.map(names, util.capitalFirst); + var capitalNames = zrUtil.map(names, modelUtil.capitalFirst); attrs = (attrs || []).slice(); - var capitalAttrs = zrUtil.map(attrs, util.capitalFirst); + var capitalAttrs = zrUtil.map(attrs, modelUtil.capitalFirst); return function (callback, context) { zrUtil.each(names, function (name, index) { @@ -36,7 +36,7 @@ define(function(require) { /** * @public */ - util.capitalFirst = function (str) { + modelUtil.capitalFirst = function (str) { return str ? str.charAt(0).toUpperCase() + str.substr(1) : str; }; @@ -54,14 +54,14 @@ define(function(require) { * } * @param {Object} context */ - util.eachAxisDim = util.createNameEach(AXIS_DIMS, ['axisIndex', 'axis', 'index']); + modelUtil.eachAxisDim = modelUtil.createNameEach(AXIS_DIMS, ['axisIndex', 'axis', 'index']); /** * If value is not array, then translate it to array. * @param {*} value * @return {Array} [value] or value */ - util.normalizeToArray = function (value) { + modelUtil.normalizeToArray = function (value) { return zrUtil.isArray(value) ? value : value == null @@ -80,7 +80,7 @@ define(function(require) { * @param {Function} edgeIdGetter Giving node and edgeType, return an array of edge id. * @return {Function} Input: sourceNode, Output: Like {nodes: [], dims: {}} */ - util.createLinkedNodesFinder = function (forEachNode, forEachEdgeType, edgeIdGetter) { + modelUtil.createLinkedNodesFinder = function (forEachNode, forEachEdgeType, edgeIdGetter) { return function (sourceNode) { var result = { @@ -139,5 +139,36 @@ define(function(require) { } }; - return util; + /** + * Sync default option between normal and emphasis like `position` and `show` + * In case some one will write code like + * label: { + * normal: { + * show: false + * }, + * emphasis: { + * show: true, + * position: 'outside', + * textStyle: { + * fontSize: 18 + * } + * } + * } + * @param {Object} opt + * @param {Array.} [subOpts=['position', 'show']] + */ + modelUtil.defaultEmphasis = function (opt, subOpts) { + if (opt) { + var emphasisOpt = opt.emphasis = opt.emphasis || {}; + var normalOpt = opt.normal = opt.normal || {}; + + subOpts = subOpts || ['position', 'show', 'textStyle']; + // Default emphasis option from normal + zrUtil.each(subOpts, function (subOptName) { + emphasisOpt[subOptName] = zrUtil.retrieve(emphasisOpt[subOptName], normalOpt[subOptName]); + }); + } + }; + + return modelUtil; }); \ No newline at end of file diff --git a/src/util/number.js b/src/util/number.js index 2f075fbd1adce8d4b84de98ce4b076617cf94585..a30ab56b1ec44ab9b1f08e7cb50d0081fcb642d9 100644 --- a/src/util/number.js +++ b/src/util/number.js @@ -85,7 +85,7 @@ define(function (require) { number.round = function (x) { // PENDING return +(+x).toFixed(12); - } + }; number.asc = function (arr) { arr.sort(function (a, b) { diff --git a/src/view/Chart.js b/src/view/Chart.js index e79ceb8f7de1866a3fb66b0f50e1625a02774708..bab2048791a245bf4947b7b644ba3e838cefc1db 100644 --- a/src/view/Chart.js +++ b/src/view/Chart.js @@ -97,14 +97,12 @@ define(function (require) { */ function elSetState(el, state) { if (el) { + el.trigger(state); if (el.type === 'group') { for (var i = 0; i < el.childCount(); i++) { elSetState(el.childAt(i), state); } } - else { - el.trigger(state); - } } } /**