提交 4f9fd8b0 编写于 作者: P pah100

tooltip datazoom fix

上级 ac0e6c72
......@@ -229,8 +229,7 @@ define(function (require) {
*/
this._lastHover = {
// data
// dataIndex
// seriesIndex
// payloadBatch
};
var tooltipContent = this._tooltipContent;
......@@ -724,35 +723,35 @@ define(function (require) {
var rootTooltipModel = this._tooltipModel;
var tooltipContent = this._tooltipContent;
var data = seriesList[0].getData();
var baseAxis = coordSys.getBaseAxis();
var val = value[baseAxis.dim === 'x' ? 0 : 1];
var dataIndex = data.indexOfNearest(baseAxis.dim, val);
// FIXME
// Dont case by case
var val = value[baseAxis.dim === 'x' || baseAxis.dim === 'radius' ? 0 : 1];
var payloadBatch = zrUtil.map(seriesList, function (series) {
return {
seriesIndex: series.seriesIndex,
dataIndex: series.getData().indexOfNearest(baseAxis.dim, val)
};
});
var api = this._api;
// FIXME Not here
var lastHover = this._lastHover;
if (lastHover.seriesIndex != null && !contentNotChange) {
if (lastHover.payloadBatch && !contentNotChange) {
this._api.dispatchAction({
type: 'downplay',
seriesIndex: lastHover.seriesIndex,
dataIndex: lastHover.dataIndex
batch: zrUtil.clone(lastHover.payloadBatch, true)
});
}
// Dispatch highlight action
if (!contentNotChange) {
var seriesIndices = zrUtil.map(seriesList, function (series) {
return series.seriesIndex;
});
this._api.dispatchAction({
type: 'highlight',
seriesIndex: seriesIndices,
dataIndex: dataIndex
batch: zrUtil.clone(payloadBatch, true)
});
lastHover.seriesIndex = seriesIndices;
lastHover.dataIndex = dataIndex;
lastHover.payloadBatch = payloadBatch;
}
if (baseAxis && rootTooltipModel.get('showContent')) {
......@@ -761,8 +760,8 @@ define(function (require) {
var positionExpr = rootTooltipModel.get('position');
var html;
var paramsList = zrUtil.map(seriesList, function (series) {
return series.getDataParams(dataIndex);
var paramsList = zrUtil.map(seriesList, function (series, index) {
return series.getDataParams(payloadBatch[index].dataIndex);
});
// If only one series
// FIXME
......@@ -773,14 +772,16 @@ define(function (require) {
tooltipContent.show(rootTooltipModel);
// Update html content
var fitstDataIndex = payloadBatch[0].dataIndex;
if (!contentNotChange) {
// Reset ticket
this._ticket = '';
if (!formatter) {
// Default tooltip content
html = data.getName(dataIndex) + '<br />'
+ zrUtil.map(seriesList, function (series) {
return series.formatTooltip(dataIndex, true);
// FIXME shold be the first data which has name?
html = seriesList[0].getData().getName(fitstDataIndex) + '<br />'
+ zrUtil.map(seriesList, function (series, index) {
return series.formatTooltip(payloadBatch[index].dataIndex, true);
}).join('<br />');
}
else {
......@@ -789,7 +790,7 @@ define(function (require) {
}
else if (typeof formatter === 'function') {
var self = this;
var ticket = 'axis_' + coordSys.name + '_' + dataIndex;
var ticket = 'axis_' + coordSys.name + '_' + fitstDataIndex;
var callback = function (cbTicket, html) {
if (cbTicket === self._ticket) {
tooltipContent.setContent(html);
......@@ -905,11 +906,10 @@ define(function (require) {
*/
_hideAxisPointer: function (coordSysName) {
var lastHover = this._lastHover;
if (lastHover.seriesIndex != null && lastHover.dataIndex != null) {
if (lastHover.payloadBatch) {
this._api.dispatchAction({
type: 'downplay',
seriesIndex: lastHover.seriesIndex,
dataIndex: lastHover.dataIndex
batch: lastHover.payloadBatch
});
}
// Reset lastHover
......
......@@ -328,10 +328,12 @@ define(function (require) {
ecModel.eachComponent(
{mainType: 'series', query: payload},
function (seriesModel) {
function (seriesModel, index, payloadInfo) {
var chartView = this._chartsMap[seriesModel.id];
if (chartView) {
chartView[method](seriesModel, ecModel, this._api, payload);
chartView[method](
seriesModel, ecModel, this._api, payloadInfo
);
}
},
this
......
......@@ -237,14 +237,37 @@ define(function (require) {
* {mainType: 'dataZoom', query: {dataZoomId: 'abc'}},
* function (model, index) {...}
* );
*
* findComponents(
* {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}},
* function (model, index) {...}
* );
* findComponents(
*
* var result = findComponents(
* {mainType: 'series'},
* function (model, index) {...}
* );
* // result like [component0, componnet1, ...]
*
* var result = findComponents(
* {mainType: 'series', query: {
* type: 'someAction'
* batch: [
* {seriesId: 'asdf', dataIndex: 6},
* {seriesId: 'qwer', dataIndex: 4},
* ...
* ]
* }}
* )
* result like [component0, component1, component2]
* result.batchQueries like [
* {type: 'someAction', seriesId: 'qwer', dataIndex: 4},
* {type: 'someAction', seriesId: 'qwer', dataIndex: 4},
* {type: 'someAction', seriesId: 'asdf', dataIndex: 6},
* ...
* ]
* where each item of batchQueryies is coresponding to each item of result.
*
*
* @param {Object} condition
* @param {string} condition.mainType Mandatory.
......@@ -254,31 +277,55 @@ define(function (require) {
* If query attribute is null/undefined, do not filtering by
* query conditions, which is convenient for no-payload
* situations like visual coding, layout.
* If query.batch is an array, query by each batch item.
* @param {Function} [condition.filter] parameter: component, return boolean.
* @return {Array.<module:echarts/model/Component>} If condition.query.batch
* exist, result by batch is stored on 'batch' prop of returned array,
* see example above;
*/
findComponents: function (condition) {
var mainType = condition.mainType;
var query = condition.query;
var result;
if (query) {
condition.index = query[mainType + 'Index'];
condition.id = query[mainType + 'Id'];
condition.name = query[mainType + 'Name'];
var mainType = condition.mainType;
var subType = condition.subType;
result = this.queryComponents(condition);
if (!query) {
return doFilter(filterBySubType(
this._componentsMap[mainType], condition
));
}
else if (query.batch) {
var result = [];
var batchQueries = result.batchQueries = [];
each(query.batch, function (batchItem) {
batchItem = zrUtil.defaults(zrUtil.extend({}, batchItem), query);
batchItem.batch = null;
var res = doFilter(this.queryComponents(getCond(batchItem)));
each(res, function (re) {
result.push(re);
batchQueries.push(batchItem);
});
}, this);
return result;
}
else {
result = filterBySubType(
this._componentsMap[mainType], condition
);
return doFilter(this.queryComponents(getCond(query)));
}
if (condition.filter) {
result = filter(result, condition.filter);
function getCond(q) {
return {
mainType: mainType,
subType: subType,
index: q[mainType + 'Index'],
id: q[mainType + 'Id'],
name: q[mainType + 'Name']
};
}
return result;
function doFilter(res) {
return condition.filter
? filter(res, condition.filter)
: res;
}
},
/**
......@@ -292,12 +339,17 @@ define(function (require) {
* });
* eachComponent(
* {mainType: 'dataZoom', query: {dataZoomId: 'abc'}},
* function (model, index) {...}
* function (model, index, queryInfo) {...}
* );
* eachComponent(
* {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}},
* function (model, index) {...}
* function (model, index, queryInfo) {...}
* );
* eachComponent(
* {mainType: 'series', subType: 'pie', query: {batch: [ ... ]}},
* function (model, index, queryInfo) {...}
* );
* where query info is always an object but not null.
*
* @param {string|Object=} mainType When mainType is object, the definition
* is the same as the method 'findComponents'.
......@@ -317,10 +369,19 @@ define(function (require) {
});
}
else if (zrUtil.isString(mainType)) {
each(componentsMap[mainType], cb, context);
each(componentsMap[mainType], function (cpt, index) {
cb.call(context, cpt, index, {});
}, context);
}
else if (isObject(mainType)) {
each(this.findComponents(mainType), cb, context);
var queryResult = this.findComponents(mainType);
each(queryResult, function (cpt, index) {
var batchQueries = queryResult.batchQueries;
cb.call(
context, cpt, index,
batchQueries ? batchQueries[index] : mainType.query
);
});
}
},
......@@ -661,7 +722,7 @@ define(function (require) {
* @inner
*/
function filterBySubType(components, condition) {
return condition.hasOwnProperty('subType')
return condition.subType !== void 0
? filter(components, function (cpt) {
return cpt.subType === condition.subType;
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册