apache / apache/echarts

MagicType 'stack' does not recognize bars being stacked upon chart initialization, fails to change to tiled on first click.

Open
#15,571 1 comment 0 reactions 0 assignees View on GitHub
bug en
Dominant language
TypeScript
Stars
67.3k
Forks
19.8k
Avg merge
11d 14h
Merged PRs (30d)
8

Description

### Version
5.1.2

### Steps to reproduce
Create a simple bar chart with 2 series entries. In each, set type to 'bar' and stack to a simple string, such as 'cars'. Ensure that a toolbox with a magictype of type 'stack' exists.

Click on the stack icon in the toolbox. Click on the stack icon a 2nd time.

### What is expected?
On first click of the stack icon in the toolbox, the chart should immediately switch to tiled display, and subsequent clicks should toggle back and forth.

Also, if your chart has 2 bars that are stacked together, and another 2 bars that are stacked together in a different group, the bars should all separate, and then return to their 2 individual stack groups.

### What is actually happening?
On first click of the stack icon in the toolbox, nothing happens. On second click, the chart switches to tiled display, and all following clicks will toggle correctly.

Also, if you have 2 sets of separately stacked bars, this bug causes the bars to all merge and become 1 single stacked bar, which breaks the layout.

---
This appears to be caused by a bug in MagicType.ts file in the "seriesOptGenreator" (spelling) method. In that method, a variable called isStack is set by comparing the seriesModel 'stack' property specifically to INNER_STACK_KEYWORD, which is a predefined constant value of "__ec_magicType_stack__". However, if you have defined your own stack common name (such as "cars"), this means a match will fail and isStack will be set to false. This is incorrect.

The code then proceeds to generate 2 new series replacements, and sets the 'stack' property to INNER_STACK_KEYWORD, overwriting the name you gave it. This causes the 2nd click of the toolbox icon to actually work correctly, because isStack will now be recognized.

This should be corrected so that isStack is defined to look at whether or not the 'stack' property is "truthy", such as:

var isStack = !!seriesModel.get('stack');

Then, lower, the line where the stack property is redefined would need to be modified. We would have to store the original 'stack' property in the model options, and not simply toggle it between '' and INNER_STACK_KEYWORD, but between '' and the stored value. This would ensure the model toggles correctly and still preserves the original stack name, which also solves the second part of this bug.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.