Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
半栈学徒
incubator-echarts
提交
639354b6
I
incubator-echarts
项目概览
半栈学徒
/
incubator-echarts
与 Fork 源项目一致
从无法访问的项目Fork
通知
5
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,发现更多精彩内容 >>
提交
639354b6
编写于
11月 20, 2019
作者:
O
Ovilia
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
WIP(axisPointer): snapping logic WIP.
上级
bba490f3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
99 addition
and
14 deletion
+99
-14
src/component/axisPointer/axisTrigger.js
src/component/axisPointer/axisTrigger.js
+99
-14
未找到文件。
src/component/axisPointer/axisTrigger.js
浏览文件 @
639354b6
...
@@ -97,19 +97,92 @@ export default function (payload, ecModel, api) {
...
@@ -97,19 +97,92 @@ export default function (payload, ecModel, api) {
// Process for triggered axes.
// Process for triggered axes.
each
(
coordSysAxesInfo
.
coordSysMap
,
function
(
coordSys
,
coordSysKey
)
{
each
(
coordSysAxesInfo
.
coordSysMap
,
function
(
coordSys
,
coordSysKey
)
{
/**
* If both x and y axes are snapping and one and only one of them is
* of category type, then the category axis is used as primary
* snapping, otherwise the baseAxis is used as primary snapping.
* The snapped value of the other axis is calculated from it.
*
* 4 | *
* 3 | *
* 2 | *
* 1 | * +
* ---------------------
* a b c d
*
* In the above example, the x axis is in category type, and y axis
* value.
* The *'s are data items, + is the mouse position.
*
* If both x and y axes are using snapping, then:
* 1. x axis is used as primary snapping axis because it's the only
* category axis.
* 2. The nearest x value to the mouse is 'b', so 'b' is used as
* snapped x value.
* 3. The corresponding y value of 'b' is 3, so 3 is used as snapped y
* value.
* 4. So the axisPointer should be at ('b', 3).
*
* If only x is snapping, then the axisPointer should be at ('b', 1).
* If only y is snapping, then the axisPointer should be at the
* position of +.
*/
// If a point given, it must be contained by the coordinate system.
// If a point given, it must be contained by the coordinate system.
var
coordSysContainsPoint
=
isIllegalPoint
||
coordSys
.
containPoint
(
point
);
var
coordSysContainsPoint
=
isIllegalPoint
||
coordSys
.
containPoint
(
point
);
var
snapXor
;
// One and only one of the axes is snapping
var
snapBoth
=
true
;
// Both axes are snapping
var
primarySnapAxis
;
each
(
coordSysAxesInfo
.
coordSysAxesInfo
[
coordSysKey
],
function
(
axisInfo
)
{
if
(
snapXor
===
undefined
)
{
snapXor
=
axisInfo
.
snap
;
}
else
{
snapXor
=
snapXor
&&
!
axisInfo
.
snap
||
!
snapXor
&&
axisInfo
.
snap
;
}
snapBoth
=
snapBoth
&&
axisInfo
.
snap
;
axisInfo
.
snap
&&
(
primarySnapAxis
=
axisInfo
.
axis
);
});
if
(
!
snapBoth
&&
!
snapXor
)
{
// Snap none
return
;
}
if
(
!
snapXor
)
{
// Snap both
var
coord
=
coordSys
.
getCartesians
()[
0
];
primarySnapAxis
=
coord
.
getBaseAxis
()
// coord.getOtherAxis(coord.getBaseAxis());
}
var
primaryPayload
;
each
(
coordSysAxesInfo
.
coordSysAxesInfo
[
coordSysKey
],
function
(
axisInfo
,
key
)
{
each
(
coordSysAxesInfo
.
coordSysAxesInfo
[
coordSysKey
],
function
(
axisInfo
,
key
)
{
var
axis
=
axisInfo
.
axis
;
var
axis
=
axisInfo
.
axis
;
var
inputAxisInfo
=
findInputAxisInfo
(
inputAxesInfo
,
axisInfo
);
if
(
axis
===
primarySnapAxis
)
{
// If no inputAxesInfo, no axis is restricted.
var
inputAxisInfo
=
findInputAxisInfo
(
inputAxesInfo
,
axisInfo
);
if
(
!
shouldHide
&&
coordSysContainsPoint
&&
(
!
inputAxesInfo
||
inputAxisInfo
))
{
// If no inputAxesInfo, no axis is restricted.
var
val
=
inputAxisInfo
&&
inputAxisInfo
.
value
;
if
(
!
shouldHide
&&
coordSysContainsPoint
&&
(
!
inputAxesInfo
||
inputAxisInfo
))
{
if
(
val
==
null
&&
!
isIllegalPoint
)
{
var
val
=
inputAxisInfo
&&
inputAxisInfo
.
value
;
if
(
val
==
null
&&
!
isIllegalPoint
)
{
val
=
axis
.
pointToData
(
point
);
}
axisInfo
.
isPrimarySnap
=
true
;
if
(
val
!=
null
)
{
primaryPayload
=
processOnAxis
(
axisInfo
,
val
,
updaters
,
false
,
outputFinder
);
}
}
}
else
{
if
(
axisInfo
.
snap
)
{
// Secondary snapping axis
val
=
axis
.
pointToData
(
point
);
val
=
axis
.
pointToData
(
point
);
axisInfo
.
isPrimarySnap
=
false
;
if
(
primaryPayload
)
{
axisInfo
.
primarySnapToValue
=
primaryPayload
.
snapToValue
;
}
val
!=
null
&&
processOnAxis
(
axisInfo
,
val
,
updaters
,
false
,
outputFinder
);
}
}
val
!=
null
&&
processOnAxis
(
axisInfo
,
val
,
updaters
,
false
,
outputFinder
);
}
}
});
});
});
});
...
@@ -180,6 +253,8 @@ function processOnAxis(axisInfo, newValue, updaters, dontSnap, outputFinder) {
...
@@ -180,6 +253,8 @@ function processOnAxis(axisInfo, newValue, updaters, dontSnap, outputFinder) {
// Tooltip should always be snapToValue, otherwise there will be
// Tooltip should always be snapToValue, otherwise there will be
// incorrect "axis value ~ series value" mapping displayed in tooltip.
// incorrect "axis value ~ series value" mapping displayed in tooltip.
updaters
.
showTooltip
(
axisInfo
,
payloadInfo
,
snapToValue
);
updaters
.
showTooltip
(
axisInfo
,
payloadInfo
,
snapToValue
);
return
payloadInfo
;
}
}
function
buildPayloadsBySeries
(
value
,
axisInfo
)
{
function
buildPayloadsBySeries
(
value
,
axisInfo
)
{
...
@@ -191,6 +266,10 @@ function buildPayloadsBySeries(value, axisInfo) {
...
@@ -191,6 +266,10 @@ function buildPayloadsBySeries(value, axisInfo) {
var
minDiff
=
-
1
;
var
minDiff
=
-
1
;
each
(
axisInfo
.
seriesModels
,
function
(
series
,
idx
)
{
each
(
axisInfo
.
seriesModels
,
function
(
series
,
idx
)
{
if
(
!
axisInfo
.
isPrimarySnap
&&
idx
>
0
)
{
return
;
}
var
dataDim
=
series
.
getData
().
mapDimension
(
dim
,
true
);
var
dataDim
=
series
.
getData
().
mapDimension
(
dim
,
true
);
var
seriesNestestValue
;
var
seriesNestestValue
;
var
dataIndices
;
var
dataIndices
;
...
@@ -201,14 +280,20 @@ function buildPayloadsBySeries(value, axisInfo) {
...
@@ -201,14 +280,20 @@ function buildPayloadsBySeries(value, axisInfo) {
seriesNestestValue
=
result
.
nestestValue
;
seriesNestestValue
=
result
.
nestestValue
;
}
}
else
{
else
{
dataIndices
=
series
.
getData
().
indicesOfNearest
(
if
(
isPrimarySnap
)
{
dataDim
[
0
],
dataIndices
=
series
.
getData
().
indicesOfNearest
(
value
,
dataDim
[
0
],
// Add a threshold to avoid find the wrong dataIndex
value
,
// when data length is not same.
// Add a threshold to avoid find the wrong dataIndex
// false,
// when data length is not same.
axis
.
type
===
'
category
'
?
0.5
:
null
// false,
);
axis
.
type
===
'
category
'
?
0.5
:
null
);
}
else
{
// TODO: find somewhere to put primarySnapDataIndex into axisInfo?
dataIndices
=
axisInfo
.
primarySnapDataIndex
==
null
?
[]
:
[
axisInfo
.
primarySnapDataIndex
];
}
if
(
!
dataIndices
.
length
)
{
if
(
!
dataIndices
.
length
)
{
return
;
return
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录