Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
alon@wen
echarts
提交
9acf8388
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,发现更多精彩内容 >>
提交
9acf8388
编写于
8月 25, 2015
作者:
L
lang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optimize axis draw
上级
521a1cb2
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
175 addition
and
20 deletion
+175
-20
src/chart/bar/BarView.js
src/chart/bar/BarView.js
+4
-1
src/component/axis.js
src/component/axis.js
+162
-10
src/component/grid.js
src/component/grid.js
+1
-1
src/util/graphic.js
src/util/graphic.js
+5
-5
test/bar.html
test/bar.html
+3
-3
未找到文件。
src/chart/bar/BarView.js
浏览文件 @
9acf8388
...
...
@@ -17,9 +17,11 @@ define(function (require) {
_renderCartesian
:
function
(
seriesModel
,
ecModel
,
api
)
{
var
group
=
this
.
group
;
var
data
=
seriesModel
.
getData
();
data
.
diff
(
this
.
data
)
.
add
(
function
(
dataItem
,
idx
)
{
var
layout
=
dataItem
.
layout
;
var
normalItemStyle
=
dataItem
.
getModel
(
'
itemStyle.normal
'
);
var
rect
=
new
api
.
Rect
({
shape
:
{
x
:
layout
.
x
,
...
...
@@ -28,7 +30,8 @@ define(function (require) {
},
style
:
{
fill
:
dataItem
.
getVisual
(
'
color
'
),
stroke
:
dataItem
.
get
(
'
itemStyle.normal.borderColor
'
)
stroke
:
normalItemStyle
.
get
(
'
borderColor
'
),
lineWidth
:
normalItemStyle
.
get
(
'
borderWidth
'
)
}
});
...
...
src/component/axis.js
浏览文件 @
9acf8388
...
...
@@ -13,17 +13,23 @@ define(function(require) {
this
.
group
.
clear
();
var
gridModel
=
ecModel
.
getComponent
(
'
grid
'
,
axisModel
.
get
(
'
gridIndex
'
)
);
var
gridModel
=
ecModel
.
getComponent
(
'
grid
'
,
axisModel
.
get
(
'
gridIndex
'
));
if
(
axisModel
.
get
(
'
axisLine.show
'
))
{
this
.
_renderAxisLine
(
axisModel
,
gridModel
,
api
);
}
if
(
axisModel
.
get
(
'
axisTick.show
'
))
{
this
.
_renderAxisTick
(
axisModel
,
gridModel
,
api
);
}
var
labelShowList
;
if
(
axisModel
.
get
(
'
axisLabel.show
'
))
{
this
.
_renderAxisLabel
(
axisModel
,
gridModel
,
api
);
labelShowList
=
this
.
_renderAxisLabel
(
axisModel
,
gridModel
,
api
);
}
if
(
axisModel
.
get
(
'
splitLine.show
'
))
{
this
.
_renderSplitLine
(
axisModel
,
gridModel
,
api
,
labelShowList
);
}
if
(
axisModel
.
get
(
'
splitArea.show
'
))
{
this
.
_renderSplitArea
(
axisModel
,
gridModel
,
api
,
labelShowList
);
}
},
...
...
@@ -109,7 +115,7 @@ define(function(require) {
// Only ordinal scale support tick interval
if
(
isOrdinalAxis
)
{
if
(
isTickIntervalFunction
)
{
if
(
!
tickInterval
(
i
,
axis
.
scale
.
getItem
(
i
)))
{
if
(
!
tickInterval
(
i
,
axis
.
scale
.
getItem
(
i
)))
{
continue
;
}
}
...
...
@@ -176,7 +182,7 @@ define(function(require) {
var
textStyleModel
=
labelModel
.
getModel
(
'
textStyle
'
);
var
labelFormatter
=
labelModel
.
get
(
'
formatter
'
);
if
(
!
labelFormatter
)
{
if
(
!
labelFormatter
)
{
// Default formatter
switch
(
axisModel
.
get
(
'
type
'
))
{
// TODO
...
...
@@ -225,7 +231,7 @@ define(function(require) {
needsCheckTextSpace
=
true
;
}
else
if
(
isLabelIntervalFunction
)
{
if
(
!
labelInterval
(
tick
,
axis
.
scale
.
getItem
(
tick
)))
{
if
(
!
labelInterval
(
tick
,
axis
.
scale
.
getItem
(
tick
)))
{
continue
;
}
}
...
...
@@ -291,9 +297,9 @@ define(function(require) {
origin
:
[
x
,
y
]
});
if
(
needsCheckTextSpace
&&
!
labelRotate
)
{
if
(
needsCheckTextSpace
&&
!
labelRotate
)
{
var
rect
=
textEl
.
getBoundingRect
();
if
(
!
textSpaceTakenRect
)
{
if
(
!
textSpaceTakenRect
)
{
textSpaceTakenRect
=
rect
;
}
else
{
...
...
@@ -311,6 +317,152 @@ define(function(require) {
this
.
group
.
add
(
textEl
);
}
},
/**
* @param {module:echarts/coord/cartesian/AxisModel} axisModel
* @param {module:echarts/coord/cartesian/GridModel} gridModel
* @param {module:echarts/ExtensionAPI} api
* @param {Array.<boolean>} showList
* @private
*/
_renderSplitLine
:
function
(
axisModel
,
gridModel
,
api
,
showList
)
{
var
axis
=
axisModel
.
axis
;
var
splitLineModel
=
axisModel
.
getModel
(
'
splitLine
'
);
var
lineStyleModel
=
splitLineModel
.
getModel
(
'
lineStyle
'
);
var
lineWidth
=
lineStyleModel
.
get
(
'
width
'
);
var
lineColors
=
lineStyleModel
.
get
(
'
color
'
);
var
lineType
=
lineStyleModel
.
get
(
'
type
'
);
lineColors
=
lineColors
instanceof
Array
?
lineColors
:
[
lineColors
];
var
gridRect
=
gridModel
.
coordinateSystem
.
getRect
();
var
isHorizontal
=
axis
.
isHorizontal
();
var
splitLines
=
[];
var
lineCount
=
0
;
var
isOrdinalAxis
=
axis
.
scale
.
type
===
'
ordinal
'
;
var
ticksCoords
=
isOrdinalAxis
&&
axis
.
boundaryGap
?
axis
.
getBandsCoords
(
true
)
:
axis
.
getTicksCoords
();
var
p1
=
[];
var
p2
=
[];
for
(
var
i
=
0
;
i
<
ticksCoords
.
length
;
i
++
)
{
var
tickCoord
=
ticksCoords
[
i
];
if
(
isHorizontal
)
{
p1
[
0
]
=
tickCoord
;
p1
[
1
]
=
gridRect
.
y
;
p2
[
0
]
=
tickCoord
;
p2
[
1
]
=
gridRect
.
y
+
gridRect
.
height
;
}
else
{
p1
[
0
]
=
gridRect
.
x
;
p1
[
1
]
=
tickCoord
;
p2
[
0
]
=
gridRect
.
x
+
gridRect
.
width
;
p2
[
1
]
=
tickCoord
;
}
api
.
subPixelOptimizeLine
(
p1
,
p2
,
lineWidth
);
var
colorIndex
=
(
lineCount
++
)
%
lineColors
.
length
;
splitLines
[
colorIndex
]
=
splitLines
[
colorIndex
]
||
[];
splitLines
[
colorIndex
].
push
(
new
api
.
Line
({
shape
:
{
x1
:
p1
[
0
],
y1
:
p1
[
1
],
x2
:
p2
[
0
],
y2
:
p2
[
1
]
}
}));
}
// Simple optimization
// Batching the lines if color are the same
for
(
var
i
=
0
;
i
<
splitLines
.
length
;
i
++
)
{
this
.
group
.
add
(
api
.
mergePath
(
splitLines
[
i
],
{
style
:
{
stroke
:
lineColors
[
i
%
lineColors
.
length
],
lineType
:
lineType
,
lineWidth
:
lineWidth
},
silent
:
true
}));
}
},
/**
* @param {module:echarts/coord/cartesian/AxisModel} axisModel
* @param {module:echarts/coord/cartesian/GridModel} gridModel
* @param {module:echarts/ExtensionAPI} api
* @param {Array.<boolean>} showList
* @private
*/
_renderSplitArea
:
function
(
axisModel
,
gridModel
,
api
,
showList
)
{
var
axis
=
axisModel
.
axis
;
var
splitAreaModel
=
axisModel
.
getModel
(
'
splitArea
'
);
var
areaColors
=
splitAreaModel
.
get
(
'
areaStyle.color
'
);
var
gridRect
=
gridModel
.
coordinateSystem
.
getRect
();
var
isOrdinalAxis
=
axis
.
scale
.
type
===
'
ordinal
'
;
var
ticksCoords
=
isOrdinalAxis
&&
axis
.
boundaryGap
?
axis
.
getBandsCoords
(
true
)
:
axis
.
getTicksCoords
();
var
prevX
;
var
prevY
;
var
splitAreaRects
=
[];
var
count
=
0
;
areaColors
=
areaColors
instanceof
Array
?
areaColors
:
[
areaColors
];
for
(
var
i
=
1
;
i
<
ticksCoords
.
length
;
i
++
)
{
var
tickCoord
=
ticksCoords
[
i
];
var
x
;
var
y
;
var
width
;
var
height
;
if
(
axis
.
isHorizontal
())
{
x
=
prevX
;
y
=
gridRect
.
y
;
width
=
tickCoord
-
x
;
height
=
gridRect
.
height
;
}
else
{
x
=
gridRect
.
x
;
y
=
prevY
;
width
=
gridRect
.
width
;
height
=
tickCoord
-
y
;
}
var
colorIndex
=
(
count
++
)
%
areaColors
.
length
;
splitAreaRects
[
colorIndex
]
=
splitAreaRects
[
colorIndex
]
||
[];
splitAreaRects
[
colorIndex
].
push
(
new
api
.
Rect
({
shape
:
{
x
:
x
,
y
:
y
,
width
:
width
,
height
:
height
}
}));
prevX
=
x
;
prevY
=
y
;
}
// Simple optimization
// Batching the rects if color are the same
for
(
var
i
=
0
;
i
<
splitAreaRects
.
length
;
i
++
)
{
this
.
group
.
add
(
api
.
mergePath
(
splitAreaRects
[
i
],
{
style
:
{
fill
:
areaColors
[
i
%
areaColors
.
length
]
},
silent
:
true
}));
}
}
});
...
...
src/component/grid.js
浏览文件 @
9acf8388
...
...
@@ -18,7 +18,7 @@ define(function(require) {
lineWidth
:
gridModel
.
get
(
'
borderWidth
'
),
fill
:
gridModel
.
get
(
'
backgroundColor
'
)
},
hoverable
:
fals
e
silent
:
tru
e
}));
}
}
...
...
src/util/graphic.js
浏览文件 @
9acf8388
...
...
@@ -59,14 +59,14 @@ define(function(require) {
path
.
applyTransform
(
m
);
},
subPixelOptimizeLine
:
function
(
p
0
,
p1
,
lineWidth
)
{
subPixelOptimizeLine
:
function
(
p
1
,
p2
,
lineWidth
)
{
var
round
=
Math
.
round
;
// Sub pixel optimize
var
offset
=
lineWidth
%
2
/
2
;
var
x1
=
round
(
p
0
[
0
]);
var
y1
=
round
(
p
0
[
1
]);
var
x2
=
round
(
p
1
[
0
]);
var
y2
=
round
(
p
1
[
1
]);
var
x1
=
round
(
p
1
[
0
]);
var
y1
=
round
(
p
1
[
1
]);
var
x2
=
round
(
p
2
[
0
]);
var
y2
=
round
(
p
2
[
1
]);
if
(
x1
===
x2
)
{
x1
+=
offset
;
...
...
test/bar.html
浏览文件 @
9acf8388
...
...
@@ -31,14 +31,14 @@
var
data2
=
[];
var
data3
=
[];
for
(
var
i
=
0
;
i
<
2
0
;
i
++
)
{
for
(
var
i
=
0
;
i
<
10
0
;
i
++
)
{
xAxisData
.
push
(
'
类目
'
+
i
);
data1
.
push
(
Math
.
random
()
*
5
);
data2
.
push
(
Math
.
random
());
data3
.
push
(
Math
.
random
());
}
console
.
tim
e
(
'
setOption
'
);
console
.
profil
e
(
'
setOption
'
);
chart
.
setOption
({
legend
:
{
// TODO First bar unclickable
...
...
@@ -77,7 +77,7 @@
data
:
data3
}]
});
console
.
tim
eEnd
(
'
setOption
'
);
console
.
profil
eEnd
(
'
setOption
'
);
})
</script>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录