提交 ae0db92d 编写于 作者: P pah100

Merge branch 'IevgenySp-feature'

此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -7,12 +7,12 @@
*/
define(function (require) {
var Base = require('./base');
// 图形依赖
var TextShape = require('zrender/shape/Text');
var LineShape = require('zrender/shape/Line');
var RectangleShape = require('zrender/shape/Rectangle');
var ecConfig = require('../config');
// 数值型坐标轴默认参数
ecConfig.valueAxis = {
......@@ -39,7 +39,7 @@ define(function (require) {
},
axisTick: { // 坐标轴小标记
show: false, // 属性show控制显示与否,默认不显示
inside: false, // 控制小标记是否在grid里
inside: false, // 控制小标记是否在grid里
length :5, // 属性length控制线长
lineStyle: { // 属性lineStyle控制线条样式
color: '#333',
......@@ -88,29 +88,29 @@ define(function (require) {
console.err('option.series.length == 0.');
return;
}
Base.call(this, ecTheme, messageCenter, zr, option, myChart);
this.series = series;
this.grid = this.component.grid;
for (var method in axisBase) {
this[method] = axisBase[method];
}
this.refresh(option, series);
}
ValueAxis.prototype = {
type: ecConfig.COMPONENT_TYPE_AXIS_VALUE,
_buildShape: function () {
this._hasData = false;
this._calculateValue();
if (!this._hasData || !this.option.show) {
return;
}
this.option.splitArea.show && this._buildSplitArea();
this.option.splitLine.show && this._buildSplitLine();
this.option.axisLine.show && this._buildAxisLine();
......@@ -135,9 +135,9 @@ define(function (require) {
if (this.isHorizontal()) {
// 横向
var yPosition = this.option.position === 'bottom'
? (tickOption.inside
? (tickOption.inside
? (this.grid.getYend() - length - 1) : (this.grid.getYend()) + 1)
: (tickOption.inside
: (tickOption.inside
? (this.grid.getY() + 1) : (this.grid.getY() - length - 1));
var x;
for (var i = 0; i < dataLength; i++) {
......@@ -163,9 +163,9 @@ define(function (require) {
else {
// 纵向
var xPosition = this.option.position === 'left'
? (tickOption.inside
? (tickOption.inside
? (this.grid.getX() + 1) : (this.grid.getX() - length - 1))
: (tickOption.inside
: (tickOption.inside
? (this.grid.getXend() - length - 1) : (this.grid.getXend() + 1));
var y;
......@@ -273,7 +273,7 @@ define(function (require) {
text: this._valueLabel[i],
textFont: this.getFont(textStyle),
textAlign: textStyle.align || align,
textBaseline: textStyle.baseline
textBaseline: textStyle.baseline
|| (
(i === 0 && this.option.name !== '')
? 'bottom'
......@@ -281,7 +281,7 @@ define(function (require) {
)
}
};
if (rotate) {
axShape.rotation = [
rotate * Math.PI / 180,
......@@ -483,10 +483,10 @@ define(function (require) {
// 不是自己的数据不计算极值
continue;
}
this._calculSum(data, i);
}
// 找极值
var oriData; // 原始数据
for (var i in data){
......@@ -512,13 +512,13 @@ define(function (require) {
}
}
}
// console.log(this._min,this._max,'vvvvv111111',this.option.type)
var gap = Math.abs(this._max - this._min);
this._min = isNaN(this.option.min - 0)
? (this._min - Math.abs(gap * this.option.boundaryGap[0]))
: (this.option.min - 0); // 指定min忽略boundaryGay[0]
this._max = isNaN(this.option.max - 0)
? (this._max + Math.abs(gap * this.option.boundaryGap[1]))
: (this.option.max - 0); // 指定max忽略boundaryGay[1]
......@@ -535,18 +535,32 @@ define(function (require) {
this._max = this._max / this.option.splitNumber != null ? this.option.splitNumber : 5;
}
}
this.option.type != 'time'
? this._reformValue(this.option.scale)
: this._reformTimeValue();
if (this.option.type === 'time') {
this._reformTimeValue();
}
else if (this.option.type === 'log') {
this._reformLogValue();
}
else {
this._reformValue(this.option.scale);
}
}
else {
this._hasData = true;
// 用户指定min max就不多管闲事了
this._min = this.option.min - 0; // 指定min忽略boundaryGay[0]
this._max = this.option.max - 0; // 指定max忽略boundaryGay[1]
this.option.type != 'time'
? this._customerValue()
: this._reformTimeValue();
if (this.option.type === 'time') {
this._reformTimeValue();
}
else if (this.option.type === 'log') {
this._reformLogValue();
}
else {
this._customerValue();
}
}
},
......@@ -636,7 +650,7 @@ define(function (require) {
}
}
},
/**
* 找到原始数据的极值后根据选项整形最终 this._min / this._max / this._valueList
* 如果你不知道这个“整形”的用义,请不要试图去理解和修改这个方法!找我也没用,我相信我已经记不起来!
......@@ -650,7 +664,7 @@ define(function (require) {
_reformValue: function (scale) {
var smartSteps = require('../util/smartSteps');
var splitNumber = this.option.splitNumber;
// 非scale下双正,修正最小值为0
if (!scale && this._min >= 0 && this._max >= 0) {
this._min = 0;
......@@ -659,7 +673,7 @@ define(function (require) {
if (!scale && this._min <= 0 && this._max <= 0) {
this._max = 0;
}
var stepOpt = smartSteps(this._min, this._max, splitNumber);
splitNumber = splitNumber != null ? splitNumber : stepOpt.secs;
//this.option.splitNumber = splitNumber;
......@@ -668,19 +682,19 @@ define(function (require) {
this._valueList = stepOpt.pnts;
this._reformLabelData();
},
/**
* 格式化时间值
* 格式化时间值
*/
_reformTimeValue : function() {
var splitNumber = this.option.splitNumber != null ? this.option.splitNumber : 5;
// 最优解
var curValue = ecDate.getAutoFormatter(this._min, this._max, splitNumber);
// 目标
var formatter = curValue.formatter;
var gapValue = curValue.gapValue;
this._valueList = [ecDate.getNewDate(this._min)];
var startGap;
switch (formatter) {
......@@ -712,17 +726,17 @@ define(function (require) {
}
break;
}
if (startGap - this._min < gapValue / 2) {
startGap -= -gapValue;
}
// console.log(startGap,gapValue,this._min, this._max,formatter)
curValue = ecDate.getNewDate(startGap);
splitNumber *= 1.5;
while (splitNumber-- >= 0) {
if (formatter == 'month'
|| formatter == 'quarter'
if (formatter == 'month'
|| formatter == 'quarter'
|| formatter == 'half-year'
|| formatter == 'year'
) {
......@@ -738,12 +752,12 @@ define(function (require) {
this._reformLabelData(formatter);
},
_customerValue: function () {
var accMath = require('../util/accMath');
var splitNumber = this.option.splitNumber != null ? this.option.splitNumber : 5;
var splitGap = (this._max - this._min) / splitNumber;
this._valueList = [];
for (var i = 0; i <= splitNumber; i++) {
this._valueList.push(accMath.accAdd(this._min, accMath.accMul(splitGap, i)));
......@@ -751,6 +765,24 @@ define(function (require) {
this._reformLabelData();
},
_reformLogValue: function() {
// log数轴本质就是缩放,相当于默认this.option.scale === true,所以不修正_min和_max到0。
var stepOpt = require('../util/smartLogSteps')({
dataMin: this._min,
dataMax: this._max,
logPositive: this.option.logPositive,
splitNumber: this.option.splitNumber
});
this._min = stepOpt.dataMin;
this._max = stepOpt.dataMax;
this._valueList = stepOpt.tickList;
this._logMethods = stepOpt.methods;
this._reformLabelData();
},
_reformLabelData: function (timeFormatter) {
this._valueLabel = [];
var formatter = this.option.axisLabel.formatter;
......@@ -765,7 +797,7 @@ define(function (require) {
}
else if (typeof formatter === 'string') {
this._valueLabel.push(
timeFormatter
timeFormatter
? ecDate.format(formatter, this._valueList[i])
: formatter.replace('{value}',this._valueList[i])
);
......@@ -784,7 +816,7 @@ define(function (require) {
}
}
},
getExtremum: function () {
this._calculateValue();
return {
......@@ -814,22 +846,26 @@ define(function (require) {
// 根据值换算位置
getCoord: function (value) {
if (this.option.type === 'log') {
value = this._logMethods.logMapping(value);
}
value = value < this._min ? this._min : value;
value = value > this._max ? this._max : value;
var result;
if (!this.isHorizontal()) {
// 纵向
result = this.grid.getYend()
- (value - this._min)
/ (this._max - this._min)
result = this.grid.getYend()
- (value - this._min)
/ (this._max - this._min)
* this.grid.getHeight();
}
else {
// 横向
result = this.grid.getX()
+ (value - this._min)
/ (this._max - this._min)
result = this.grid.getX()
+ (value - this._min)
/ (this._max - this._min)
* this.grid.getWidth();
}
......@@ -841,7 +877,7 @@ define(function (require) {
: Math.floor(result);
*/
},
// 根据值换算绝对大小
getCoordSize: function (value) {
if (!this.isHorizontal()) {
......@@ -853,32 +889,37 @@ define(function (require) {
return Math.abs(value / (this._max - this._min) * this.grid.getWidth());
}
},
// 根据位置换算值
getValueFromCoord: function(coord) {
var result;
if (!this.isHorizontal()) {
// 纵向
coord = coord < this.grid.getY() ? this.grid.getY() : coord;
coord = coord > this.grid.getYend() ? this.grid.getYend() : coord;
result = this._max
- (coord - this.grid.getY())
/ this.grid.getHeight()
result = this._max
- (coord - this.grid.getY())
/ this.grid.getHeight()
* (this._max - this._min);
}
else {
// 横向
coord = coord < this.grid.getX() ? this.grid.getX() : coord;
coord = coord > this.grid.getXend() ? this.grid.getXend() : coord;
result = this._min
+ (coord - this.grid.getX())
/ this.grid.getWidth()
result = this._min
+ (coord - this.grid.getX())
/ this.grid.getWidth()
* (this._max - this._min);
}
if (this.option.type === 'log') {
result = this._logMethods.powMapping(result);
}
return result.toFixed(2) - 0;
},
isMaindAxis : function (value) {
for (var i = 0, l = this._valueList.length; i < l; i++) {
if (this._valueList[i] === value) {
......@@ -890,9 +931,9 @@ define(function (require) {
};
zrUtil.inherits(ValueAxis, Base);
require('../component').define('valueAxis', ValueAxis);
return ValueAxis;
});
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册