Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
alon@wen
echarts
提交
d678bc85
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,发现更多精彩内容 >>
提交
d678bc85
编写于
9月 29, 2015
作者:
L
lang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Layout helper
上级
9b9c01d0
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
158 addition
and
68 deletion
+158
-68
src/component/legend/LegendModel.js
src/component/legend/LegendModel.js
+6
-4
src/component/legend/LegendView.js
src/component/legend/LegendView.js
+33
-34
src/component/legend/legendLayout.js
src/component/legend/legendLayout.js
+0
-29
src/util/layout.js
src/util/layout.js
+118
-0
test/bar.html
test/bar.html
+1
-1
未找到文件。
src/component/legend/LegendModel.js
浏览文件 @
d678bc85
...
...
@@ -94,13 +94,15 @@ define(function(require) {
// 'horizontal' | 'vertical'
orient
:
'
horizontal
'
,
// 水平安放位置,默认为全图居中,可选为:
//
x, x2 为
水平安放位置,默认为全图居中,可选为:
// 'center' | 'left' | 'right' | {number}(x坐标,单位px)
x
:
'
center
'
,
// x: 'center',
// x2: 'center',
// 垂直安放位置,默认为全图顶端,可选为:
//
y, y2 为
垂直安放位置,默认为全图顶端,可选为:
// 'top' | 'bottom' | 'center' | {number}(y坐标,单位px)
y
:
'
top
'
,
// y: 'top',
// y2: 'top'
// 水平对齐
// 'auto' | 'left' | 'right'
...
...
src/component/legend/LegendView.js
浏览文件 @
d678bc85
...
...
@@ -3,9 +3,10 @@ define(function (require) {
var
zrUtil
=
require
(
'
zrender/core/util
'
);
var
numberUtil
=
require
(
'
../../util/number
'
);
var
symbolCreator
=
require
(
'
../../util/symbol
'
);
var
legendLayout
=
require
(
'
./legendLayout
'
);
var
graphic
=
require
(
'
../../util/graphic
'
);
var
layout
=
require
(
'
../../util/layout
'
);
var
LEGEND_DISABLE_COLOR
=
'
#ccc
'
;
function
createSelectActionDispatcher
(
uid
,
seriesName
,
api
)
{
...
...
@@ -16,6 +17,32 @@ define(function (require) {
});
}
function
positionGroup
(
group
,
legendModel
,
api
)
{
var
x
=
legendModel
.
get
(
'
x
'
);
var
y
=
legendModel
.
get
(
'
y
'
);
var
x2
=
legendModel
.
get
(
'
x2
'
);
var
y2
=
legendModel
.
get
(
'
y2
'
);
if
(
!
x
&&
!
x2
)
{
x
=
'
center
'
;
}
if
(
!
y
&&
!
y2
)
{
y
=
'
top
'
;
}
layout
.
positionGroup
(
group
,
{
x
:
x
,
y
:
y
,
x2
:
x2
,
y2
:
y2
},
{
width
:
api
.
getWidth
(),
height
:
api
.
getHeight
()
},
legendModel
.
get
(
'
padding
'
)
);
}
return
require
(
'
../../echarts
'
).
extendComponentView
({
type
:
'
legend
'
,
...
...
@@ -31,13 +58,6 @@ define(function (require) {
var
itemAlign
=
legendModel
.
get
(
'
align
'
);
var
group
=
this
.
group
;
var
x
=
legendModel
.
get
(
'
x
'
);
var
y
=
legendModel
.
get
(
'
y
'
);
var
parsePercent
=
numberUtil
.
parsePercent
;
group
.
position
=
[
parsePercent
(
x
,
api
.
getWidth
()),
parsePercent
(
y
,
api
.
getHeight
())
];
group
.
removeAll
();
if
(
itemAlign
===
'
auto
'
)
{
...
...
@@ -101,9 +121,12 @@ define(function (require) {
}
},
this
);
legendLayout
(
group
,
legendModel
);
layout
.
box
(
legendModel
.
get
(
'
orient
'
),
group
,
legendModel
.
get
(
'
itemGap
'
)
);
this
.
_adjustGroupPosition
(
group
,
x
,
y
);
positionGroup
(
group
,
legendModel
,
api
);
},
_createItem
:
function
(
...
...
@@ -151,30 +174,6 @@ define(function (require) {
this
.
group
.
add
(
itemGroup
);
itemGroup
.
on
(
'
click
'
,
zrUtil
.
curry
(
createSelectActionDispatcher
,
this
.
uid
,
name
,
api
),
this
);
},
_adjustGroupPosition
:
function
(
group
,
x
,
y
)
{
var
groupRect
=
group
.
getBoundingRect
();
var
position
=
group
.
position
;
var
padding
=
group
.
padding
;
switch
(
x
)
{
case
'
center
'
:
position
[
0
]
-=
groupRect
.
width
/
2
;
break
;
case
'
right
'
:
position
[
0
]
-=
groupRect
.
width
+
groupRect
.
x
+
padding
[
1
];
break
;
}
switch
(
y
)
{
case
'
center
'
:
position
[
1
]
-=
groupRect
.
height
/
2
;
break
;
case
'
bottom
'
:
position
[
0
]
-=
groupRect
.
height
+
groupRect
.
y
+
padding
[
2
];
break
;
}
}
});
});
\ No newline at end of file
src/component/legend/legendLayout.js
已删除
100644 → 0
浏览文件 @
9b9c01d0
define
(
function
(
require
)
{
'
use strict
'
;
var
formatUtil
=
require
(
'
../../util/format
'
);
return
function
(
group
,
legendModel
)
{
var
itemGap
=
legendModel
.
get
(
'
itemGap
'
);
var
padding
=
formatUtil
.
normalizeCssArray
(
legendModel
.
get
(
'
padding
'
)
);
var
orient
=
legendModel
.
get
(
'
orient
'
);
var
x
=
padding
[
3
];
var
y
=
padding
[
0
];
group
.
eachChild
(
function
(
child
)
{
var
position
=
child
.
position
;
var
rect
=
child
.
getBoundingRect
();
position
[
0
]
=
x
;
position
[
1
]
=
y
;
orient
===
'
horizontal
'
?
(
x
+=
rect
.
width
+
itemGap
)
:
(
y
+=
rect
.
height
+
itemGap
);
});
group
.
padding
=
padding
;
};
});
\ No newline at end of file
src/util/layout.js
0 → 100644
浏览文件 @
d678bc85
// Layout helpers for each component positioning
define
(
function
(
require
)
{
'
use strict
'
;
var
zrUtil
=
require
(
'
zrender/core/util
'
);
var
numberUtil
=
require
(
'
./number
'
);
var
formatUtil
=
require
(
'
./format
'
);
var
layout
=
{};
function
boxLayout
(
orient
,
group
,
gap
)
{
var
x
=
0
;
var
y
=
0
;
group
.
eachChild
(
function
(
child
)
{
var
position
=
child
.
position
;
var
rect
=
child
.
getBoundingRect
();
position
[
0
]
=
x
;
position
[
1
]
=
y
;
orient
===
'
horizontal
'
?
(
x
+=
rect
.
width
+
gap
)
:
(
y
+=
rect
.
height
+
gap
);
});
}
/**
* VBox or HBox layouting
* @param {string} orient
* @param {module:zrender/container/Group} group
* @param {number} gap
*/
layout
.
box
=
boxLayout
;
/**
* VBox layouting
* @param {module:zrender/container/Group} group
* @param {number} gap
*/
layout
.
vbox
=
zrUtil
.
curry
(
boxLayout
,
'
vertical
'
);
/**
* HBox layouting
* @param {module:zrender/container/Group} group
* @param {number} gap
*/
layout
.
hbox
=
zrUtil
.
curry
(
boxLayout
,
'
horizontal
'
);
/**
* Position group of component in viewport
* Group position is specified by either
* {x, y}, {x2, y2}
* If all properties exists, x2 and y2 will be igonred.
*
* @param {module:zrender/container/Group} group
* @param {Object} positionInfo
* @param {number|string} [positionInfo.x]
* @param {number|string} [positionInfo.y]
* @param {number|string} [positionInfo.x2]
* @param {number|string} [positionInfo.y2]
* @param {Object} containerRect
* @param {string|number} margin
*/
layout
.
positionGroup
=
function
(
group
,
positionInfo
,
containerRect
,
margin
)
{
margin
=
formatUtil
.
normalizeCssArray
(
margin
);
var
groupRect
=
group
.
getBoundingRect
();
var
containerWidth
=
containerRect
.
width
;
var
containerHeight
=
containerRect
.
height
;
var
parsePercent
=
numberUtil
.
parsePercent
;
var
x
=
parsePercent
(
positionInfo
.
x
,
containerWidth
);
var
y
=
parsePercent
(
positionInfo
.
y
,
containerHeight
);
var
x2
=
parsePercent
(
positionInfo
.
x2
,
containerWidth
);
var
y2
=
parsePercent
(
positionInfo
.
y2
,
containerHeight
);
var
width
=
groupRect
.
width
;
var
height
=
groupRect
.
height
;
height
+=
margin
[
2
]
+
margin
[
0
];
width
+=
margin
[
1
]
+
margin
[
3
];
// If x is not specified, calculate x from x2 and width
if
(
isNaN
(
x
))
{
x
=
x2
-
width
;
}
if
(
isNaN
(
y
))
{
y
=
y2
-
height
;
}
switch
(
positionInfo
.
x
||
positionInfo
.
x2
)
{
case
'
center
'
:
x
=
containerWidth
/
2
-
width
/
2
;
break
;
case
'
right
'
:
x
=
containerWidth
-
width
;
break
;
}
switch
(
positionInfo
.
y
||
positionInfo
.
y2
)
{
case
'
middle
'
:
y
-=
containerHeight
/
2
-
height
/
2
;
break
;
case
'
bottom
'
:
y
-=
containerHeight
-
height
;
break
;
}
group
.
position
=
[
x
-
groupRect
.
x
+
margin
[
3
],
y
-
groupRect
.
y
+
margin
[
0
]
];
};
return
layout
;
});
\ No newline at end of file
test/bar.html
浏览文件 @
d678bc85
...
...
@@ -63,7 +63,7 @@
},
orient
:
'
vertical
'
,
x
:
'
right
'
,
align
:
'
lef
t
'
align
:
'
righ
t
'
},
tooltip
:
{},
xAxis
:
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录