jordibruin / Swift-Charts-Examples

An overview of the different types of charts you can make with Swift Charts
MIT License
2.04k stars 129 forks source link

MarkDimension not working as expected. Someone an idea? Is this a bug? #53

Closed dasdom closed 2 years ago

dasdom commented 2 years ago

I tried to add the bottom right chart to the repo but there seems to be bugs in the beta 1.

Reading the documentation of MarkDimension, I assume that using .inset(0) should fill the step size. If I understand it correctly this should result in rectangles next to each other filling the whole space, as desired.

Screenshot 2022-06-16 at 22 40 48

But when I create a chart like this:

Chart(data) { rectData in
  RectangleMark(x: .value("x", rectData.a),
                y: .value("y", rectData.b),
                width: .inset(0),
                height: .inset(0))
  .foregroundStyle(by: .value("Value", rectData.value))
}

the result is an empty chart:

Screenshot 2022-06-16 at 22 46 12

I get it to work with the following code (works but uses hard-coded values for the step size):

Chart(data) { rectData in
  RectangleMark(xStart: .value("minA", rectData.a),
                xEnd: .value("maxA", rectData.a + 1),
                yStart: .value("minB", rectData.b),
                yEnd: .value("minB", rectData.b + 1.0))
    .foregroundStyle(by: .value("Value", rectData.value))
}

The result:

Screenshot 2022-06-16 at 22 48 29

Do I misunderstand .inset(_:)?

By the way, .ratio(1) doesn't work as well.

atrinh0 commented 2 years ago

Does HeatMap cover this chart type?

dasdom commented 2 years ago

Oh, haven't seen this. HeatMap uses the same solution I used in my working example. It's ok but not ideal in my opinion because of the hard coded step size.

I'll close this issue. Thanks.

atrinh0 commented 2 years ago

Keep in mind the HeatMap code is one potential way to represent the chart. No idea if that is the way the chart was intended to be used. Happy to see any other solutions anyone can work out and would always welcome the addition for everyone to learn from.