Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
x649585723
incubator-echarts
提交
d17731aa
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,发现更多精彩内容 >>
提交
d17731aa
编写于
9月 28, 2016
作者:
1
100pah
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[geo] enable convertToPixel for geo.
上级
505063f5
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
366 addition
and
90 deletion
+366
-90
src/CoordinateSystem.js
src/CoordinateSystem.js
+82
-9
src/coord/cartesian/Grid.js
src/coord/cartesian/Grid.js
+1
-5
src/coord/geo/Geo.js
src/coord/geo/Geo.js
+23
-0
src/echarts.js
src/echarts.js
+10
-0
src/model/Component.js
src/model/Component.js
+8
-0
src/model/Global.js
src/model/Global.js
+3
-3
test/ut/core/utHelper.js
test/ut/core/utHelper.js
+8
-0
test/ut/spec/component/dataZoom/helper.js
test/ut/spec/component/dataZoom/helper.js
+100
-0
test/ut/spec/coord/converter.js
test/ut/spec/coord/converter.js
+129
-0
test/ut/spec/util/model.js
test/ut/spec/util/model.js
+0
-73
test/ut/ut.js
test/ut/ut.js
+2
-0
未找到文件。
src/CoordinateSystem.js
浏览文件 @
d17731aa
...
...
@@ -2,6 +2,32 @@ define(function(require) {
'
use strict
'
;
var
zrUtil
=
require
(
'
zrender/core/util
'
);
/**
* Coordinate Interface
*
* create:
* @param {module:echarts/model/Global} ecModel
* @param {module:echarts/ExtensionAPI} api
* @return {Object} coordinate system instance
*
* update:
* @param {module:echarts/model/Global} ecModel
* @param {module:echarts/ExtensionAPI} api
*
* isTargetCoordinate:
* @param {module:echarts/model/Global} ecModel
* @param {Object} finder key: mainType, value: component model
* e.g., {geo: geoModel, series: seriesModel}
* @return {boolean}
*
* convertToPixel:
* @param {module:echarts/model/Global} ecModel
* @param {Array|number} value
* @return {Array|number} convert result.
*/
var
coordinateSystemCreators
=
{};
function
CoordinateSystemManager
()
{
...
...
@@ -15,21 +41,49 @@ define(function(require) {
create
:
function
(
ecModel
,
api
)
{
var
coordinateSystems
=
[];
for
(
var
type
in
coordinateSystemCreators
)
{
if
(
coordinateSystemCreators
.
hasOwnProperty
(
type
))
{
var
list
=
coordinateSystemCreators
[
type
].
create
(
ecModel
,
api
);
list
&&
(
coordinateSystems
=
coordinateSystems
.
concat
(
list
));
}
}
zrUtil
.
each
(
coordinateSystemCreators
,
function
(
creater
,
type
)
{
var
list
=
creater
.
create
(
ecModel
,
api
);
coordinateSystems
=
coordinateSystems
.
concat
(
list
||
[]);
});
this
.
_coordinateSystems
=
coordinateSystems
;
},
update
:
function
(
ecModel
,
api
)
{
var
coordinateSystems
=
this
.
_coordinateSystems
;
for
(
var
i
=
0
;
i
<
coordinateSystems
.
length
;
i
++
)
{
zrUtil
.
each
(
this
.
_coordinateSystems
,
function
(
coordSys
)
{
// FIXME MUST have
coordinateSystems
[
i
].
update
&&
coordinateSystems
[
i
].
update
(
ecModel
,
api
);
coordSys
.
update
&&
coordSys
.
update
(
ecModel
,
api
);
});
},
/**
* Convert from coordinate system to pixel.
* @param {string|Object} finder
* If string, e.g., 'geo', means {geoIndex: 0}.
* If Object, could contain some of these properties below:
* {
* seriesIndex, seriesId,
* geoIndex, geoId,
* bmapIndex, bmapId,
* xAxisIndex, xAxisId,
* yAxisIndex, yAxisId,
* gridIndex, gridId,
* ... (can be extended)
* }
* @param {Array|number} value
*/
convertToPixel
:
function
(
ecModel
,
finder
,
value
)
{
finder
=
parseFinder
(
ecModel
,
finder
);
var
coordSysList
=
this
.
_coordinateSystems
;
for
(
var
i
=
0
;
i
<
coordSysList
.
length
;
i
++
)
{
var
coordSys
=
coordSysList
[
i
];
if
(
coordSys
.
isTargetCoordinateSystem
&&
coordSys
.
isTargetCoordinateSystem
(
ecModel
,
finder
)
&&
coordSys
.
convertToPixel
)
{
return
coordSys
.
convertToPixel
(
ecModel
,
value
);
}
}
}
};
...
...
@@ -42,5 +96,24 @@ define(function(require) {
return
coordinateSystemCreators
[
type
];
};
function
parseFinder
(
ecModel
,
finder
)
{
if
(
zrUtil
.
isString
(
finder
))
{
var
obj
=
{};
obj
[
finder
+
'
Index
'
]
=
0
;
finder
=
obj
;
}
var
result
=
{};
zrUtil
.
each
(
finder
,
function
(
value
,
key
)
{
key
=
key
.
match
(
/^
(\w
+
)(
Index|Id|Name
)
$/
);
var
queryParam
=
{
mainType
:
key
[
1
]};
queryParam
[
key
[
2
].
toLowerCase
()]
=
value
;
result
[
key
[
1
]]
=
ecModel
.
queryComponents
(
queryParam
)[
0
];
});
return
result
;
}
return
CoordinateSystemManager
;
});
\ No newline at end of file
src/coord/cartesian/Grid.js
浏览文件 @
d17731aa
...
...
@@ -406,11 +406,7 @@ define(function(require, factory) {
*/
function
findAxesModels
(
seriesModel
,
ecModel
)
{
return
zrUtil
.
map
(
axesTypes
,
function
(
axisType
)
{
var
axisModel
=
ecModel
.
queryComponents
({
mainType
:
axisType
,
index
:
seriesModel
.
get
(
axisType
+
'
Index
'
),
id
:
seriesModel
.
get
(
axisType
+
'
Id
'
)
})[
0
];
var
axisModel
=
seriesModel
.
getReferringComponents
(
axisType
)[
0
];
if
(
__DEV__
)
{
if
(
!
axisModel
)
{
...
...
src/coord/geo/Geo.js
浏览文件 @
d17731aa
...
...
@@ -221,7 +221,30 @@ define(function (require) {
if
(
data
)
{
return
View
.
prototype
.
dataToPoint
.
call
(
this
,
data
);
}
},
/**
* @implements
* see {module:echarts/CoodinateSystem}
*/
isTargetCoordinateSystem
:
function
(
ecModel
,
finder
)
{
var
geoModel
=
finder
.
geo
?
finder
.
geo
:
finder
.
series
?
finder
.
series
.
getReferringComponents
(
'
geo
'
)[
0
]
:
null
;
return
geoModel
&&
geoModel
.
coordinateSystem
===
this
;
},
/**
* @implements
* see {module:echarts/CoodinateSystem}
*/
convertToPixel
:
function
(
ecModel
,
value
)
{
return
this
.
dataToPoint
(
value
);
}
};
zrUtil
.
mixin
(
Geo
,
View
);
...
...
src/echarts.js
浏览文件 @
d17731aa
...
...
@@ -417,6 +417,16 @@ define(function (require) {
}
};
/**
* Convert from coordinate system to pixel.
* See CoordinateSystem#convertToPixel.
* @param {string|Object} finder
* @param {Array|number} value
*/
echartsProto
.
convertToPixel
=
function
(
finder
,
value
)
{
return
this
.
_coordSysMgr
.
convertToPixel
(
this
.
_model
,
finder
,
value
);
};
var
updateMethods
=
{
...
...
src/model/Component.js
浏览文件 @
d17731aa
...
...
@@ -140,6 +140,14 @@ define(function(require) {
this
.
__defaultOption
=
defaultOption
;
}
return
this
.
__defaultOption
;
},
getReferringComponents
:
function
(
mainType
)
{
return
this
.
ecModel
.
queryComponents
({
mainType
:
mainType
,
index
:
this
.
get
(
mainType
+
'
Index
'
,
true
),
id
:
this
.
get
(
mainType
+
'
Id
'
,
true
)
});
}
});
...
...
src/model/Global.js
浏览文件 @
d17731aa
...
...
@@ -262,9 +262,9 @@ define(function (require) {
* @param {Object} condition
* @param {string} condition.mainType
* @param {string} [condition.subType] If ignore, only query by mainType
* @param {number} [condition.index] Either input index or id or name.
* @param {string} [condition.id] Either input index or id or name.
* @param {string} [condition.name] Either input index or id or name.
* @param {number
|Array.<number>
} [condition.index] Either input index or id or name.
* @param {string
|Array.<string>
} [condition.id] Either input index or id or name.
* @param {string
|Array.<string>
} [condition.name] Either input index or id or name.
* @return {Array.<module:echarts/model/Component>}
*/
queryComponents
:
function
(
condition
)
{
...
...
test/ut/core/utHelper.js
浏览文件 @
d17731aa
...
...
@@ -135,6 +135,14 @@
for
(
var
i
=
0
;
i
<
context
.
chartCount
||
0
;
i
++
)
{
var
el
=
document
.
createElement
(
'
div
'
);
document
.
body
.
appendChild
(
el
);
el
.
style
.
cssText
=
[
'
width:200px
'
,
'
height:150px
'
,
'
position:absolute
'
,
'
bottom:0
'
,
'
right:0
'
,
'
visibility:hidden
'
].
join
(
'
;
'
);
els
.
push
(
el
);
charts
.
push
(
echarts
.
init
(
el
,
null
,
{
renderer
:
'
canvas
'
}));
}
...
...
test/ut/spec/component/dataZoom/helper.js
0 → 100755
浏览文件 @
d17731aa
describe
(
'
dataZoom/helper
'
,
function
()
{
var
utHelper
=
window
.
utHelper
;
var
helper
;
beforeAll
(
function
(
done
)
{
// jshint ignore:line
utHelper
.
resetPackageLoader
(
function
()
{
window
.
require
([
'
echarts/component/dataZoom/helper
'
],
function
(
h
)
{
helper
=
h
;
done
();
});
});
});
function
makeRecords
(
result
)
{
var
o
=
{};
helper
.
eachAxisDim
(
function
(
dimNames
)
{
o
[
dimNames
.
name
]
=
{};
var
r
=
result
[
dimNames
.
name
]
||
[];
for
(
var
i
=
0
;
i
<
r
.
length
;
i
++
)
{
o
[
dimNames
.
name
][
r
[
i
]]
=
true
;
}
});
return
o
;
}
describe
(
'
findLinkedNodes
'
,
function
()
{
function
forEachModel
(
models
,
callback
)
{
for
(
var
i
=
0
;
i
<
models
.
length
;
i
++
)
{
callback
(
models
[
i
]);
}
}
function
axisIndicesGetter
(
model
,
dimNames
)
{
return
model
[
dimNames
.
axisIndex
];
}
it
(
'
findLinkedNodes_base
'
,
function
(
done
)
{
var
models
=
[
{
xAxisIndex
:
[
1
,
2
],
yAxisIndex
:
[
0
]},
{
xAxisIndex
:
[
3
],
yAxisIndex
:
[
1
]},
{
xAxisIndex
:
[
5
],
yAxisIndex
:
[]},
{
xAxisIndex
:
[
2
,
5
],
yAxisIndex
:
[]}
];
var
result
=
helper
.
createLinkedNodesFinder
(
utHelper
.
curry
(
forEachModel
,
models
),
helper
.
eachAxisDim
,
axisIndicesGetter
)(
models
[
0
]);
expect
(
result
).
toEqual
({
nodes
:
[
models
[
0
],
models
[
3
],
models
[
2
]],
records
:
makeRecords
({
x
:
[
1
,
2
,
5
],
y
:
[
0
]})
});
done
();
});
it
(
'
findLinkedNodes_crossXY
'
,
function
(
done
)
{
var
models
=
[
{
xAxisIndex
:
[
1
,
2
],
yAxisIndex
:
[
0
]},
{
xAxisIndex
:
[
3
],
yAxisIndex
:
[
3
,
0
]},
{
xAxisIndex
:
[
6
,
3
],
yAxisIndex
:
[
9
]},
{
xAxisIndex
:
[
5
,
3
],
yAxisIndex
:
[]},
{
xAxisIndex
:
[
8
],
yAxisIndex
:
[
4
]}
];
var
result
=
helper
.
createLinkedNodesFinder
(
utHelper
.
curry
(
forEachModel
,
models
),
helper
.
eachAxisDim
,
axisIndicesGetter
)(
models
[
0
]);
expect
(
result
).
toEqual
({
nodes
:
[
models
[
0
],
models
[
1
],
models
[
2
],
models
[
3
]],
records
:
makeRecords
({
x
:
[
1
,
2
,
3
,
5
,
6
],
y
:
[
0
,
3
,
9
]})
});
done
();
});
it
(
'
findLinkedNodes_emptySourceModel
'
,
function
(
done
)
{
var
models
=
[
{
xAxisIndex
:
[
1
,
2
],
yAxisIndex
:
[
0
]},
{
xAxisIndex
:
[
3
],
yAxisIndex
:
[
3
,
0
]},
{
xAxisIndex
:
[
6
,
3
],
yAxisIndex
:
[
9
]},
{
xAxisIndex
:
[
5
,
3
],
yAxisIndex
:
[]},
{
xAxisIndex
:
[
8
],
yAxisIndex
:
[
4
]}
];
var
result
=
helper
.
createLinkedNodesFinder
(
utHelper
.
curry
(
forEachModel
,
models
),
helper
.
eachAxisDim
,
axisIndicesGetter
)();
expect
(
result
).
toEqual
({
nodes
:
[],
records
:
makeRecords
({
x
:
[],
y
:
[]})
});
done
();
});
});
});
\ No newline at end of file
test/ut/spec/coord/converter.js
0 → 100755
浏览文件 @
d17731aa
describe
(
'
coord/converter
'
,
function
()
{
var
utHelper
=
window
.
utHelper
;
var
DELTA
=
1
E
-
4
;
function
pointEquals
(
p1
,
p2
)
{
return
Math
.
abs
(
p1
[
0
]
-
p2
[
0
])
<
DELTA
&&
Math
.
abs
(
p1
[
1
]
-
p2
[
1
])
<
DELTA
;
}
var
testCase
=
utHelper
.
prepare
([
'
echarts/chart/map
'
,
'
echarts/chart/scatter
'
,
'
echarts/chart/graph
'
,
'
echarts/component/geo
'
,
'
echarts/component/grid
'
]);
var
testGeoJson1
=
{
'
type
'
:
'
FeatureCollection
'
,
'
features
'
:
[
{
'
geometry
'
:
{
'
type
'
:
'
Polygon
'
,
'
coordinates
'
:
[
[
[
2000
,
3000
],
[
5000
,
3000
],
[
5000
,
8000
],
[
2000
,
8000
]
]
]
},
'
properties
'
:
{
'
name
'
:
'
Afghanistan
'
,
'
childNum
'
:
1
}
}
]
};
var
testGeoJson2
=
{
'
type
'
:
'
FeatureCollection
'
,
'
features
'
:
[
{
'
geometry
'
:
{
'
type
'
:
'
Polygon
'
,
'
coordinates
'
:
[
[
[
200
,
300
],
[
500
,
300
],
[
500
,
800
],
[
200
,
800
]
]
]
},
'
properties
'
:
{
'
name
'
:
'
Afghanistan
'
,
'
childNum
'
:
1
}
}
]
};
testCase
.
createChart
()(
'
geo
'
,
function
()
{
this
.
echarts
.
registerMap
(
'
test1
'
,
testGeoJson1
);
this
.
echarts
.
registerMap
(
'
test2
'
,
testGeoJson2
);
var
chart
=
this
.
chart
;
chart
.
setOption
({
geo
:
[
{
id
:
'
aa
'
,
left
:
0
,
right
:
0
,
top
:
0
,
bottom
:
0
,
map
:
'
test1
'
},
{
id
:
'
bb
'
,
left
:
0
,
right
:
0
,
top
:
0
,
bottom
:
0
,
map
:
'
test2
'
}
],
series
:
[
{
id
:
'
k1
'
,
type
:
'
scatter
'
,
coordinateSystem
:
'
geo
'
,
geoIndex
:
1
},
{
id
:
'
k2
'
,
type
:
'
scatter
'
,
coordinateSystem
:
'
geo
'
}
]
});
var
width
=
chart
.
getWidth
();
var
height
=
chart
.
getHeight
();
expect
(
pointEquals
(
chart
.
convertToPixel
(
'
geo
'
,
[
5000
,
3000
]),
[
width
,
height
])).
toEqual
(
true
);
expect
(
pointEquals
(
chart
.
convertToPixel
({
geoIndex
:
1
},
[
500
,
800
]),
[
width
,
0
])).
toEqual
(
true
);
expect
(
pointEquals
(
chart
.
convertToPixel
({
geoId
:
'
bb
'
},
[
200
,
300
]),
[
0
,
height
])).
toEqual
(
true
);
expect
(
pointEquals
(
chart
.
convertToPixel
({
seriesIndex
:
0
},
[
200
,
800
]),
[
0
,
0
])).
toEqual
(
true
);
expect
(
pointEquals
(
chart
.
convertToPixel
({
seriesId
:
'
k2
'
},
[
2000
,
8000
]),
[
0
,
0
])).
toEqual
(
true
);
});
});
\ No newline at end of file
test/ut/spec/util/model.js
浏览文件 @
d17731aa
...
...
@@ -24,79 +24,6 @@ describe('util/model', function() {
return
o
;
}
describe
(
'
findLinkedNodes
'
,
function
()
{
function
forEachModel
(
models
,
callback
)
{
for
(
var
i
=
0
;
i
<
models
.
length
;
i
++
)
{
callback
(
models
[
i
]);
}
}
function
axisIndicesGetter
(
model
,
dimNames
)
{
return
model
[
dimNames
.
axisIndex
];
}
it
(
'
findLinkedNodes_base
'
,
function
(
done
)
{
var
models
=
[
{
xAxisIndex
:
[
1
,
2
],
yAxisIndex
:
[
0
]},
{
xAxisIndex
:
[
3
],
yAxisIndex
:
[
1
]},
{
xAxisIndex
:
[
5
],
yAxisIndex
:
[]},
{
xAxisIndex
:
[
2
,
5
],
yAxisIndex
:
[]}
];
var
result
=
modelUtil
.
createLinkedNodesFinder
(
utHelper
.
curry
(
forEachModel
,
models
),
modelUtil
.
eachAxisDim
,
axisIndicesGetter
)(
models
[
0
]);
expect
(
result
).
toEqual
({
nodes
:
[
models
[
0
],
models
[
3
],
models
[
2
]],
records
:
makeRecords
({
x
:
[
1
,
2
,
5
],
y
:
[
0
]})
});
done
();
});
it
(
'
findLinkedNodes_crossXY
'
,
function
(
done
)
{
var
models
=
[
{
xAxisIndex
:
[
1
,
2
],
yAxisIndex
:
[
0
]},
{
xAxisIndex
:
[
3
],
yAxisIndex
:
[
3
,
0
]},
{
xAxisIndex
:
[
6
,
3
],
yAxisIndex
:
[
9
]},
{
xAxisIndex
:
[
5
,
3
],
yAxisIndex
:
[]},
{
xAxisIndex
:
[
8
],
yAxisIndex
:
[
4
]}
];
var
result
=
modelUtil
.
createLinkedNodesFinder
(
utHelper
.
curry
(
forEachModel
,
models
),
modelUtil
.
eachAxisDim
,
axisIndicesGetter
)(
models
[
0
]);
expect
(
result
).
toEqual
({
nodes
:
[
models
[
0
],
models
[
1
],
models
[
2
],
models
[
3
]],
records
:
makeRecords
({
x
:
[
1
,
2
,
3
,
5
,
6
],
y
:
[
0
,
3
,
9
]})
});
done
();
});
it
(
'
findLinkedNodes_emptySourceModel
'
,
function
(
done
)
{
var
models
=
[
{
xAxisIndex
:
[
1
,
2
],
yAxisIndex
:
[
0
]},
{
xAxisIndex
:
[
3
],
yAxisIndex
:
[
3
,
0
]},
{
xAxisIndex
:
[
6
,
3
],
yAxisIndex
:
[
9
]},
{
xAxisIndex
:
[
5
,
3
],
yAxisIndex
:
[]},
{
xAxisIndex
:
[
8
],
yAxisIndex
:
[
4
]}
];
var
result
=
modelUtil
.
createLinkedNodesFinder
(
utHelper
.
curry
(
forEachModel
,
models
),
modelUtil
.
eachAxisDim
,
axisIndicesGetter
)();
expect
(
result
).
toEqual
({
nodes
:
[],
records
:
makeRecords
({
x
:
[],
y
:
[]})
});
done
();
});
});
describe
(
'
compressBatches
'
,
function
()
{
function
item
(
seriesId
,
dataIndex
)
{
...
...
test/ut/ut.js
浏览文件 @
d17731aa
...
...
@@ -7,7 +7,9 @@ document.write('<script src="spec/util/number.js"><\/script>');
document
.
write
(
'
<script src="spec/model/Component.js"><
\
/script>
'
);
document
.
write
(
'
<script src="spec/model/Global.js"><
\
/script>
'
);
document
.
write
(
'
<script src="spec/model/timelineOptions.js"><
\
/script>
'
);
document
.
write
(
'
<script src="spec/coord/converter.js"><
\
/script>
'
);
document
.
write
(
'
<script src="spec/data/List.js"><
\
/script>
'
);
document
.
write
(
'
<script src="spec/component/visualMap/setOption.js"><
\
/script>
'
);
document
.
write
(
'
<script src="spec/component/dataZoom/helper.js"><
\
/script>
'
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录