antvis / antvis/F2

cloud chart render error

Open
#895 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
8k
Forks
637
PR merge metrics
No merged PRs in 30d

Description

- [x] I have searched the [issues](https://github.com/antvis/f2/issues) of this repository and believe that this is not a duplicate.

### Reproduction link
[![Edit on CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/f2-tag-cloud-error-8506w?fontsize=14&hidenavigation=1&theme=dark)

### Steps to reproduce
Refresh the page repeatedly

### What is expected?
Chart rendering Correctly
![image](https://user-images.githubusercontent.com/16454398/83120978-55399680-a104-11ea-8bff-c669a6f93e7c.png)

### What is actually happening?
Probability js error: Cannot read property '0' of undefined
![image](https://user-images.githubusercontent.com/16454398/83120942-4652e400-a104-11ea-904c-b07e04fdc9dc.png)

| Environment | Info |
|---|---|
| f2 | 3.6.3 |
| System | macOS 10.15.5 |
| Browser | Google Chrome 83.0.4103.61 |

---
```js
_proto.scale = function scale(value) {
if (isNil(value)) {
return NaN;
}

var max = this.max;
var min = this.min;

if (max === min) {
return 0;
}

var percent = (value - min) / (max - min);
var rangeMin = this.rangeMin();
var rangeMax = this.rangeMax();
return rangeMin percent * (rangeMax - rangeMin);
}
```
```js
// Get the interpolation between colors
function getValue(start, end, percent, index) {
var value = start[index] (end[index] - start[index]) * percent;
return value;
} // convert to hex
```
![image](https://user-images.githubusercontent.com/16454398/83138417-53300180-a11d-11ea-8488-854fbfaa9151.png)
![image](https://user-images.githubusercontent.com/16454398/83138459-6511a480-a11d-11ea-9648-6fc069f28683.png)
![image](https://user-images.githubusercontent.com/16454398/83138487-72c72a00-a11d-11ea-9ce4-795fbee10c1a.png)

'percent' should not be negative.

It's normal '@antv/f2@3.3.7'.

Contributor guide

Open the contributing guide

Research direction

Start with the linked CodeSandbox reproduction and refresh the page repeatedly to observe the intermittent rendering failure. Read the shown _proto.scale and getValue snippets, then trace why the color interpolation receives an undefined value or a negative percent; done means the chart renders correctly without the reported JavaScript error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.