Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
alon@wen
echarts
提交
0b58f7b3
E
echarts
项目概览
alon@wen
/
echarts
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
echarts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0b58f7b3
编写于
8月 25, 2015
作者:
L
lang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Axis draw
上级
2932c30a
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
228 addition
and
22 deletion
+228
-22
src/ExtensionAPI.js
src/ExtensionAPI.js
+1
-1
src/component/axis.js
src/component/axis.js
+188
-15
src/component/grid.js
src/component/grid.js
+2
-1
src/echarts.js
src/echarts.js
+2
-2
src/model/Model.js
src/model/Model.js
+5
-0
src/util/graphic.js
src/util/graphic.js
+2
-0
src/util/number.js
src/util/number.js
+26
-1
test/bar.html
test/bar.html
+2
-2
未找到文件。
src/
api/
ExtensionAPI.js
→
src/ExtensionAPI.js
浏览文件 @
0b58f7b3
...
...
@@ -15,7 +15,7 @@ define(function(require) {
};
// Mix graphic api
zrUtil
.
merge
(
ExtensionAPI
.
prototype
,
require
(
'
./graphic
'
));
zrUtil
.
merge
(
ExtensionAPI
.
prototype
,
require
(
'
./
util/
graphic
'
));
return
ExtensionAPI
;
});
\ No newline at end of file
src/component/axis.js
浏览文件 @
0b58f7b3
define
(
function
(
require
)
{
'
use strict
'
;
var
numberUtil
=
require
(
'
../util/number
'
);
require
(
'
../coord/cartesian/AxisModel
'
);
var
AxisView
=
require
(
'
../echarts
'
).
extendComponentView
({
...
...
@@ -8,15 +10,30 @@ define(function(require) {
type
:
'
axis
'
,
render
:
function
(
axisModel
,
ecModel
,
api
)
{
this
.
group
.
clear
();
var
gridModel
=
ecModel
.
getComponent
(
'
grid
'
,
axisModel
.
get
(
'
gridIndex
'
)
);
if
(
axisModel
.
get
(
'
axisLine.show
'
))
{
this
.
_renderAxisLine
(
axisModel
,
ec
Model
,
api
);
this
.
_renderAxisLine
(
axisModel
,
grid
Model
,
api
);
}
if
(
axisModel
.
get
(
'
axisTick.show
'
))
{
this
.
_renderAxisTick
(
axisModel
,
ecModel
,
api
);
this
.
_renderAxisTick
(
axisModel
,
gridModel
,
api
);
}
if
(
axisModel
.
get
(
'
axisLabel.show
'
))
{
this
.
_renderAxisLabel
(
axisModel
,
gridModel
,
api
);
}
},
_renderAxisLine
:
function
(
axisModel
,
ecModel
,
api
)
{
/**
* @param {module:echarts/coord/cartesian/AxisModel} axisModel
* @param {module:echarts/coord/cartesian/GridModel} gridModel
* @param {module:echarts/ExtensionAPI} api
* @private
*/
_renderAxisLine
:
function
(
axisModel
,
gridModel
,
api
)
{
var
axis
=
axisModel
.
axis
;
var
p1
=
[];
...
...
@@ -27,9 +44,6 @@ define(function(require) {
var
lineColor
=
lineStyleModel
.
get
(
'
color
'
);
var
lineType
=
lineStyleModel
.
get
(
'
type
'
);
var
gridModel
=
ecModel
.
getComponent
(
'
grid
'
,
axisModel
.
get
(
'
gridIndex
'
)
);
var
rect
=
gridModel
.
coordinateSystem
.
getRect
();
var
otherCoord
=
axis
.
otherCoord
;
...
...
@@ -63,7 +77,13 @@ define(function(require) {
}));
},
_renderAxisTick
:
function
(
axisModel
,
ecModel
,
api
)
{
/**
* @param {module:echarts/coord/cartesian/AxisModel} axisModel
* @param {module:echarts/coord/cartesian/GridModel} gridModel
* @param {module:echarts/ExtensionAPI} api
* @private
*/
_renderAxisTick
:
function
(
axisModel
,
gridModel
,
api
)
{
var
axis
=
axisModel
.
axis
;
var
tickModel
=
axisModel
.
getModel
(
'
axisTick
'
);
...
...
@@ -84,6 +104,7 @@ define(function(require) {
var
ticksCoords
=
isOrdinalAxis
&&
axis
.
boundaryGap
?
axis
.
getBandsCoords
(
true
)
:
axis
.
getTicksCoords
();
var
tickLines
=
[];
for
(
var
i
=
0
;
i
<
ticksCoords
.
length
;
i
++
)
{
// Only ordinal scale support tick interval
if
(
isOrdinalAxis
)
{
...
...
@@ -124,21 +145,173 @@ define(function(require) {
var
p2
=
[
x
+
offX
,
y
+
offY
];
api
.
subPixelOptimizeLine
(
p1
,
p2
,
tickLineWidth
);
// Tick line
var
tickLine
=
new
api
.
Line
({
tickLines
.
push
(
new
api
.
Line
({
shape
:
{
x1
:
p1
[
0
],
y1
:
p1
[
1
],
x2
:
p2
[
0
],
y2
:
p2
[
1
]
},
style
:
{
stroke
:
tickColor
,
lineWidth
:
tickLineWidth
}
});
this
.
group
.
add
(
tickLine
);
}));
}
}
var
tickEl
=
api
.
mergePath
(
tickLines
,
{
style
:
{
stroke
:
tickColor
,
lineWidth
:
tickLineWidth
}
});
this
.
group
.
add
(
tickEl
);
},
/**
* @param {module:echarts/coord/cartesian/AxisModel} axisModel
* @param {module:echarts/coord/cartesian/GridModel} gridModel
* @param {module:echarts/ExtensionAPI} api
* @private
*/
_renderAxisLabel
:
function
(
axisModel
,
gridModel
,
api
)
{
var
axis
=
axisModel
.
axis
;
var
labelModel
=
axisModel
.
getModel
(
'
axisLabel
'
);
var
textStyleModel
=
labelModel
.
getModel
(
'
textStyle
'
);
var
labelFormatter
=
labelModel
.
get
(
'
formatter
'
);
if
(
!
labelFormatter
)
{
// Default formatter
switch
(
axisModel
.
get
(
'
type
'
))
{
// TODO
case
'
log
'
:
break
;
case
'
category
'
:
labelFormatter
=
function
(
val
)
{
return
val
;};
break
;
default
:
labelFormatter
=
function
(
val
)
{
return
numberUtil
.
addCommas
(
numberUtil
.
round
(
val
));
}
break
;
}
}
else
if
(
typeof
labelFormatter
===
'
string
'
)
{
labelFormatter
=
(
function
(
tpl
)
{
return
function
(
val
)
{
return
tpl
.
replace
(
'
{value}
'
,
val
);
};
})(
labelFormatter
);
}
var
gridRect
=
gridModel
.
coordinateSystem
.
getRect
();
var
ticks
=
axis
.
scale
.
getTicks
();
var
labelMargin
=
labelModel
.
get
(
'
margin
'
);
var
labelRotate
=
labelModel
.
get
(
'
rotate
'
);
var
labelInterval
=
labelModel
.
get
(
'
interval
'
)
||
0
;
var
isLabelIntervalFunction
=
typeof
labelInterval
===
'
function
'
;
var
labelShowList
=
[];
var
textSpaceTakenRect
;
var
needsCheckTextSpace
;
for
(
var
i
=
0
;
i
<
ticks
.
length
;
i
++
)
{
// Default is false
labelShowList
[
i
]
=
false
;
needsCheckTextSpace
=
false
;
// Only ordinal scale support label interval
if
(
axis
.
scale
.
type
===
'
ordinal
'
)
{
if
(
labelInterval
===
'
auto
'
)
{
needsCheckTextSpace
=
true
;
}
else
if
(
isLabelIntervalFunction
)
{
if
(
!
labelInterval
(
tick
,
axis
.
scale
.
getItem
(
tick
)))
{
continue
;
}
}
else
{
if
(
tick
%
(
labelInterval
+
1
))
{
continue
;
}
}
}
var
x
;
var
y
;
var
tick
=
ticks
[
i
];
var
tickCoord
=
axis
.
dataToCoord
(
tick
);
var
labelTextAlign
=
'
center
'
;
var
labelTextBaseline
=
'
middle
'
;
var
label
=
tick
;
switch
(
axis
.
type
)
{
case
'
category
'
:
label
=
axis
.
scale
.
getItem
(
tick
);
break
;
case
'
time
'
:
// TODO
}
switch
(
axis
.
position
)
{
case
'
top
'
:
y
=
gridRect
.
y
-
labelMargin
;
x
=
tickCoord
;
labelTextBaseline
=
'
bottom
'
;
break
;
case
'
bottom
'
:
x
=
tickCoord
;
y
=
gridRect
.
y
+
gridRect
.
height
+
labelMargin
;
labelTextBaseline
=
'
top
'
;
break
;
case
'
left
'
:
x
=
gridRect
.
x
-
labelMargin
;
y
=
tickCoord
;
labelTextAlign
=
'
right
'
;
break
;
case
'
right
'
:
x
=
gridRect
.
x
+
gridRect
.
width
+
labelMargin
;
y
=
tickCoord
;
labelTextAlign
=
'
left
'
;
}
if
(
axis
.
isHorizontal
())
{
if
(
labelRotate
)
{
labelTextAlign
=
labelRotate
>
0
?
'
left
'
:
'
right
'
;
}
}
var
textEl
=
new
api
.
Text
({
style
:
{
x
:
x
,
y
:
y
,
text
:
labelFormatter
(
label
),
textAlign
:
labelTextAlign
,
textBaseline
:
labelTextBaseline
},
rotation
:
labelRotate
*
Math
.
PI
/
180
,
origin
:
[
x
,
y
]
});
if
(
needsCheckTextSpace
&&
!
labelRotate
)
{
var
rect
=
textEl
.
getBoundingRect
();
if
(
!
textSpaceTakenRect
)
{
textSpaceTakenRect
=
rect
;
}
else
{
// There is no space for current label;
if
(
textSpaceTakenRect
.
intersect
(
rect
))
{
continue
;
}
else
{
textSpaceTakenRect
.
union
(
rect
);
}
}
}
labelShowList
[
i
]
=
true
;
this
.
group
.
add
(
textEl
);
}
}
});
AxisView
.
extend
({
...
...
src/component/grid.js
浏览文件 @
0b58f7b3
...
...
@@ -17,7 +17,8 @@ define(function(require) {
stroke
:
gridModel
.
get
(
'
borderColor
'
),
lineWidth
:
gridModel
.
get
(
'
borderWidth
'
),
fill
:
gridModel
.
get
(
'
backgroundColor
'
)
}
},
hoverable
:
false
}));
}
}
...
...
src/echarts.js
浏览文件 @
0b58f7b3
...
...
@@ -7,7 +7,7 @@
define
(
function
(
require
)
{
var
GlobalModel
=
require
(
'
./model/Global
'
);
var
ExtensionAPI
=
require
(
'
./
api/
ExtensionAPI
'
);
var
ExtensionAPI
=
require
(
'
./ExtensionAPI
'
);
var
CoordinateSystemManager
=
require
(
'
./CoordinateSystem
'
);
var
ComponentModel
=
require
(
'
./model/Component
'
);
...
...
@@ -70,7 +70,7 @@ define(function (require) {
this
.
_componentsMap
=
{};
/**
* @type {module:echarts/
api/
ExtensionAPI}
* @type {module:echarts/ExtensionAPI}
* @private
*/
this
.
_extensionAPI
=
new
ExtensionAPI
(
this
);
...
...
src/model/Model.js
浏览文件 @
0b58f7b3
...
...
@@ -76,6 +76,11 @@ define(function (require) {
return
obj
;
},
/**
* @param {string} path
* @param {module:echarts/model/Model} parentModel
* @return {module:echarts/model/Model}
*/
getModel
:
function
(
path
,
parentModel
)
{
var
obj
=
this
.
get
(
path
);
return
new
Model
(
obj
,
parentModel
);
...
...
src/
api
/graphic.js
→
src/
util
/graphic.js
浏览文件 @
0b58f7b3
...
...
@@ -37,6 +37,8 @@ define(function(require) {
return
path
;
},
mergePath
:
pathTool
.
mergePath
,
/**
* Resize a path to fit the rect
*/
...
...
src/util/number.js
浏览文件 @
0b58f7b3
...
...
@@ -88,12 +88,37 @@ define(function (require) {
return
val
;
}
/**
* 每三位默认加,格式化
* @type {string|number} x
*/
function
addCommas
(
x
)
{
if
(
isNaN
(
x
))
{
return
'
-
'
;
}
x
=
(
x
+
''
).
split
(
'
.
'
);
return
x
[
0
].
replace
(
/
(\d{1,3})(?=(?:\d{3})
+
(?!\d))
/g
,
'
$1,
'
)
+
(
x
.
length
>
1
?
(
'
.
'
+
x
[
1
])
:
''
);
}
/**
* Fix rounding error of float numbers
*/
function
round
(
x
)
{
// PENDING
return
+
(
+
x
).
toFixed
(
10
);
}
return
{
linearMap
:
linearMap
,
parsePercent
:
parsePercent
,
normalizeCssArray
:
normalizeCssArray
normalizeCssArray
:
normalizeCssArray
,
addCommas
:
addCommas
,
round
:
round
};
});
\ No newline at end of file
test/bar.html
浏览文件 @
0b58f7b3
...
...
@@ -32,8 +32,8 @@
var
data3
=
[];
for
(
var
i
=
0
;
i
<
20
;
i
++
)
{
xAxisData
.
push
(
Math
.
random
()
);
data1
.
push
(
Math
.
random
());
xAxisData
.
push
(
'
类目
'
+
i
);
data1
.
push
(
Math
.
random
()
*
5
);
data2
.
push
(
Math
.
random
());
data3
.
push
(
Math
.
random
());
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录