ivnsch / SwiftCharts

Easy to use and highly customizable charts library for iOS
Apache License 2.0
2.53k stars 410 forks source link

why chatLinelayer is always draw in front of chatPointHighlightLayer ? #398

Open woshahua opened 5 years ago

woshahua commented 5 years ago

in the example of multi-touch chart-tracking, the chatlinelayer is always draw in front of the chartPointHighlightlayer, even though I change the position in [layer].

I read the wiki, but dont understand in which order the layers are draw. can you please answer this.

heumn commented 4 years ago

Following

chulkov commented 4 years ago

I fixed it by doing this:

creating Chart() as usual, except not adding LineLayer

 let chart = Chart(frame: chartFrame,
                          innerFrame: innerFrame,
                          settings: ChartSettings(),
                          layers: [
                            xAxisLayer,
                            yAxisLayer,
                            guidelinesLayer,
                            showCoordsLinesLayer,
                            //chartPointsLineLayer,
                            chartPointsCircleLayer,
                            touchLayer])

then create LineLayer and add as subview before adding chart

        let lineView = Chart(frame: chartFrame,
        innerFrame: innerFrame,
        settings: ChartSettings(),
        layers: [chartPointsLineLayer])

        self.chartView.addSubview(lineView.view)

        self.chartView.addSubview(chart.view)
        self.patientChart = chart

Thats it, now line is behind points. Actually this solutions makes bug, when lineView duplicates on screen rotation. I solved this by doing this before "addSubview":

self.chartView.subviews.forEach({ $0.removeFromSuperview() })