Skip to content

Commit

Permalink
Merge pull request #16332 from apache/tooltip-value-formatter
Browse files Browse the repository at this point in the history
add valueFormatter in tooltip
  • Loading branch information
pissang authored Jan 6, 2022
2 parents 219d3f2 + cbdf73b commit 60c0fdf
Show file tree
Hide file tree
Showing 7 changed files with 446 additions and 194 deletions.
24 changes: 15 additions & 9 deletions src/component/tooltip/TooltipView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { bind, each, clone, trim, isString, isFunction, isArray, isObject } from 'zrender/src/core/util';
import { bind, each, clone, trim, isString, isFunction, isArray, isObject, extend } from 'zrender/src/core/util';
import env from 'zrender/src/core/env';
import TooltipHTMLContent from './TooltipHTMLContent';
import TooltipRichContent from './TooltipRichContent';
Expand Down Expand Up @@ -585,11 +585,16 @@ class TooltipView extends ComponentView {
const seriesTooltipResult = normalizeTooltipFormatResult(
series.formatTooltip(dataIndex, true, null)
);
if (seriesTooltipResult.markupFragment) {
axisSectionMarkup.blocks.push(seriesTooltipResult.markupFragment);
const frag = seriesTooltipResult.frag;
if (frag) {
const valueFormatter = buildTooltipModel(
[series as Model<TooltipableOption>],
globalTooltipModel
).get('valueFormatter');
axisSectionMarkup.blocks.push(valueFormatter ? extend({ valueFormatter }, frag) : frag);
}
if (seriesTooltipResult.markupText) {
markupTextArrLegacy.push(seriesTooltipResult.markupText);
if (seriesTooltipResult.text) {
markupTextArrLegacy.push(seriesTooltipResult.text);
}
cbParamsList.push(cbParams);
});
Expand Down Expand Up @@ -682,16 +687,17 @@ class TooltipView extends ComponentView {
dataModel.formatTooltip(dataIndex, false, dataType)
);
const orderMode = tooltipModel.get('order');
const markupText = seriesTooltipResult.markupFragment
? buildTooltipMarkup(
seriesTooltipResult.markupFragment,
const valueFormatter = tooltipModel.get('valueFormatter');
const frag = seriesTooltipResult.frag;
const markupText = frag ? buildTooltipMarkup(
valueFormatter ? extend({ valueFormatter }, frag) : frag,
markupStyleCreator,
renderMode,
orderMode,
ecModel.get('useUTC'),
tooltipModel.get('textStyle')
)
: seriesTooltipResult.markupText;
: seriesTooltipResult.text;

const asyncTicket = 'item_' + dataModel.name + '_' + dataIndex;

Expand Down
Loading

0 comments on commit 60c0fdf

Please sign in to comment.