Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
x649585723
incubator-echarts
提交
c4d201cd
I
incubator-echarts
项目概览
x649585723
/
incubator-echarts
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
incubator-echarts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c4d201cd
编写于
11月 06, 2014
作者:
I
i6ma
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request
#1
from ecomfe/master
jshint
上级
f73d6fe1
a4aaed7b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
196 addition
and
190 deletion
+196
-190
src/component/tooltip.js
src/component/tooltip.js
+25
-17
src/component/valueAxis.js
src/component/valueAxis.js
+31
-71
src/util/smartSteps.js
src/util/smartSteps.js
+118
-98
test/allchart/all.html
test/allchart/all.html
+22
-4
未找到文件。
src/component/tooltip.js
浏览文件 @
c4d201cd
...
...
@@ -641,7 +641,12 @@ define(function (require) {
dataIndex
:
dataIndex
,
data
:
data
,
name
:
categoryAxis
.
getNameByIndex
(
dataIndex
),
value
:
value
value
:
value
,
// 向下兼容
0
:
seriesArray
[
i
].
name
||
''
,
1
:
categoryAxis
.
getNameByIndex
(
dataIndex
),
2
:
value
,
3
:
data
});
}
this
.
_curTicket
=
'
axis:
'
+
dataIndex
;
...
...
@@ -765,6 +770,7 @@ define(function (require) {
if
(
seriesArray
.
length
>
0
)
{
var
polarData
;
var
data
;
var
value
;
var
params
=
[];
for
(
var
i
=
0
,
l
=
seriesArray
.
length
;
i
<
l
;
i
++
)
{
...
...
@@ -777,7 +783,8 @@ define(function (require) {
data
=
data
!=
null
?
data
:
{
name
:
''
,
value
:
{
dataIndex
:
'
-
'
}};
value
=
data
.
value
[
dataIndex
].
value
!=
null
?
data
.
value
[
dataIndex
].
value
:
data
.
value
[
dataIndex
];
params
.
push
({
seriesIndex
:
seriesIndex
[
i
],
seriesName
:
seriesArray
[
i
].
name
||
''
,
...
...
@@ -785,8 +792,12 @@ define(function (require) {
data
:
data
,
name
:
data
.
name
,
indicator
:
indicatorName
,
value
:
data
.
value
[
dataIndex
].
value
!=
null
?
data
.
value
[
dataIndex
].
value
:
data
.
value
[
dataIndex
]
value
:
value
,
// 向下兼容
0
:
seriesArray
[
i
].
name
||
''
,
1
:
data
.
name
,
2
:
value
,
3
:
indicatorName
});
}
}
...
...
@@ -918,20 +929,17 @@ define(function (require) {
percent
:
special
,
// 饼图
indicator
:
special
,
// 雷达图
value2
:
special2
,
indicator2
:
special2
indicator2
:
special2
,
// 向下兼容
0
:
serie
.
name
||
''
,
1
:
name
,
2
:
value
,
3
:
special
,
4
:
special2
,
5
:
data
,
6
:
ecData
.
get
(
this
.
_curTarget
,
'
seriesIndex
'
),
7
:
dataIndex
},
/*
[
serie.name || '',
name,
value,
special,
special2,
data,
ecData.get(this._curTarget, 'seriesIndex'),
ecData.get(this._curTarget, 'dataIndex')
],
*/
this
.
_curTicket
,
this
.
_setContent
);
...
...
src/component/valueAxis.js
浏览文件 @
c4d201cd
...
...
@@ -462,10 +462,10 @@ define(function (require) {
}
// 修复最大值==最小值时数据整形
else
if
(
this
.
_max
>
0
)
{
this
.
_min
=
this
.
_max
/
this
.
option
.
splitNumber
;
this
.
_min
=
this
.
_max
/
this
.
option
.
splitNumber
!=
null
?
this
.
option
.
splitNumber
:
5
;
}
else
{
// this._max < 0
this
.
_max
=
this
.
_max
/
this
.
option
.
splitNumber
;
this
.
_max
=
this
.
_max
/
this
.
option
.
splitNumber
!=
null
?
this
.
option
.
splitNumber
:
5
;
}
}
this
.
option
.
type
!=
'
time
'
...
...
@@ -578,78 +578,38 @@ define(function (require) {
* 找到原始数据的极值后根据选项整形最终 this._min / this._max / this._valueList
* 如果你不知道这个“整形”的用义,请不要试图去理解和修改这个方法!找我也没用,我相信我已经记不起来!
* 如果你有更简洁的数学推导欢迎重写,后果自负~
* 一旦你不得不遇到了需要修改或重写的厄运,希望下面的脚手架能帮助你
* ps:其实我是想说别搞砸了!升级后至少得保证这些case通过!!
*
* by linzhifeng@baidu.com 2013-1-8
* --------
this._valueList = [];
this.option = {splitNumber:5,power:100,precision:0};
this._min = 1; this._max = 123; console.log(this._min, this._max); this._reformValue();
console.log('result is :', this._min, this._max, this._valueList);
console.log('should be : 0 150 [0, 30, 60, 90, 120, 150]',
(this._min == 0 && this._max == 150) ? 'success' : 'failed');
this._min = 10; this._max = 1923; console.log(this._min, this._max); this._reformValue();
console.log('result is :', this._min, this._max, this._valueList);
console.log('should be : 0 2000 [0, 400, 800, 1200, 1600, 2000]',
(this._min == 0 && this._max == 2000) ? 'success' : 'failed');
this._min = 10; this._max = 78; console.log(this._min, this._max); this._reformValue();
console.log('result is :', this._min, this._max, this._valueList);
console.log('should be : 0 100 [0, 20, 40, 60, 80, 100]',
(this._min == 0 && this._max == 100) ? 'success' : 'failed');
this._min = -31; this._max = -3; console.log(this._min, this._max); this._reformValue();
console.log('result is :', this._min, this._max, this._valueList);
console.log('should be : -35 0 [-35, -28, -21, -14, -7, 0]',
(this._min == -35 && this._max == 0) ? 'success' : 'failed');
this._min = -51; this._max = 203; console.log(this._min, this._max); this._reformValue();
console.log('result is :', this._min, this._max, this._valueList);
console.log('should be : -60 240 [-60, 0, 60, 120, 180, 240]',
(this._min == -60 && this._max == 240) ? 'success' : 'failed');
this._min = -251; this._max = 23; console.log(this._min, this._max); this._reformValue();
console.log('result is :', this._min, this._max, this._valueList);
console.log('should be : -280 70 [-280, -210, -140, -70, 0, 70]',
(this._min == -280 && this._max == 70) ? 'success' : 'failed');
this.option.precision = 2;
this._min = 0.23; this._max = 0.78; console.log(this._min, this._max); this._reformValue();
console.log('result is :', this._min, this._max, this._valueList);
console.log('should be : 0.00 1.00'
+ '["0.00", "0.20", "0.40", "0.60", "0.80", "1.00"]',
(this._min == 0.00 && this._max == 1.00) ? 'success' : 'failed');
this._min = -12.23; this._max = -0.78; console.log(this._min, this._max);
this._reformValue();
console.log('result is :', this._min, this._max, this._valueList);
console.log('should be : -15.00 0.00'
+ '["-15.00", "-12.00", "-9.00", "-6.00", "-3.00", "0.00"]',
(this._min == -15.00 && this._max == 0.00) ? 'success' : 'failed');
this._min = -0.23; this._max = 0.78; console.log(this._min, this._max); this._reformValue()
console.log('result is :', this._min, this._max, this._valueList);
console.log('should be : -0.30 1.20'
+ '["-0.30", "0.00", "0.30", "0.60", "0.90", "1.20"]',
(this._min == -0.30 && this._max == 1.20) ? 'success' : 'failed');
this._min = -1.23; this._max = 0.78; console.log(this._min, this._max); _reformValue();
console.log('result is :', this._min, this._max, this._valueList);
console.log('should be : -1.50 1.00'
+ '["-1.50", "-1.00", "-0.50", "0.00", "0.50", "1.00"]',
(this._min == -1.50 && this._max == 1.00) ? 'success' : 'failed');
this.option.precision = 1;
this._min = -2.3; this._max = 0.5; console.log(this._min, this._max); _reformValue();
console.log('result is :', this._min, this._max, this._valueList);
console.log('should be : -2.4 0.6'
+ '["-2.4", "-1.8", "-1.2", "-0.6", "0.0", "0.6"]',
(this._min == -2.4 && this._max == 0.6) ? 'success' : 'failed');
* --------
* 感谢谢世威(xieshiwei@baidu.com),终于有人改这个方法了
* by lizhifeng@baidu.com 2014-11-6
*/
_reformValue
:
function
(
scale
)
{
var
smartSteps
=
require
(
'
../util/smartSteps
'
);
var
splitNumber
=
this
.
option
.
splitNumber
;
var
precision
=
this
.
option
.
precision
;
// 非scale下双正,修正最小值为0
if
(
!
scale
&&
this
.
_min
>=
0
&&
this
.
_max
>=
0
)
{
this
.
_min
=
0
;
}
// 非scale下双负,修正最大值为0
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
;
this
.
_min
=
stepOpt
.
min
.
toFixed
(
precision
)
-
0
;
this
.
_max
=
stepOpt
.
max
.
toFixed
(
precision
)
-
0
;
this
.
_valueList
=
[];
for
(
var
i
=
0
;
i
<=
splitNumber
;
i
++
)
{
this
.
_valueList
[
i
]
=
(
stepOpt
.
pnts
[
i
]
-
0
).
toFixed
(
precision
)
-
0
;
}
this
.
_reformLabelData
();
return
;
var
splitNumber
=
this
.
option
.
splitNumber
;
var
precision
=
this
.
option
.
precision
;
var
splitGap
;
...
...
@@ -763,7 +723,7 @@ define(function (require) {
* 格式化时间值
*/
_reformTimeValue
:
function
()
{
var
splitNumber
=
this
.
option
.
splitNumber
;
var
splitNumber
=
this
.
option
.
splitNumber
!=
null
?
this
.
option
.
splitNumber
:
5
;
;
// 最优解
var
curValue
=
ecDate
.
getAutoFormatter
(
this
.
_min
,
this
.
_max
,
splitNumber
);
...
...
@@ -830,7 +790,7 @@ define(function (require) {
},
_customerValue
:
function
()
{
var
splitNumber
=
this
.
option
.
splitNumber
;
var
splitNumber
=
this
.
option
.
splitNumber
!=
null
?
this
.
option
.
splitNumber
:
5
;
;
var
precision
=
this
.
option
.
precision
;
var
splitGap
=
(
this
.
_max
-
this
.
_min
)
/
splitNumber
;
...
...
src/util/smartSteps.js
浏览文件 @
c4d201cd
;
/**
* echarts 值轴刻度线计算方法
*
* @author xieshiwei (谢世威, xieshiwei@baidu.com)
*/
/**
* 最值、跨度、步长取近似值
* @function smartSteps
...
...
@@ -18,37 +14,38 @@
* @param {Array} opts.steps 自定义步长备选值,如 [10, 12, 15, 20, 25, 30, 40, 50, 60, 80] ,但必须 => [10, 99]
* @return {Object} {min: 新最小值, max: 新最大值, secs: 分段数, step: 每段长, fix: 小数保留位数, pnts: [分段结果]}
*/
define
(
function
()
{
var
mySections
=
[
4
,
5
,
6
];
var
mySteps
=
[
10
,
25
,
50
];
var
custSteps
=
0
;
var
Mt
=
Math
;
var
M
ath_round
=
Mt
.
round
;
var
M
ath_floor
=
Mt
.
floor
;
var
M
ath_ceil
=
Mt
.
ceil
;
var
M
ATH_ROUND
=
Mt
.
round
;
var
M
ATH_FLOOR
=
Mt
.
floor
;
var
M
ATH_CEIL
=
Mt
.
ceil
;
function
M
ath_log
(
n
)
{
return
Mt
.
log
(
n
)
/
Mt
.
LN10
;}
function
M
ath_pow
(
n
)
{
return
Mt
.
pow
(
10
,
n
);}
function
M
ATH_LOG
(
n
)
{
return
Mt
.
log
(
n
)
/
Mt
.
LN10
;}
function
M
ATH_POW
(
n
)
{
return
Mt
.
pow
(
10
,
n
);}
function
smartSteps
(
min
,
max
,
sections
,
opts
)
{
// 拿公共变量来接收 opts.steps 这个参数,就不用带着参数层层传递了,注意在函数的最终出口处释放这个值
custSteps
=
(
opts
||
{}).
steps
||
mySteps
;
sections
=
M
ath_round
(
+
sections
||
0
)
%
99
;
// 段数限定在 [0, 99]
sections
=
M
ATH_ROUND
(
+
sections
||
0
)
%
99
;
// 段数限定在 [0, 99]
min
=
+
min
||
0
;
max
=
+
max
||
0
;
if
(
min
>
max
)
{
max
=
[
min
,
min
=
max
][
0
];}
// 最值交换
var
span
=
max
-
min
;
if
(
span
===
0
)
{
// 跨度为零,即最大值等于最小值的情况
// 跨度为零,即最大值等于最小值的情况
if
(
span
===
0
)
{
return
forSpan0
(
min
,
max
,
sections
);
}
else
if
(
span
<
(
sections
||
5
))
{
// 跨度值小于要分的段数,步长必定要小于 1
if
(
min
===
Math_round
(
min
)
&&
max
===
Math_round
(
max
))
{
// 步长小于 1 同时两个最值都是整数,特别处理
}
else
if
(
span
<
(
sections
||
5
))
{
// 跨度值小于要分的段数,步长必定要小于 1
// 步长小于 1 同时两个最值都是整数,特别处理
if
(
min
===
MATH_ROUND
(
min
)
&&
max
===
MATH_ROUND
(
max
))
{
return
forInteger
(
min
,
max
,
sections
);
}
}
return
coreCalc
(
min
,
max
,
sections
);
}
;
}
/**
* 最值、跨度、步长取近似值
...
...
@@ -57,49 +54,52 @@ define(function() {
*/
function
coreCalc
(
min
,
max
,
sections
,
opts
)
{
custSteps
=
custSteps
||
(
opts
||
{}).
steps
||
mySteps
;
var
step
,
newMin
,
newMax
;
var
step
;
// var newMin;
// var newMax;
var
tmpSection
=
sections
||
mySections
[
mySections
.
length
-
1
];
var
span
=
getCeil
(
max
-
min
);
// 求 span 的近似值,返回结果是 量级 计数法,c * 10 ^ n ,其中 c => [10, 99]
var
expon
=
span
.
n
;
// 为了让后面的计算都以整数进行,设置一个基准量级
span
=
span
.
c
;
// 可以认为,这是跨度的最小近似值,为了满足后继条件,这个值可能会被多次延展
step
=
getCeil
(
span
/
tmpSection
,
custSteps
);
// 跨度最小值 / 段数最大值 是步长最小值
if
(
step
.
n
<
0
)
{
// 如果跨度小而段数多,步长出现小数时,再次放大有关值,保持整数计算
expon
+=
step
.
n
;
// 各种计算的基准量级,保证 步长(最容易出现小数的量) 是整数
span
*=
Math_pow
(
-
step
.
n
);
step
.
n
=
0
;
if
(
step
.
n
<
0
)
{
// 如果跨度小而段数多,步长出现小数时,再次放大有关值,保持整数计算
expon
+=
step
.
n
;
// 各种计算的基准量级,保证 步长(最容易出现小数的量) 是整数
span
*=
MATH_POW
(
-
step
.
n
);
step
.
n
=
0
;
}
step
=
step
.
c
*
Math_pow
(
step
.
n
);
var
zoom
=
Math_pow
(
expon
);
var
params
=
{
min
:
min
,
zmin
:
min
/
zoom
,
max
:
max
,
zmax
:
max
/
zoom
,
span
:
span
,
step
:
step
,
secs
:
tmpSection
,
exp
:
expon
step
=
step
.
c
*
MATH_POW
(
step
.
n
);
var
zoom
=
MATH_POW
(
expon
);
var
params
=
{
min
:
min
,
zmin
:
min
/
zoom
,
max
:
max
,
zmax
:
max
/
zoom
,
span
:
span
,
step
:
step
,
secs
:
tmpSection
,
exp
:
expon
};
if
(
!
sections
)
{
// 不指定 段数 的情况
if
(
!
sections
)
{
// 不指定 段数 的情况
look4sections
(
params
);
}
else
{
}
else
{
look4step
(
params
);
}
// 如果原始值都是整数,让输出值也保持整数
if
((
min
===
M
ath_round
(
min
))
&&
(
max
===
Math_round
(
max
)))
{
if
((
min
===
M
ATH_ROUND
(
min
))
&&
(
max
===
MATH_ROUND
(
max
)))
{
step
=
params
.
step
*
zoom
;
if
(
params
.
exp
<
0
&&
step
!==
Math_round
(
step
))
{
step
=
Math_floor
(
step
);
span
=
step
*
params
.
secs
;
if
(
span
<
max
-
min
)
{
step
+=
1
;
span
=
step
*
params
.
secs
;
if
(
params
.
exp
<
0
&&
step
!==
MATH_ROUND
(
step
))
{
step
=
MATH_FLOOR
(
step
);
span
=
step
*
params
.
secs
;
if
(
span
<
max
-
min
)
{
step
+=
1
;
span
=
step
*
params
.
secs
;
}
if
(
span
>=
max
-
min
)
{
var
deltaSpan
=
span
-
(
max
-
min
);
params
.
max
=
Math_round
(
max
+
deltaSpan
/
2
);
params
.
min
=
Math_round
(
min
-
deltaSpan
/
2
);
if
(
span
>=
max
-
min
)
{
var
deltaSpan
=
span
-
(
max
-
min
);
params
.
max
=
MATH_ROUND
(
max
+
deltaSpan
/
2
);
params
.
min
=
MATH_ROUND
(
min
-
deltaSpan
/
2
);
params
.
step
=
step
;
params
.
span
=
span
;
params
.
exp
=
0
;
...
...
@@ -112,26 +112,31 @@ define(function() {
function
look4sections
(
params
)
{
var
sections
=
params
.
secs
;
var
newMin
,
newMax
,
tmpSpan
,
tmpStep
;
var
newMin
;
var
newMax
;
var
tmpSpan
;
var
tmpStep
;
var
minStep
=
params
.
step
;
var
minSpan
=
params
.
step
*
sections
;
// 上面计算了在最大段数下的最小步长,希望这对整体跨度的影响较小,但其它段数也要尝试一遍
var
minSpan
=
params
.
step
*
sections
;
// 上面计算了在最大段数下的最小步长,希望这对整体跨度的影响较小,但其它段数也要尝试一遍
for
(
var
i
=
mySections
.
length
-
1
;
i
--
;)
{
// 有点像二元一次方程,段数 和 步长 两个未知数
// 下面遍历可选的段数,各找一个匹配的步长,然后以 跨度最小 作为最优解的依据
sections
=
mySections
[
i
];
tmpStep
=
getCeil
(
params
.
span
/
sections
,
custSteps
).
d
;
newMin
=
M
ath_floor
(
params
.
zmin
/
tmpStep
)
*
tmpStep
;
newMax
=
M
ath_ceil
(
params
.
zmax
/
tmpStep
)
*
tmpStep
;
tmpSpan
=
newMax
-
newMin
;
// 步长的误差被 段数 成倍放大,可能会给跨度造成更大的误差,使最后的段数大于预期的最大值
newMin
=
M
ATH_FLOOR
(
params
.
zmin
/
tmpStep
)
*
tmpStep
;
newMax
=
M
ATH_CEIL
(
params
.
zmax
/
tmpStep
)
*
tmpStep
;
tmpSpan
=
newMax
-
newMin
;
// 步长的误差被 段数 成倍放大,可能会给跨度造成更大的误差,使最后的段数大于预期的最大值
if
(
tmpSpan
<
minSpan
)
{
minSpan
=
tmpSpan
;
minStep
=
tmpStep
;
}
}
newMin
=
M
ath_floor
(
params
.
zmin
/
minStep
)
*
minStep
;
newMax
=
M
ath_ceil
(
params
.
zmax
/
minStep
)
*
minStep
;
newMin
=
M
ATH_FLOOR
(
params
.
zmin
/
minStep
)
*
minStep
;
newMax
=
M
ATH_CEIL
(
params
.
zmax
/
minStep
)
*
minStep
;
sections
=
(
newMax
-
newMin
)
/
minStep
;
if
(
sections
<
3
)
{
sections
*=
2
;}
// 如果查表所得步长比最小步长大得多,那么段数就可能变得很小
if
(
sections
<
3
)
{
// 如果查表所得步长比最小步长大得多,那么段数就可能变得很小
sections
*=
2
;
}
params
.
min
=
newMin
;
params
.
max
=
newMax
;
params
.
step
=
minStep
;
...
...
@@ -144,7 +149,7 @@ define(function() {
var
step
=
params
.
step
;
while
(
newMin
>
params
.
zmin
)
{
span
=
step
*
params
.
secs
;
newMax
=
M
ath_ceil
(
params
.
zmax
/
step
)
*
step
;
// 优先保证 max 端的误差最小,试看 min 值能否被覆盖到
newMax
=
M
ATH_CEIL
(
params
.
zmax
/
step
)
*
step
;
// 优先保证 max 端的误差最小,试看 min 值能否被覆盖到
newMin
=
newMax
-
span
;
step
=
getCeil
(
step
*
1.01
,
custSteps
).
d
;
// 让 step 的增长允许进入更高一个量级
}
...
...
@@ -152,16 +157,16 @@ define(function() {
var
deltaMin
=
params
.
zmin
-
newMin
;
// 上面的计算可能会让 min 端的误差更大,下面尝试均衡误差
var
deltaMax
=
newMax
-
params
.
zmax
;
var
deltaDelta
=
deltaMin
-
deltaMax
;
if
(
deltaDelta
>=
20
)
{
// 当 min 端的误差比 max 端大很多时,考虑将 newMin newMax 同时上移
deltaDelta
=
getCeil
(
deltaDelta
/
2
,
custSteps
,
true
);
if
(
params
.
exp
-
deltaDelta
.
n
<
1
)
{
// 前面对 span 做了放大,所以还要看 误差修正值 与 span 的量级关系
newMin
+=
deltaDelta
.
d
;
newMax
+=
deltaDelta
.
d
;
if
(
deltaDelta
>=
20
)
{
// 当 min 端的误差比 max 端大很多时,考虑将 newMin newMax 同时上移
deltaDelta
=
getCeil
(
deltaDelta
/
2
,
custSteps
,
true
);
if
(
params
.
exp
-
deltaDelta
.
n
<
1
)
{
// 前面对 span 做了放大,所以还要看 误差修正值 与 span 的量级关系
newMin
+=
deltaDelta
.
d
;
newMax
+=
deltaDelta
.
d
;
}
}
params
.
min
=
newMin
;
params
.
max
=
newMax
;
params
.
step
=
step
;
params
.
min
=
newMin
;
params
.
max
=
newMax
;
params
.
step
=
step
;
}
/**
...
...
@@ -174,7 +179,7 @@ define(function() {
*/
function
makeResult
(
newMin
,
newMax
,
sections
,
expon
)
{
expon
=
expon
||
0
;
var
zoom
=
M
ath_pow
(
expon
);
var
zoom
=
M
ATH_POW
(
expon
);
var
step
=
(
newMax
-
newMin
)
/
sections
;
var
fixTo
=
0
;
var
points
=
[];
...
...
@@ -191,22 +196,23 @@ define(function() {
points
[
i
]
=
points
[
i
].
toFixed
(
fixTo
);
// 为保证小数点对齐,统一转为字符型
+
points
[
i
]
===
0
&&
(
points
[
i
]
=
'
0
'
);
// 0.000 不好看
}
}
else
{
}
else
{
newMin
*=
zoom
;
newMax
*=
zoom
;
step
*=
zoom
;
}
custSteps
=
0
;
custSteps
=
0
;
// custSteps 这个公共变量可能持用了对用户参数的引用
// 这里是函数的最终出口,释放引用
return
{
min
:
newMin
,
// 新最小值
max
:
newMax
,
// 新最大值
secs
:
sections
,
// 分段数
step
:
step
,
// 每段长
fix
:
fixTo
,
// 小数保留位数,0 则为整数
pnts
:
points
// 分段结果,整数都是数值型,小数时为了对齐小数点,都是字符型,但其中 0 不带小数点,即没有 "0.000"
min
:
newMin
,
// 新最小值
max
:
newMax
,
// 新最大值
secs
:
sections
,
// 分段数
step
:
step
,
// 每段长
fix
:
fixTo
,
// 小数保留位数,0 则为整数
pnts
:
points
// 分段结果,整数都是数值型,小数时为了对齐小数点,都是字符型,但其中 0 不带小数点,即没有 "0.000"
};
}
...
...
@@ -218,29 +224,43 @@ define(function() {
* @return {Object} {c: c, n: n, d: d} 其中 c n 都是整数,且 c => [10, 99] ,原始值 <= c * 10 ^ n
*/
function
getCeil
(
num
,
rounds
,
butFloor
)
{
var
n_10
=
Math_floor
(
Math_log
(
num
))
-
1
;
// 类似科学记数法,姑且称为 量级 记数法,故意将指数减 1,于是小数部分被放大 10 倍,以避免小数计算的精度问题
var
c_10
=
+
(
num
*
Math_pow
(
-
n_10
)).
toFixed
(
9
);
// 此时的 c_10 => [10, 100),下面取近似之后是 [10, 100],toFixed 处理小数精度问题,所以不适用于高精度需求
// 类似科学记数法,姑且称为 量级 记数法,故意将指数减 1,于是小数部分被放大 10 倍,以避免小数计算的精度问题
var
n10
=
MATH_FLOOR
(
MATH_LOG
(
num
))
-
1
;
// 此时的 c10 => [10, 100),下面取近似之后是 [10, 100],toFixed 处理小数精度问题,所以不适用于高精度需求
var
c10
=
+
(
num
*
MATH_POW
(
-
n10
)).
toFixed
(
9
);
if
(
!
rounds
)
{
c_10
=
butFloor
?
Math_floor
(
c_10
)
:
Math_ceil
(
c_10
);
}
else
{
c10
=
butFloor
?
MATH_FLOOR
(
c10
)
:
MATH_CEIL
(
c10
);
}
else
{
var
i
;
if
(
butFloor
)
{
i
=
rounds
.
length
;
while
(
c_10
<
rounds
[
--
i
])
{}
// 在预置的近似数中,挑一个最接近但不大于目标值的项,如果挑不出来,则下标溢出 while 结束
}
else
{
i
=
-
1
;
while
(
c_10
>
rounds
[
++
i
])
{}
// 按 接近但不小于目标值 的标准挑数
i
=
rounds
.
length
;
/* jshint ignore:start */
while
(
c10
<
rounds
[
--
i
])
{
// 在预置的近似数中,挑一个最接近但不大于目标值的项,如果挑不出来,则下标溢出 while 结束
}
/* jshint ignore:end */
}
c_10
=
custSteps
[
i
];
// 如果预置数都小于目标值,则下标溢出,c_10 = undefined
else
{
i
=
-
1
;
/* jshint ignore:start */
while
(
c10
>
rounds
[
++
i
])
{
// 按 接近但不小于目标值 的标准挑数
}
/* jshint ignore:end */
}
c10
=
custSteps
[
i
];
// 如果预置数都小于目标值,则下标溢出,c10 = undefined
}
if
(
!
c
_10
||
c_10
>
99
||
c_
10
<
10
)
{
c
_10
=
10
;
n
_10
+=
butFloor
?
-
1
:
1
;
// 如果是向下取近似,则 c_10 一定是向下超出区间 [10, 99] ,所以 n_
10 - 1 ,反之亦然
if
(
!
c
10
||
c10
>
99
||
c
10
<
10
)
{
c
10
=
10
;
n
10
+=
butFloor
?
-
1
:
1
;
// 如果是向下取近似,则 c10 一定是向下超出区间 [10, 99] ,所以 n
10 - 1 ,反之亦然
}
return
{
c
:
c
_
10
,
n
:
n
_
10
,
d
:
c
_10
*
Math_pow
(
n_
10
)
c
:
c10
,
n
:
n10
,
d
:
c
10
*
MATH_POW
(
n
10
)
};
}
...
...
@@ -250,40 +270,40 @@ define(function() {
* @return {Number} decimals 整数则返回 0 ,小数则返回小数点后的位数
*/
function
decimals
(
num
)
{
num
=
String
(
+
num
).
split
(
'
.
'
);
num
=
String
(
+
num
).
split
(
'
.
'
);
return
num
.
length
>
1
?
num
.
pop
().
length
:
0
;
}
function
forSpan0
(
min
,
max
,
sections
)
{
sections
=
sections
||
5
;
// 当最大值等于最小值时,就可以随便分几段了
if
(
max
==
0
)
{
sections
=
sections
||
5
;
// 当最大值等于最小值时,就可以随便分几段了
if
(
max
=
==
0
)
{
return
makeResult
(
0
,
sections
,
sections
);
// 如果全部值都是 0 ,则以 0 为起点,步长按 1 分段
}
var
delta
=
Mt
.
abs
(
max
/
sections
);
// 以最值为中心,上下各延展一小段
var
delta
=
Mt
.
abs
(
max
/
sections
);
// 以最值为中心,上下各延展一小段
return
coreCalc
(
min
-
delta
,
max
+
delta
,
sections
);
}
function
forInteger
(
min
,
max
,
sections
)
{
// 都是整数,且跨度小于段数,特别处理
sections
=
sections
||
5
;
var
span
_
2
=
(
sections
-
max
+
min
)
/
2
;
// 向上下延展跨度
var
newMax
=
M
ath_round
(
max
+
span_
2
);
var
newMin
=
M
ath_round
(
min
-
span_
2
);
sections
=
sections
||
5
;
var
span2
=
(
sections
-
max
+
min
)
/
2
;
// 向上下延展跨度
var
newMax
=
M
ATH_ROUND
(
max
+
span
2
);
var
newMin
=
M
ATH_ROUND
(
min
-
span
2
);
var
arrMM
=
cross0
(
min
,
max
,
newMin
,
newMax
);
// 避免跨 0
return
makeResult
(
arrMM
[
0
],
arrMM
[
1
],
sections
);
}
function
cross0
(
min
,
max
,
newMin
,
newMax
)
{
if
(
newMin
<
0
&&
min
>=
0
)
{
// 当原始值都在 0 以上时,让新值也都在 0 以上
if
(
newMin
<
0
&&
min
>=
0
)
{
// 当原始值都在 0 以上时,让新值也都在 0 以上
newMax
-=
newMin
;
newMin
=
0
;
}
else
if
(
newMax
>
0
&&
max
<=
0
)
{
// 尽量不让调整后的最值横跨 0 线
}
else
if
(
newMax
>
0
&&
max
<=
0
)
{
// 尽量不让调整后的最值横跨 0 线
newMin
-=
newMax
;
newMax
=
0
;
}
return
[
newMin
,
newMax
];
}
return
smartSteps
;
});
test/allchart/all.html
浏览文件 @
c4d201cd
...
...
@@ -580,10 +580,10 @@ option = {
tooltip : {
trigger: 'axis',
formatter: function (params) {
var res = params[0]
[1]
;
res += '
<br/>
' + params[0]
[0]
;
res += '
<br/>
开盘 : ' + params[0]
[2][0] + ' 最高 : ' + params[0][2]
[3];
res += '
<br/>
收盘 : ' + params[0]
[2][1] + ' 最低 : ' + params[0][2]
[2];
var res = params[0]
.name
;
res += '
<br/>
' + params[0]
.seriesName
;
res += '
<br/>
开盘 : ' + params[0]
.value[0] + ' 最高 : ' + params[0].value
[3];
res += '
<br/>
收盘 : ' + params[0]
.value[1] + ' 最低 : ' + params[0].value
[2];
return res;
}
},
...
...
@@ -1198,6 +1198,15 @@ option = {
tooltip : {
trigger: 'item'
},
toolbox: {
show : true,
y: 'bottom',
feature : {
restore : {show: true},
magicType: {show: true, type: ['force', 'chord']},
saveAsImage : {show: true}
}
},
legend: {
x: 'right',
data:['g1','g2', 'g3', 'g4']
...
...
@@ -1314,6 +1323,14 @@ option = {
trigger: 'item',
formatter: '{a} : {b}'
},
toolbox: {
show : true,
feature : {
restore : {show: true},
magicType: {show: true, type: ['force', 'chord']},
saveAsImage : {show: true}
}
},
legend: {
x: 'left',
data:['家人','朋友']
...
...
@@ -1321,6 +1338,7 @@ option = {
series : [
{
type:'force',
ribbonType: false,
name : "人物关系",
categories : [
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录