ivnsch / SwiftCharts

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

ChartPointsViewsLayer and zoom #313

Closed MasterWatcher closed 6 years ago

MasterWatcher commented 6 years ago

Hello, thanks for such a great library! In my project I need to show year label above every bar. Also it should be scrollable, so I use maxZoom properties

 chartSettings.zoomPan.maxZoomX = 2
 chartSettings.zoomPan.minZoomX = 2
 chartSettings.zoomPan.minZoomY = 1
 chartSettings.zoomPan.maxZoomY = 1

then I create ChartPointsViewsLayer and add it to my chart

  let labelsLayer = ChartPointsViewsLayer(xAxis: xAxisLayer.axis, yAxis: yAxisLayer.axis, chartPoints: labelChartPoints, viewGenerator: { (chartPointModel, layer, chart) -> UIView? in
        let label = HandlingLabel()
        label.text =  chartPointModel.chartPoint.x.description
        label.font = UIFont.systemFont(ofSize: 12)
        label.sizeToFit()
        label.center = CGPoint(x: chartPointModel.screenLoc.x, y: chartPointModel.screenLoc.y - 10)
        return label
    })

but the labels are zooming too

screenshot

How can I make labels not stretched?

ivnsch commented 6 years ago

Please take a look at https://github.com/i-schuetz/SwiftCharts/wiki/View-hierarchy-and-transforms#chartpointsviewslayer-transform-modes. It's explained there (hint: you have to use .translate mode for the labels).

preethacmu commented 6 years ago

could you please comment how did add ChartPointsViewsLayer to chart MasterWatcher