SwiftUICharts icon indicating copy to clipboard operation
SwiftUICharts copied to clipboard

Q: space for infoBox

Open mvolkmann opened this issue 2 years ago • 5 comments

How does a LineChart know how much space to leave between the metadata title and the top of the chart for displaying and infoBox when the user taps on the chart?

mvolkmann avatar Mar 18 '22 21:03 mvolkmann

When I display an infoBox, it throws off the alignment of the axes. The x-axis no longer starts at the bottom of the y-axis and instead is moved part way up on the y-axis.

mvolkmann avatar Mar 18 '22 21:03 mvolkmann

In my LineChartStyle I have the following:

                infoBoxPlacement: .infoBox(isStatic: false),
                infoBoxContentAlignment: .vertical,
                infoBoxBorderColour: Color.primary,
                infoBoxBorderStyle: StrokeStyle(lineWidth: 1),

mvolkmann avatar Mar 18 '22 21:03 mvolkmann

The space is set by the view modifier .infoBox(chartData: data, height: 140), the default set to 70.

I'm not sure what exactly the issue you're facing is, could you post a screenshot please?

It might be the order of the view modifiers as each one wraps a stack layer around those that come before. .infoBox should probably be near the end of the chain.

I just noticed a placement issue with with the box, I'll add I PR for it but I don't think its the issue that you are facing.

willdale avatar Mar 19 '22 15:03 willdale

Here is a screen shot that shows the issue. The value for "Mark" is 10, but notice that the y-axis has shifted down so that the "10.00" y-axis label isn't lined up properly. I believe this happens due to the infoBox height IMG_5884 .

mvolkmann avatar Mar 21 '22 15:03 mvolkmann

Here is my code that creates the chart:

        LineChart(chartData: chartData)
            .pointMarkers(chartData: chartData)
            .touchOverlay(chartData: chartData, formatter: numberFormatter)
            .xAxisLabels(chartData: chartData)
            .yAxisLabels(
                chartData: chartData,
                formatter: numberFormatter,
                colourIndicator: .style(size: 12)
            )
            .headerBox(chartData: chartData)
            .legends(
                chartData: chartData,
                columns: [GridItem(.flexible()), GridItem(.flexible())]
            )
            .infoBox(chartData: chartData)
            .id(UUID())
            .frame(
                minWidth: 300,
                maxWidth: Double.infinity,
                minHeight: 300,
                idealHeight: 450,
                maxHeight: 600,
                alignment: .center
            )
            .padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 50))

mvolkmann avatar Mar 21 '22 15:03 mvolkmann