ChartsOrg / ChartsOrg/Charts

Proposed change on bubble size calculation.

Open
#1,081 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Hi guys!

I just want to propose a small change in the calculation of the bubble size, I saw that the algorithm that is in charge of this the following one:

``` swift
private func getShapeSize(
entrySize entrySize: CGFloat,
maxSize: CGFloat,
reference: CGFloat,
normalizeSize: Bool) -> CGFloat
{
let factor: CGFloat = normalizeSize ? ((maxSize == 0.0) ? 1.0 : sqrt(entrySize / maxSize)) : entrySize

let shapeSize: CGFloat = reference * factor

return shapeSize
}
```

If I use a set with a sizes [ 1, 2 , 3 , 4 , 5 , 6 ] and I print the sizes, I'll see the following:

```
20.8240648827442
29.4496749809142
36.0683383970238
41.6481297654884
46.5640246456822
51.0083333333333
```

The problem here is that the size for the bubble two is not the double of the first bubble and so. This represent a problem for my dataset when there are a lot of bubble entries. The difference between the sizes is not the correct one. I know that you use a sqrt function to normalize the sizes but on my special case this doesn't work.

``` swift
private func getShapeSize(
entrySize entrySize: CGFloat,
maxSize: CGFloat,
reference: CGFloat,
normalizeSize: Bool) -> CGFloat
{
let factor: CGFloat = normalizeSize ? ((maxSize == 0.0) ? 1.0 : (entrySize / maxSize)) : entrySize

let shapeSize: CGFloat = reference * factor

return shapeSize
}
```

If we erase the sqrt function and we print the sizes, we got the following:

```
8.50138888888889
17.0027777777778
25.5041666666667
34.0055555555555
42.5069444444444
51.0083333333333
```

In this case we got the correct proportion in every size 😎. This works perfect for me, and I guess this could be helpful for anyone who need specific growing on the bubbles sizes. So why not get both?

I have the following implementations with enums to specify the type of normalize that the developer wants. I'll add a pull reques to you can check it.

Contributor guide

Open the contributing guide

Research direction

Start by locating the getShapeSize function in the Swift charting code and review how its normalizeSize branch is used for bubble entries. Compare the current square-root normalization with the proposed proportional mode and inspect the existing bubble-chart tests or examples, if present. Done means developers can choose the normalization behavior and the reported size proportions are verified.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.