question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using ECHarts Tree Shaking API's not reducing the overall package size of an Angular application

See original GitHub issue

Version

5.0.1

Steps to reproduce

We compared using full echarts against echarts tree shakable API’s.

Option 1: Full ECharts imported

var echarts = require('echarts');
var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);
var option;

option ={
    title: {
        text: '饼图程序调用高亮示例',
        left: 'center'
    },
    tooltip: {
        trigger: 'item',
        formatter: '{a} <br/>{b} : {c} ({d}%)'
    },
    legend: {
        orient: 'vertical',
        left: 'left',
        data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
    },
    series: [
        {
            name: '访问来源',
            type: 'pie',
            radius: '55%',
            center: ['50%', '60%'],
            data: [
                {value: 335, name: '直接访问'},
                {value: 310, name: '邮件营销'},
                {value: 234, name: '联盟广告'},
                {value: 135, name: '视频广告'},
                {value: 1548, name: '搜索引擎'}
            ],
            emphasis: {
                itemStyle: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }]
};

option && myChart.setOption(option);

Our observation is this: image

Total Main.js Size: 1.2 MB

Option 2: Using tree shakable API’s from ECharts

import * as echarts from 'echarts/core';

import {
  PieChart
} from 'echarts/charts';

import {
  TitleComponent,
  TooltipComponent,
  GridComponent
} from 'echarts/components';

import {
  SVGRenderer
} from 'echarts/renderers';

echarts.use(
  [TitleComponent, TooltipComponent, GridComponent, PieChart, SVGRenderer]
);

Observation image

Total Main.js Size: 1.3 MB

What is expected?

We should get a reduced overall package size when tree shakable API is introduced.

What is actually happening?

So as you could see total size of main.js increased with tree shakable API usage. What could be the reason for the increase in package size after using tree shakable API?

Please let us know in case the approach we followed is not correct.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
echarts-bot[bot]commented, Jun 11, 2021

@msbasanth It seems you are not using English, I’ve helped translate the content automatically. To make your issue understood by more people, we’d like to suggest using English next time. 🤗

TRANSLATED

BODY

Version

5.0.1

Steps to reproduce

We compared using full echarts against echarts tree shakable API’s.

Option 1: Full ECharts imported

var echarts = require('echarts');
var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);
var option;

option ={
    title: {
        text:'Pie chart program call highlight example',
        left:'center'
    },
    tooltip: {
        trigger:'item',
        formatter:'{a} <br/>{b}: {c} ({d}%)'
    },
    legend: {
        orient:'vertical',
        left:'left',
        data: ['Direct Access','Email Marketing','Affiliate Advertising','Video Advertising','Search Engine']
    },
    series: [
        {
            name:'Access source',
            type:'pie',
            radius: '55%',
            center: ['50%', '60%'],
            data: [
                {value: 335, name:'Direct access'},
                {value: 310, name:'Email marketing'},
                {value: 234, name:'Affiliate Ads'},
                {value: 135, name:'Video ad'},
                {value: 1548, name:'search engine'}
            ],
            emphasis: {
                itemStyle: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor:'rgba(0, 0, 0, 0.5)'
                }
            }
        }]
};

option && myChart.setOption(option);

Our observation is this: image

Total Main.js Size: 1.2 MB

Option 2: Using tree shakable API’s from ECharts

import * as echarts from'echarts/core';

import {
  PieChart
} from'echarts/charts';

import {
  TitleComponent,
  TooltipComponent,
  GridComponent
} from'echarts/components';

import {
  SVGRenderer
} from'echarts/renderers';

echarts.use(
  [TitleComponent, TooltipComponent, GridComponent, PieChart, SVGRenderer]
);

Observation image

Total Main.js Size: 1.3 MB

What is expected?

We should get a reduced overall package size when tree shakable API is introduced.

What is actually happening?

So as you could see total size of main.js increased with tree shakable API usage. What could be the reason for the increase in package size after using tree shakable API?

Please let us know in case the approach we followed is not correct.

0reactions
msbasanthcommented, Jun 21, 2021

@pissang Thanks for the solution given. As suggested registered theme by passing the json theme data echarts.registerTheme('dark',theme) . Observation I could see reduction, now main.js size of the angular application is 687KB. Base Angular main.js size is 140KB, that means approx. 540KB added by echarts. So it looks like tree shaking is working as documented. Hope this is the reduction I can expect.

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using ECHarts Tree Shaking API's not reducing the overall ...
[GitHub] [echarts] msbasanth commented on issue #15138: Using ECHarts Tree Shaking API's not reducing the overall package size of an Angular ...
Read more >
How to decrease prod bundle size? - angular - Stack Overflow
Firstly, vendor bundles are huge simply because Angular 2 relies on a lot of libraries. Minimum size for Angular 2 app is around...
Read more >
Changelog - Apache ECharts
#16772 (jiawulin001); [Fix] [tree] fix radial tree with a single root not working. ... which enabled tree shaking of bundle and reduced size....
Read more >
Reduce JavaScript payloads with tree shaking - web.dev
Knowing where to begin optimizing your application's JavaScript can be daunting. If you're taking advantage of modern tooling such as webpack, however, tree...
Read more >
Honey, I shrunk the bundle — A story about Angular ... - Medium
One main problem we were facing was the bundle size and the overall performance of the application in the browser. It felt non-responsive...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found