提交 11d3a50f 编写于 作者: S susiwen8

tooltip unified function

上级 76c645bc
......@@ -21,7 +21,7 @@
import * as zrUtil from 'zrender/src/core/util';
import createListSimply from '../helper/createListSimply';
import SeriesModel from '../../model/Series';
import {encodeHTML, addCommas} from '../../util/format';
import {encodeHTML, addCommas, concatTooltipHtml} from '../../util/format';
import {DataSelectableMixin, DataSelectableOptionMixin, SelectableTarget} from '../../component/helper/selectableMixin';
import {retrieveRawAttr} from '../../data/helper/dataProvider';
import geoSourceManager from '../../coord/geo/geoSourceManager';
......@@ -223,7 +223,7 @@ class MapSeries extends SeriesModel<MapSeriesOption> {
}
return seriesNames.join(', ') + '<br />'
+ encodeHTML(name + ' : ' + formattedValue);
+ concatTooltipHtml(encodeHTML(name), formattedValue);
}
getTooltipPosition = function (this: MapSeries, dataIndex: number): number[] {
......
......@@ -20,7 +20,7 @@
import SeriesModel from '../../model/Series';
import createListSimply from '../helper/createListSimply';
import * as zrUtil from 'zrender/src/core/util';
import {encodeHTML} from '../../util/format';
import {encodeHTML, concatTooltipHtml} from '../../util/format';
import LegendVisualProvider from '../../visual/LegendVisualProvider';
import {
SeriesOption,
......@@ -113,8 +113,8 @@ class RadarSeriesModel extends SeriesModel<RadarSeriesOption> {
return encodeHTML(name === '' ? this.name : name) + '<br/>'
+ zrUtil.map(indicatorAxes, function (axis, idx) {
const val = data.get(data.mapDimension(axis.dim), dataIndex);
return '<p style="margin: 8px 0 0;">' + encodeHTML(axis.name)
+ `<strong style="float:right;margin-left:20px;color:#000;">${val}</strong>`
return '<p style="margin: 8px 0 0;">'
+ concatTooltipHtml(encodeHTML(axis.name), val)
+ '</p>';
}).join('');
}
......
......@@ -19,7 +19,7 @@
import SeriesModel from '../../model/Series';
import createGraphFromNodeEdge from '../helper/createGraphFromNodeEdge';
import {encodeHTML} from '../../util/format';
import {encodeHTML, concatTooltipHtml} from '../../util/format';
import Model from '../../model/Model';
import { __DEV__ } from '../../config';
import {
......@@ -238,18 +238,15 @@ class SankeySeriesModel extends SeriesModel<SankeySeriesOption> {
if (dataType === 'edge') {
const params = this.getDataParams(dataIndex, dataType);
const rawDataOpt = params.data;
let html = rawDataOpt.source + ' -- ' + rawDataOpt.target;
if (params.value) {
html += ' : ' + params.value;
}
return encodeHTML(html);
const html = encodeHTML(rawDataOpt.source + ' -- ' + rawDataOpt.target);
return concatTooltipHtml(html, params.value || '');
}
else if (dataType === 'node') {
const node = this.getGraph().getNodeByIndex(dataIndex);
const value = node.getLayout().value;
const name = this.getDataParams(dataIndex, dataType).data.name;
const html = value ? name + ' : ' + value : '';
return encodeHTML(html);
const html = encodeHTML(value ? name : '');
return concatTooltipHtml(html, value || '');
}
return super.formatTooltip(dataIndex, multipleSeries);
}
......
......@@ -23,7 +23,7 @@ import {getDimensionTypeByAxis} from '../../data/helper/dimensionHelper';
import List from '../../data/List';
import * as zrUtil from 'zrender/src/core/util';
import {groupData} from '../../util/model';
import {encodeHTML} from '../../util/format';
import {encodeHTML, concatTooltipHtml} from '../../util/format';
import LegendVisualProvider from '../../visual/LegendVisualProvider';
import {
SeriesOption,
......@@ -308,7 +308,11 @@ class ThemeRiverSeriesModel extends SeriesModel<ThemeRiverSeriesOption> {
if (isNaN(htmlValue as number) || htmlValue == null) {
htmlValue = '-';
}
return encodeHTML(htmlName + ' : ' + htmlValue);
return `
<p style="margin: 8px 0 0;">
${concatTooltipHtml(encodeHTML(htmlName), htmlValue)}
</p>
`;
}
static defaultOption: ThemeRiverSeriesOption = {
......
......@@ -19,7 +19,7 @@
import SeriesModel from '../../model/Series';
import Tree from '../../data/Tree';
import {encodeHTML} from '../../util/format';
import {encodeHTML, concatTooltipHtml} from '../../util/format';
import {
SeriesOption,
SymbolOptionMixin,
......@@ -230,9 +230,8 @@ class TreeSeriesModel extends SeriesModel<TreeSeriesOption> {
name = node.parentNode.name + '.' + name;
node = node.parentNode;
}
return encodeHTML(name + (
(isNaN(value as number) || value == null) ? '' : ' : ' + value
));
return concatTooltipHtml(encodeHTML(name), (isNaN(value as number) || value == null) ? '' : value);
}
static defaultOption: TreeSeriesOption = {
......
......@@ -21,7 +21,7 @@ import * as zrUtil from 'zrender/src/core/util';
import SeriesModel from '../../model/Series';
import Tree, { TreeNode } from '../../data/Tree';
import Model from '../../model/Model';
import {encodeHTML, addCommas} from '../../util/format';
import {encodeHTML, addCommas, concatTooltipHtml} from '../../util/format';
import {wrapTreePathInfo} from '../helper/treeHelper';
import {
SeriesOption,
......@@ -387,7 +387,7 @@ class TreemapSeriesModel extends SeriesModel<TreemapSeriesOption> {
? addCommas(value[0] as number) : addCommas(value as number);
const name = data.getName(dataIndex);
return encodeHTML(name + ': ' + formattedValue);
return concatTooltipHtml(encodeHTML(name), formattedValue);
}
/**
......
......@@ -20,7 +20,7 @@
import {__DEV__} from '../../config';
import * as zrUtil from 'zrender/src/core/util';
import env from 'zrender/src/core/env';
import * as formatUtil from '../../util/format';
import {addCommas, encodeHTML, concatTooltipHtml} from '../../util/format';
import DataFormatMixin from '../../model/mixin/dataFormat';
import ComponentModel from '../../model/Component';
import SeriesModel from '../../model/Series';
......@@ -37,9 +37,6 @@ import GlobalModel from '../../model/Global';
import List from '../../data/List';
import { makeInner, defaultEmphasis } from '../../util/model';
const addCommas = formatUtil.addCommas;
const encodeHTML = formatUtil.encodeHTML;
function fillLabel(opt: DisplayStateHostOption) {
defaultEmphasis(opt, 'label', ['show']);
}
......@@ -218,7 +215,7 @@ abstract class MarkerModel<Opts extends MarkerOption = MarkerOption> extends Com
}
}
if (value != null) {
html += encodeHTML(formattedValue);
html = concatTooltipHtml(html, encodeHTML(formattedValue));
}
return html;
}
......
......@@ -525,7 +525,7 @@ class SeriesModel<Opt extends SeriesOption = SeriesOption> extends ComponentMode
colorStr = typeof colorEl === 'string' ? colorEl : colorEl.content;
const html = !multipleSeries
? seriesName + '<br/>' + '<p style="margin: 8px 0 0;">' + colorStr
? seriesName + (seriesName ? '<br/>' : '') + '<p style="margin: 8px 0 0;">' + colorStr
+ (name
? `${encodeHTML(name)}${content}`
: content
......
......@@ -66,6 +66,10 @@ export function encodeHTML(source: string): string {
});
}
export function concatTooltipHtml(html: string, value: unknown): string {
return `${html}<strong style="float:right;margin-left:20px;color:#000;">${value || ''}</strong>`;
}
const TPL_VAR_ALIAS = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
const wrapVar = function (varName: string, seriesIdx?: number): string {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册