Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(line): endLabel animation #13246

Merged
merged 21 commits into from
Sep 29, 2020
Merged

feat(line): endLabel animation #13246

merged 21 commits into from
Sep 29, 2020

Conversation

Ovilia
Copy link
Contributor

@Ovilia Ovilia commented Sep 8, 2020

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Support line endLabel animation so as to show the data changes over time.

Note the difference between connectNulls being true and false.

Situation A: connectNulls: false

endLabel is displayed on the last non-NaN data (that is '-' for data in option) when connectNulls is false.

The left column shows charts with xAxis as category and yAxis as value axis, with xAxis.inverse and yAxis.inverse being either true or false.

1 (1)

Situation B: connectNulls: true

endLabel is displayed on the interpolated internal data when connectNulls is false.

2 (1)

Line Series ClipPath Fixing

This PR also fixes the clipPath used for initial animation.

Usage

Are there any API changes?

  • The API has been changed.

A new option series(line).endLabel is supported, which is almost the same as series.label only that it has the following default values:

endLabel: {
    show: false,
    valueAnimation: false,
    distance: 8
},
  • show is for enabling endLabel
  • valueAnimation is for value interpolation
  • distance is the distance between label text to the symbol item

Related test cases or examples to use the new APIs

Added a new test case test/line-endLabel.html and updated test/line-animation.html.

Others

Merging options

  • Please squash the commits into a single one when merge.

TODOs

  • Interpolating other dimensions of data.

Limitations

These things should be fixed in future PRs.

  • State bugs
    • When hovering the line near the end of animation, the normal text after animation is not correct
    • State change from emphasis to normal during the animation
    • Data items outside of the clipPath can be hovered
  • endLabel does not support polar system for this PR because I didn't find enough use case for this.
  • Interpolate when smooth is true.

…allbacks

BREAKING CHANGE: May not be compatible with 4.x.
Since default symbol animation with line charts has been changed in 5.0 to be
displayed when the clipPath of the line goes through the data point,
animationDelay callback now has two meanings:
animationDelay: function (i) { return ... }
(1) If `i` is `null`, the callback should return the delay of the overall
    series animation, that is, the delay before the line clipPath starts
    changing.
(2) If `i` is a `number`, the callback should return the delay of the certain
    delay of each data item.
In ECharts 4.x, however, since the label animation shows along with the line
animation, only the `number` form is used.
@pull-request-size pull-request-size bot added size/XL and removed size/L labels Sep 8, 2020
@echarts-bot echarts-bot bot added the PR: awaiting doc Document changes is required for this PR. label Sep 9, 2020
@Ovilia Ovilia marked this pull request as ready for review September 24, 2020 08:04
@Ovilia Ovilia changed the title WIP(line): endLabel animation feat(line): endLabel animation Sep 24, 2020
@pissang pissang merged commit b25e051 into next Sep 29, 2020
@echarts-bot
Copy link

echarts-bot bot commented Sep 29, 2020

Congratulations! Your PR has been merged. Thanks for your contribution! 👍

@pissang pissang deleted the line-label branch September 29, 2020 03:39
@realeve
Copy link

realeve commented Oct 18, 2020

@pissang @Ovilia
1.尾部跟随能否将图例的信息显示在线/区域图的最后面,目前显示的是最后一项的值。
image

2.将图例和曲线一并显示,可读性更高一些,比如阿里在g2-plot中是这样处理的:
image

在面积图又是这样的效果(https://g2plot-v1.antv.vision/zh/examples/area/stacked#area-label ):
image


3.目前5.0的尾部跟随效果在开/关 legend时对应的数据序列不会关闭。例如下图在关闭series0时,对应数据未隐藏,同时series1的曲线图及辅助点错位,tooltip也不正。另外 endLabel的formatter不支持富文本。

image

代码如下

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <script src="lib/esl.js"></script>
        <script src="lib/config.js"></script>
        <script src="lib/facePrint.js"></script>
    </head>
    <body>
        <style>
            html,
            body {
                width: 100%;
                height:100vh;
            }
            #main0 {
                width: 100%;
                height: 600px;
            }
        </style>
        <div id="main0"></div>
        <script>
            require(["echarts"], function (echarts) {
                var chart = echarts.init(document.getElementById("main0"));
                var config = {
                    type: "line",
                    endLabel: {
                        show: true,
                        valueAnimation: true,
                        formatter: (param) =>
                            `${param.seriesName}: ${param.value}`,
                    },
                    emphasis: {
                        endLabel: {
                            color: "red",
                        },
                    },
                };
                var option = {
                    xAxis: {
                        data: [
                            "0",
                            "1",
                            "2",
                            "3",
                            "4",
                            "5",
                            "6",
                            "7",
                            "8",
                            "9",
                            "10",
                            "11",
                        ],
                    },
                    yAxis: {},
                    tooltip:{
                        trigger:'axis'
                    },
                    legend:{},
                    series: [
                        {
                            name: "series0",
                            data: [
                                645,
                                -271,
                                -550,
                                -1580,
                                -2295,
                                "-",
                                -1195,
                                -2295,
                                -1799,
                                -1188,
                                -354,
                                459,
                            ],
                            ...config,
                        },
                        {
                            name: "series11",
                            data: [
                                472,
                                828,
                                1679,
                                "-",
                                2818,
                                2220,
                                2220,
                                2220,
                                1570,
                                1109,
                                '-',
                            ],
                            ...config,
                        },
                    ],
                };

                chart.setOption(option);
            });
        </script>
    </body>
</html>

@Ovilia Ovilia removed the PR: awaiting doc Document changes is required for this PR. label Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants