未验证 提交 fdda0254 编写于 作者: T Tommy 提交者: GitHub

fix(sankey): provide missing label value in formatter #18212

上级 b84493a7
......@@ -275,6 +275,7 @@ class SankeyView extends ChartView {
{
labelFetcher: seriesModel,
labelDataIndex: node.dataIndex,
labelValue: layout.value,
defaultText: node.id
}
);
......
......@@ -94,6 +94,7 @@ interface SetLabelStyleOpt<TLabelDataIndex> extends TextCommonParams {
};
labelDataIndex?: TLabelDataIndex;
labelDimIndex?: number;
labelValue?: number;
/**
* Inject a setter of text for the text animation case.
......@@ -135,6 +136,7 @@ function getLabelText<TLabelDataIndex>(
const labelFetcher = opt.labelFetcher;
const labelDataIndex = opt.labelDataIndex;
const labelDimIndex = opt.labelDimIndex;
const labelValue = opt.labelValue;
const normalModel = stateModels.normal;
let baseText;
if (labelFetcher) {
......@@ -143,9 +145,7 @@ function getLabelText<TLabelDataIndex>(
null,
labelDimIndex,
normalModel && normalModel.get('formatter'),
interpolatedValue != null ? {
interpolatedValue: interpolatedValue
} : null
{interpolatedValue: retrieve2(interpolatedValue, labelValue)}
);
}
if (baseText == null) {
......
<!DOCTYPE html>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="lib/simpleRequire.js"></script>
<script src="lib/config.js"></script>
</head>
<body>
<style>
html, body, #main {
margin: 0;
width: 100%;
height: 100vh;
}
</style>
<div id="main"></div>
<script>
require(['echarts'], function (echarts) {
var chart = echarts.init(document.querySelector("#main"), 'dark');
window.onresize = chart.resize;
const sankeyData = [
{source: 'EasyGrid Energy', target: 'Chip Industry', value: 860},
{source: 'EasyGrid Energy', target: 'Industrial Internet', value: 1600},
{source: 'EG Green Energy', target: 'Chip Industry', value: 2600},
{source: 'EG Green Energy', target: 'IOT', value: 500},
{source: 'Industrial Internet', target: 'IOT', value: 800},
{source: 'Industrial Internet', target: 'Intelligent Manufacturing', value: 600},
{source: 'Chip Industry', target: 'Chip Manufacturing', value: 1600},
{source: 'Chip Industry', target: 'Chip Package', value: 1200},
{source: 'Chip Industry', target: 'Chip Design', value: 600},
{source: 'Chip Manufacturing', target: '5mm', value: 600},
{source: 'Chip Manufacturing', target: '10mm', value: 500},
{source: 'Chip Manufacturing', target: '15mm', value: 500}
];
var option = {
title: {text: 'The values of Label and Tooltip are the same',padding: 20},
series: [{
type: 'sankey',
layout: 'none',
lineStyle: {color: 'gradient', curveness: 0.5},
emphasis: {focus: 'adjacency'},
data: getNames(),
links: sankeyData
}],
tooltip: {trigger: 'item', triggerOn: 'mousemove'},
label: {
formatter: (params) => {
return params.name + ' ' + params.value + 'kW·h';
}
}
};
chart.setOption(option);
function getNames() {
return sankeyData.reduce((names, item) => {
if (-1 == names.indexOf(item.source)) {
names.push(item.source);
}
if (-1 == names.indexOf(item.target)) {
names.push(item.target);
}
return names;
}, []).map(item => {return {name:item}});
}
});
</script>
</body>
</html>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册