提交 cfe39961 编写于 作者: P pah100

Fix #5874 (postion not work when dispatch 'showTip' manually)

上级 95c42c49
...@@ -43,19 +43,6 @@ define(function (require) { ...@@ -43,19 +43,6 @@ define(function (require) {
type: 'updateAxisPointer', type: 'updateAxisPointer',
event: 'updateAxisPointer', event: 'updateAxisPointer',
update: ':updateAxisPointer' update: ':updateAxisPointer'
}, function (payload, ecModel, api) { }, axisTrigger);
var outputFinder = axisTrigger(
ecModel.getComponent('axisPointer').coordSysAxesInfo,
payload.currTrigger,
[payload.x, payload.y],
payload,
payload.dispatchAction || zrUtil.bind(api.dispatchAction, api),
ecModel,
api,
payload.tooltipOption
);
return outputFinder;
});
}); });
\ No newline at end of file
...@@ -14,26 +14,35 @@ define(function(require) { ...@@ -14,26 +14,35 @@ define(function(require) {
* then hide/downplay them. * then hide/downplay them.
* *
* @param {Object} coordSysAxesInfo * @param {Object} coordSysAxesInfo
* @param {string} [currTrigger] 'click' | 'mousemove' | 'leave' * @param {Object} payload
* @param {Array.<number>} [point] x and y, which are mandatory, specify a point to * @param {string} [payload.currTrigger] 'click' | 'mousemove' | 'leave'
* @param {Array.<number>} [payload.x] x and y, which are mandatory, specify a point to
* tigger axisPointer and tooltip. * tigger axisPointer and tooltip.
* @param {Object} [finder] { * @param {Array.<number>} [payload.y] x and y, which are mandatory, specify a point to
* seriesIndex, dataIndex, * tigger axisPointer and tooltip.
* axesInfo: [{ * @param {Object} [payload.seriesIndex] finder, optional, restrict target axes.
* axisDim: 'x'|'y'|'angle'|..., axisIndex: ..., value: ... * @param {Object} [payload.dataIndex] finder, restrict target axes.
* }, ...] * @param {Object} [payload.axesInfo] finder, restrict target axes.
* } * [{
* These properties, which are optional, restrict target axes. * axisDim: 'x'|'y'|'angle'|...,
* @param {Function} dispatchAction * axisIndex: ...,
* value: ...
* }, ...]
* @param {Function} [payload.dispatchAction]
* @param {Object} [payload.tooltipOption]
* @param {Object|Array.<number>|Function} [payload.position] Tooltip position,
* which can be specified in dispatchAction
* @param {module:echarts/model/Global} ecModel
* @param {module:echarts/ExtensionAPI} api * @param {module:echarts/ExtensionAPI} api
* @param {Object} [tooltipOption]
* @return {Object} content of event obj for echarts.connect. * @return {Object} content of event obj for echarts.connect.
*/ */
function axisTrigger( function axisTrigger(payload, ecModel, api) {
coordSysAxesInfo, currTrigger, point, finder, dispatchAction, var currTrigger = payload.currTrigger;
ecModel, api, tooltipOption var point = [payload.x, payload.y];
) { var finder = payload;
finder = finder || {}; var dispatchAction = payload.dispatchAction || zrUtil.bind(api.dispatchAction, api);
var coordSysAxesInfo = ecModel.getComponent('axisPointer').coordSysAxesInfo;
if (illegalPoint(point)) { if (illegalPoint(point)) {
// Used in the default behavior of `connection`: use the sample seriesIndex // Used in the default behavior of `connection`: use the sample seriesIndex
// and dataIndex. And also used in the tooltipView trigger. // and dataIndex. And also used in the tooltipView trigger.
...@@ -107,7 +116,7 @@ define(function(require) { ...@@ -107,7 +116,7 @@ define(function(require) {
}); });
updateModelActually(showValueMap, axesInfo, outputFinder); updateModelActually(showValueMap, axesInfo, outputFinder);
dispatchTooltipActually(dataByCoordSys, point, tooltipOption, dispatchAction); dispatchTooltipActually(dataByCoordSys, point, payload, dispatchAction);
dispatchHighDownActually(axesInfo, dispatchAction, api); dispatchHighDownActually(axesInfo, dispatchAction, api);
return outputFinder; return outputFinder;
...@@ -290,7 +299,7 @@ define(function(require) { ...@@ -290,7 +299,7 @@ define(function(require) {
}); });
} }
function dispatchTooltipActually(dataByCoordSys, point, tooltipOption, dispatchAction) { function dispatchTooltipActually(dataByCoordSys, point, payload, dispatchAction) {
// Basic logic: If no showTip required, hideTip will be dispatched. // Basic logic: If no showTip required, hideTip will be dispatched.
if (illegalPoint(point) || !dataByCoordSys.list.length) { if (illegalPoint(point) || !dataByCoordSys.list.length) {
dispatchAction({type: 'hideTip'}); dispatchAction({type: 'hideTip'});
...@@ -308,7 +317,8 @@ define(function(require) { ...@@ -308,7 +317,8 @@ define(function(require) {
escapeConnect: true, escapeConnect: true,
x: point[0], x: point[0],
y: point[1], y: point[1],
tooltipOption: tooltipOption, tooltipOption: payload.tooltipOption,
position: payload.position,
dataIndexInside: sampleItem.dataIndexInside, dataIndexInside: sampleItem.dataIndexInside,
dataIndex: sampleItem.dataIndex, dataIndex: sampleItem.dataIndex,
seriesIndex: sampleItem.seriesIndex, seriesIndex: sampleItem.seriesIndex,
......
...@@ -265,7 +265,8 @@ define(function (require) { ...@@ -265,7 +265,8 @@ define(function (require) {
api.dispatchAction({ api.dispatchAction({
type: 'updateAxisPointer', type: 'updateAxisPointer',
seriesIndex: seriesIndex, seriesIndex: seriesIndex,
dataIndex: dataIndex dataIndex: dataIndex,
position: payload.position
}); });
return true; return true;
......
...@@ -40,6 +40,8 @@ ...@@ -40,6 +40,8 @@
<div class="chart" id="position"></div> <div class="chart" id="position"></div>
<h1>triggerOn click</h1> <h1>triggerOn click</h1>
<div class="chart" id="click"></div> <div class="chart" id="click"></div>
<h1>dispatchAciton manually with `position` specified (postion: [10,10])</h1>
<div class="chart" id="positionSpecified"></div>
<!--<h1>alwaysShowContent (check when hover on the last one, the content should not be the previous one)</h1>--> <!--<h1>alwaysShowContent (check when hover on the last one, the content should not be the previous one)</h1>-->
<!--<div class="chart" id="alwaysShowContent"></div>--> <!--<div class="chart" id="alwaysShowContent"></div>-->
...@@ -646,6 +648,168 @@ ...@@ -646,6 +648,168 @@
<script>
require([
'echarts',
'echarts/chart/line',
'echarts/component/legend',
'echarts/component/grid',
'echarts/component/tooltip',
'zrender/vml/vml'
], function (echarts) {
var option = {
title: {
text: '未来一周气温变化',
subtext: '纯属虚构'
},
tooltip: {
trigger: 'axis'
},
legend: {
data:['最高气温','最低气温']
},
toolbox: {
show: true,
feature: {
dataZoom: {
yAxisIndex: 'none'
},
dataView: {readOnly: false},
magicType: {type: ['line', 'bar']},
restore: {},
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: ['周一','周二','周三','周四','周五','周六','周日']
},
yAxis: {
type: 'value',
axisLabel: {
formatter: '{value} °C'
}
},
series: [
{
name:'最高气温',
type:'line',
data:[11, 11, 15, 13, 12, 13, 10],
markPoint: {
data: [
{type: 'max', name: '最大值'},
{type: 'min', name: '最小值'}
]
},
markLine: {
data: [
{type: 'average', name: '平均值'}
]
}
},
{
name:'最低气温',
type:'line',
data:[1, -2, 2, 5, 3, 2, 0],
markPoint: {
data: [
{name: '周最低', value: -2, xAxis: 1, yAxis: -1.5}
]
},
markLine: {
data: [
{type: 'average', name: '平均值'},
[{
symbol: 'none',
x: '90%',
yAxis: 'max'
}, {
symbol: 'circle',
label: {
normal: {
position: 'start',
formatter: '最大值'
}
},
type: 'max',
name: '最高点'
}]
]
}
}
]
};
var chart = createChart('positionSpecified', echarts, option, 500);
setTimeout(function () {
chart.dispatchAction({
type: 'showTip',
seriesIndex: 0,
dataIndex: 0,
position: function () {
return [10, 10];
}
})
}, 1000);
})
</script>
<script>
require([
'echarts',
'echarts/chart/line',
'echarts/component/legend',
'echarts/component/grid',
'echarts/component/tooltip',
'zrender/vml/vml'
], function (echarts) {
var option = {
tooltip: {
trigger: 'axis',
triggerOn: 'click',
axisPointer: {
type: 'cross'
}
}
};
var baseTop = 90;
var height = 150;
var gap = 50;
makeCategoryGrid(option, {
grid: {top: baseTop, height: height},
yAxis: {
name: 'click show tip',
tooltip: {
show: true
}
}
});
baseTop += height + gap;
createChart('click', echarts, option, baseTop);
})
</script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册