diff --git a/doc/asset/js/echartsExample.js b/doc/asset/js/echartsExample.js index 642d1247f7506034555d9c5d61fb26c6a5364d32..297e12ae58282b575c1569c6d96aca035af24cff 100644 --- a/doc/asset/js/echartsExample.js +++ b/doc/asset/js/echartsExample.js @@ -61,7 +61,8 @@ function needMap() { var href = location.href; return href.indexOf('map') != -1 || href.indexOf('mix3') != -1 - || href.indexOf('mix5') != -1; + || href.indexOf('mix5') != -1 + || href.indexOf('dataRange') != -1; } diff --git a/doc/example/dataRange.html b/doc/example/dataRange.html index 3f12bd514f04ba9e133ed9dad9a51fced66ccf40..807759dc41c7b3bc58c5b8ef35bd5ad655fca00b 100644 --- a/doc/example/dataRange.html +++ b/doc/example/dataRange.html @@ -75,13 +75,19 @@ dataRangeStyle = [ // 0 { min: 0, - max: 2000 + max: 2000, + formatter : function(v, v2){ + if (v2 < 1000) { return '低于' + v2} + else if (v > 1000) { return '高于' + v} + else { return '中' } + } }, // 1 { orient: 'horizontal', // 'vertical' min: 0, - max: 2000 + max: 2000, + formatter : '{value} 到 {value2}' }, // 2 { @@ -128,7 +134,12 @@ dataRangeStyle = [ { calculable : true, min: 0, - max: 2000 + max: 2000, + formatter : function(v) { + if (v > 1500) {return v + ' (高)'} + else if (v < 500) {return v + ' (低)'} + else {return v + ' (中)'}; + } }, // 9 { diff --git a/doc/example/map15.html b/doc/example/map15.html index 639ffdd64464251952b69687a7b3937bd2cd3418..44d7e90aba18a95afef903bd69c867371f6fb61c 100644 --- a/doc/example/map15.html +++ b/doc/example/map15.html @@ -286,14 +286,6 @@ option = { color: '#fff' } }, - dataRangde: { - min : 0, - max : 100, - color: ['#fff','#1e90ff'], - textStyle : { - color: '#fff' - } - }, toolbox: { show : true, orient : 'vertical', @@ -335,7 +327,7 @@ option = { geoCoord = placeList[len % placeList.length].geoCoord; data.push({ name : placeList[len % placeList.length].name + len, - value : 50, + value : 10, geoCoord : [ geoCoord[0] + Math.random() * 5 * -1, geoCoord[1] + Math.random() * 3 * -1 diff --git a/src/component/dataRange.js b/src/component/dataRange.js index 4b0da2d9379514c8d457e767bec02af9ef25df96..ad9ab3eecb0c967914958bccb2de7829f1c25d1e 100644 --- a/src/component/dataRange.js +++ b/src/component/dataRange.js @@ -42,6 +42,9 @@ define(function (require) { self._ondragend = function() { return self.__ondragend(); }; + self._dataRangeSelected = function(param) { + return self.__dataRangeSelected(param); + } this._selectedMap = {}; this._range = {}; @@ -334,17 +337,8 @@ define(function (require) { var font = this.getFont(this.dataRangeOption.textStyle); var textHeight = zrArea.getTextHeight('国', font); var textWidth = Math.max( - zrArea.getTextWidth( - this.dataRangeOption.max.toFixed( - this.dataRangeOption.precision - ), - font), - zrArea.getTextWidth( - this.dataRangeOption.min.toFixed( - this.dataRangeOption.precision - ), - font - ) + zrArea.getTextWidth(this._textFormat(this.dataRangeOption.max), font), + zrArea.getTextWidth(this._textFormat(this.dataRangeOption.min), font) ) + 2; var pointListStart; @@ -504,9 +498,7 @@ define(function (require) { this._startShape = { style : { pointList : pointListStart, - text : this.dataRangeOption.max.toFixed( - this.dataRangeOption.precision - ), + text : this._textFormat(this.dataRangeOption.max), textX : textXStart, textY : textYStart, color : this.getColor(this.dataRangeOption.max), @@ -525,9 +517,7 @@ define(function (require) { this._endShape = { style : { pointList : pointListEnd, - text : this.dataRangeOption.min.toFixed( - this.dataRangeOption.precision - ), + text : this._textFormat(this.dataRangeOption.min), textX : textXEnd, textY : textYEnd, color : this.getColor(this.dataRangeOption.min), @@ -1083,39 +1073,31 @@ define(function (require) { this._startShape.style.y - this._startShape.style._y ]; - if (this.dataRangeOption.precision === 0) { - this._startShape.style.text = Math.round( - this._gap * this._range.start + this.dataRangeOption.min - ) + ''; - } else { - this._startShape.style.text =( - this._gap * this._range.start + this.dataRangeOption.min - ).toFixed(this.dataRangeOption.precision); - } - this._startShape.style.color - = this._startShape.highlightStyle.strokeColor - = this.getColor( + this._startShape.style.text = this._textFormat( this._gap * this._range.start + this.dataRangeOption.min ); + this._startShape.style.color + = this._startShape.highlightStyle.strokeColor + = this.getColor( + this._gap * this._range.start + this.dataRangeOption.min + ); + this._endShape.position = [ this._endShape.style.x - this._endShape.style._x, this._endShape.style.y - this._endShape.style._y ]; - if (this.dataRangeOption.precision === 0) { - this._endShape.style.text = Math.round( - this._gap * this._range.end + this.dataRangeOption.min - ) + ''; - } else { - this._endShape.style.text = ( - this._gap * this._range.end + this.dataRangeOption.min - ).toFixed(this.dataRangeOption.precision); - } - this._endShape.style.color = this._endShape.highlightStyle.strokeColor = this.getColor( + this._endShape.style.text = this._textFormat( this._gap * this._range.end + this.dataRangeOption.min ); + this._endShape.style.color + = this._endShape.highlightStyle.strokeColor + = this.getColor( + this._gap * this._range.end + this.dataRangeOption.min + ); + this.zr.modShape(this._startShape.id); this.zr.modShape(this._endShape.id); this.zr.modShape(this._startMask.id); @@ -1140,12 +1122,33 @@ define(function (require) { }, - _dataRangeSelected : function (param) { + __dataRangeSelected : function (param) { var idx = param.target._idx; this._selectedMap[idx] = !this._selectedMap[idx]; this.messageCenter.dispatch(ecConfig.EVENT.REFRESH); }, + _textFormat : function(valueStart, valueEnd) { + valueStart = valueStart.toFixed(this.dataRangeOption.precision); + valueEnd = typeof valueEnd != 'undefined' + ? valueEnd.toFixed(this.dataRangeOption.precision) : '' + if (this.dataRangeOption.formatter) { + if (typeof this.dataRangeOption.formatter == 'string') { + return this.dataRangeOption.formatter.replace('{value}', valueStart) + .replace('{value2}', valueEnd); + } + else if (typeof this.dataRangeOption.formatter == 'function') { + return this.dataRangeOption.formatter(valueStart, valueEnd); + } + } + + if (valueEnd != '') { + return valueStart + ' - ' + valueEnd; + } + + return valueStart; + }, + /** * 刷新 */ @@ -1200,9 +1203,10 @@ define(function (require) { for (var i = 0; i < splitNumber; i++) { this._selectedMap[i] = true; this._valueTextList.unshift( - (i * this._gap + this.dataRangeOption.min).toFixed(precision) - + ' - ' - + ((i + 1) * this._gap + this.dataRangeOption.min).toFixed(precision) + this._textFormat( + i * this._gap + this.dataRangeOption.min, + (i + 1) * this._gap + this.dataRangeOption.min + ) ); } } diff --git a/src/config.js b/src/config.js index 8ee14bada77928fdcdeb290d309a798671905dc9..de0dd14162ccf7d496ce940204a420ad6b537c87 100644 --- a/src/config.js +++ b/src/config.js @@ -130,6 +130,7 @@ define(function() { calculable: false, // 是否值域漫游,启用后无视splitNumber,线性渐变 realtime: true, color:['#006edd','#e0ffff'],//颜色 + //formatter: null, //text:['高','低'], // 文本,默认为数值文本 textStyle: { color: '#333' // 值域文字颜色