ivnsch / SwiftCharts

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

X Node Last point Not Visible some times. #353

Open smartKrunal opened 6 years ago

smartKrunal commented 6 years ago

i have make one simple demo in which by clicking button increase X Nodes & draw graph. initially it draw 2 points. and last point not visible after draw 3 points. then draw 5 points & last point not visible. again at 8 point this issue occurs. This type of problem occurs in Iphone SE (Small Device). so please check in SE & please guide me @i-schuetz .

simulator screen shot - iphone se - 2018-06-04 at 22 58 20 simulator screen shot - iphone se - 2018-06-04 at 22 58 22 simulator screen shot - iphone se - 2018-06-04 at 22 58 26 simulator screen shot - iphone se - 2018-06-04 at 22 58 31

i am attaching demo project. also code is written here.

` @IBOutlet weak var viewGraphContainer: UIView! fileprivate var chart: Chart? // arc var chartDataCounter = 2

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
}

override func viewDidAppear(_ animated: Bool) {
    reloadChartMonths()
}

@IBAction func buttonClicked(_ sender: UIButton) {
    chartDataCounter += 1
    reloadChartMonths()
}

func reloadChartMonths() {
    // Data Load
    var arrayXY = [(x:Int,y:Int)]()

    //Chart load
    let labelSettings = ChartLabelSettings(font: ExamplesDefaults.labelFont)

    var chartPoints = [ChartPoint]()

    for i in 1..<chartDataCounter+1{
        let y = i % 2 == 0 ? i * 10 : i / 2
        arrayXY.append((x: i, y: y))
    }

    for i in 0..<arrayXY.count{
        let xAxisValue = ChartAxisValueDoubleScreenLoc(screenLocDouble: Double(i), actualDouble: Double(arrayXY[i].x))
        let yAxisValue = ChartAxisValueDouble(Double(arrayXY[i].y))
        chartPoints.append(ChartPoint(x: xAxisValue, y: yAxisValue))
    }

    let labelSettingsX = ChartLabelSettings(font: ExamplesDefaults.labelFont)

    let xValues = ChartAxisValuesStaticGenerator.generateXAxisValuesWithChartPoints(chartPoints, minSegmentCount: Double(arrayXY.count-1), maxSegmentCount: Double(arrayXY.count-1), multiple: 1, axisValueGenerator: {ChartAxisValueDouble($0, labelSettings: labelSettingsX)}, addPaddingSegmentIfEdge: false)
    let yValues = ChartAxisValuesStaticGenerator.generateYAxisValuesWithChartPoints(chartPoints, minSegmentCount: 4, maxSegmentCount: 4, multiple: 10, axisValueGenerator: {ChartAxisValueDouble($0, labelSettings: labelSettings)}, addPaddingSegmentIfEdge: false)

    // Axis titles
    let xModel = ChartAxisModel(axisValues: xValues, lineColor:UIColor.black, axisTitleLabel: ChartAxisLabel(text: "", settings: labelSettings))

    let yModel = ChartAxisModel(axisValues: yValues, lineColor:UIColor.black, axisTitleLabel: ChartAxisLabel(text: "", settings: labelSettings.defaultVertical()))

    viewGraphContainer.layoutIfNeeded()
    let chartFrame = viewGraphContainer.bounds//ExamplesDefaults.chartFrame(viewGraphContainer.bounds)
    let chartSettings = ExamplesDefaults.smartChartSettings
    let coordsSpace = ChartCoordsSpaceLeftBottomSingleAxis(chartSettings: chartSettings, chartFrame: chartFrame, xModel: xModel, yModel: yModel)
    let (xAxisLayer, yAxisLayer, innerFrame) = (coordsSpace.xAxisLayer, coordsSpace.yAxisLayer, coordsSpace.chartInnerFrame)
    let lineModel = ChartLineModel(chartPoints: chartPoints, lineColor: UIColor.black, lineWidth: 1.5, animDuration: 1, animDelay: 0)
    let chartPointsLineLayer = ChartPointsLineLayer(xAxis: xAxisLayer.axis, yAxis: yAxisLayer.axis, lineModels: [lineModel])

    let chart = Chart(
        frame: chartFrame,
        innerFrame: innerFrame,
        settings: chartSettings,
        layers: [
            xAxisLayer,
            yAxisLayer,
            chartPointsLineLayer
        ]
    )

    viewGraphContainer.subviews.forEach { (subview) in
        subview.removeFromSuperview()
    }
    viewGraphContainer.addSubview(chart.view)
    self.chart = chart
}

` ChartDemoLineSmartOffice2.zip