Skip to content

ikost/SwiftUIGraphPlotLibrary

 
 

Repository files navigation

SwiftUIGraphPlotLibrary

Graph plot library with SwiftUI

platform

It supports only on ios v13

useage

Add Package repository

To add a package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency

import the package

import SwiftUIGraphPlotLibrary
-- Lineplot --
struct LinePlot: View {
var body: some View {
    let plotset:[PlotData] = [PlotData(x: 0.0,y: 0.0),PlotData(x: 1.0,y: 2.0),PlotData(x: 2.0,y: 5.0),
                              PlotData(x: 3.0,y: 3.0),PlotData(x: 4.0,y: 8.0),PlotData(x: 5.0,y: 10.0),
                              PlotData(x: 6.0,y: 25.0),PlotData(x: 7.0,y: 21.0),PlotData(x: 8.0,y: 23.0),
                              PlotData(x: 9.0,y: 22.0),PlotData(x: 9.6,y: 21.0),PlotData(x: 10,y: 30.0)]

    let plotView = GraphPlot(type: .linePlot, color: .orange)
    let frameSize = CGSize(width: 300, height: 200)
        
    return GraphView(dataSet: plotset, plotType: plotView, frameSize: frameSize, xTicks: true, yTicks: true)
             .frame(width: 350, height: 250, alignment: .center)
    }
}

alt tag

-- Vertical Bar plot --

struct BarPlot:View {
    var body:some View{
        let plotset:[PlotData] = [PlotData(x: 0.0,y: 0.0),PlotData(x: 1.0,y: 2.0),PlotData(x: 2.0,y: 5.0),
                                  PlotData(x: 3.0,y: 3.0),PlotData(x: 4.0,y: 8.0),PlotData(x: 5.0,y: 10.0),
                                  PlotData(x: 6.0,y: 25.0),PlotData(x: 7.0,y: 21.0),PlotData(x: 8.0,y: 23.0),
                                  PlotData(x: 9.0,y: 22.0),PlotData(x: 9.6,y: 21.0),PlotData(x: 10,y: 30.0)]
            
        let plotView = GraphPlot(type: .verticalBar, color: .blue)
            let frameSize = CGSize(width: 300, height: 200)
            
        return GraphView(dataSet: plotset, plotType: plotView, frameSize: frameSize, xTicks: true, yTicks: true)
               .frame(width: 350, height: 250, alignment: .center)
        }
}

alt tag

-- Bubble plot --

import SwiftUI
import SwiftUIGraphPlotLibrary

struct exampleBuble: View {
var body: some View {

  let plotset:[PlotData] = [PlotData(x: 1.0,y: 2.0),PlotData(x: 2.0,y: 3.0),PlotData(x: 3.0,y: 2.0),
                            PlotData(x: 4.0,y: 8.0),PlotData(x: 5.0,y: 30.0),PlotData(x: 6.0,y: 25.0),
                            PlotData(x: 7.0,y: 24.0),PlotData(x: 8.0,y: 23.0),PlotData(x: 9.0,y: 22.0),
                            PlotData(x: 9.6,y: 21.0)]

  let bublePlot = GraphPlot(type: .circlePlot, color: .blue)
      .setCircleRadiusFunc{ index in 
                            plotset[index].getY() * 1.4}
      .setHueDegreeFunc{ index in
                            return Double(plotset[index].getY() * 90 / 23)}
  let frameSize = CGSize(width: 300, height: 200)

  return GraphView(dataSet: plotset, plotType: bublePlot, frameSize: frameSize, xTicks: true, yTicks: true)
        .frame(width: 350, height: 250, alignment: .center)
  
 }
}

alt tag

-- Multipul plot --

struct MultiPlot:View {
    var body:some View {
        let plotset:[PlotData] = [PlotData(x: 0.0,y: 0.0),PlotData(x: 1.0,y: 2.0),PlotData(x: 2.0,y: 5.0),
                                  PlotData(x: 3.0,y: 3.0),PlotData(x: 4.0,y: 8.0),PlotData(x: 5.0,y: 10.0),
                                  PlotData(x: 6.0,y: 25.0),PlotData(x: 7.0,y: 21.0),PlotData(x: 8.0,y: 23.0),
                                  PlotData(x: 9.0,y: 22.0),PlotData(x: 9.6,y: 21.0),PlotData(x: 10,y: 30.0)]
        
        let frameSize = CGSize(width: 300, height: 200)
        let linePLot = GraphPlot(type: .linePlot, color: .orange)
        let barPlot = GraphPlot(type: .verticalBar, color: .blue)
        let bubblePlot = GraphPlot(type: .circlePlot, color: .blue)
            .setCircleRadiusFunc{ index in plotset[index].getY() * 1.4}
            .setHueDegreeFunc{ index in
                                return Double(plotset[index].getY() * 90 / 23)
                              }
        
        let plotsSet = [linePLot, barPlot,bubblePlot]
        
        return GraphView(dataSet: plotset, plotTypes: plotsSet, frameSize: frameSize, xTicks: true, yTicks: true)
               .frame(width: 350, height: 250, alignment: .center)
    }
}

alt tag

Contribute

This program is still under development. However If you have any query or need more information, please open an issue.

Your contribution is highly appliciated. Please help me !!!

Credits

This program is created by Kanshu Yokoo

License

This program is available under the MIT license. See the LICENSE file for more info.

About

Graph Plot library build with SwiftUI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%