vicanso / charts-rs

A charts library for rust
https://charts.npmtrend.com/
Mozilla Public License 2.0
190 stars 8 forks source link

Piechart overlaps items overlap #19

Closed Ava-Fleming closed 1 month ago

Ava-Fleming commented 3 months ago

When part of the dataset is substantially larger than the remaining set there is overlapping text. This seems to be a problem when the smaller sets are almost the same.

image

Sample code:

let mut pie_chart = PieChart::new( vec![]);

pie_chart.series_list.push((
    "item 1",
    vec![29 as f32],
).into());

pie_chart.series_list.push((
  "item 2",
  vec![2 as f32],
).into());

pie_chart.series_list.push((
    "item 3",
    vec![2 as f32],
).into());
Ava-Fleming commented 3 months ago

It looks like the label offset on is_left plays into this. the end.y is adjusted it generally seems to fix it.

I'm taking the index and doing some crude math to see what changes I can make it do here.

            let is_left = angle > 180.0;
            if is_left {
                end.x -= label_offset; 
                end.y -= 10.0-(label_offset/(index as f32)); 
            } else {
                end.x += label_offset;
            }
vicanso commented 1 month ago

@Ava-Fleming Please try the latest version.

Ava-Fleming commented 1 month ago

Tested this today, it looks like it resolves the problem. Thank you!