Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 version of SwiftUI ChartView #89

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open

V2 version of SwiftUI ChartView #89

wants to merge 29 commits into from

Conversation

AppPear
Copy link
Owner

@AppPear AppPear commented May 22, 2020

The goal is to have a new more easily expandable codebase, setup with CI and test so PRs could be merged quicker and safer.

If you would like to help and participate in the new version you are very welcomed you can find project related tasks here or under the Issues with a v2 tag

to submit your work please fork this repo and create a new branch from new-version branch then update with your work and create a PR for the new-version branch.

If you work on a ticket please go to the project board and assign the ticket to yourself and move it to the in-progress column. If you are finished please assign the newly created PR to me and move your ticket to the ready-for-review column.

Join our Slack channel for day to day conversation and more insights:

slack invite link

New code proposal:

ChartViews

These chart views come with the bare minimum for a chart, so it can be easily built into custom user interfaces. We also build on them for the more complex chart widgets.

Data

  • should be a structure which can hold a x and y value.
  • y value must be numeric (possibly floating point number)
  • x can be numeric or string
  • has to be at least 3 initialisers: 1) only y values, 2) x and y numeric values 3) x string and y numeric values

Barchart:

@State var chartData: [Double] = [0, 5, 6, 2, 13, 4, 3, 6]

BarChart()
.data(chartData)
.style(lightOrange)

Linechart:

@State var chartData: [Double] = [0, 5, 6, 2, 13, 4, 3, 6]

LineChart()
.data(chartData)
.style(lightOrange)

Piechart:

@State var chartData: [Double] = [0, 5, 6, 2, 13, 4, 3, 6]

PieChart()
.data(chartData)
.style(lightOrange)

Grid (not in beta 1)

  • is a view under a chart
  • should support barchart and linechart
  • legend ranges can be user set
  • legend ranges can be automatic
  • user can set a custom style (colors)
Grid {
    BarChart()
}
.data(chartData)
.style(lightOrange)

Cardview

  • support for all charts
  • a holder for the chart, title, subtitle
  • support for displaying x axis values interactively
  • should be rounded
  • light versions have a shadow around them
  • dark versions have a thin light bezel
  • have 3 size presets: small, medium, large
  • user can set a custom style (colors)
  • has a defualt style so setting a style is optional
CardView {
        BarChart()
}
.data(chartData)
.style(darkBlue)

ChartData (beta 1 supports Chart init with [Double] only)

ChartData is an observable object so you can make state changes and it will be reflected now in the charts.

To initialise:

ChartData(_ data: [Double])

and to make a state change:

@State var chartData = ChartData([0, 4, 5])
.
.
.
chartData.data = [0, 2, 6, 7, 8, 11]

@AppPear AppPear self-assigned this May 22, 2020
@satan87
Copy link
Contributor

satan87 commented May 22, 2020

I believe this will break a lot of other PR. But looks cleaner, and easier so I don't mind adapting my PR.

@LucasCarioca
Copy link
Contributor

LucasCarioca commented May 22, 2020

@AppPear With this in the works, should people hold off on PRs?

Do you want to open up issues to break up this change and get help implementing it?

@satan87
Copy link
Contributor

satan87 commented May 24, 2020

To participate in the new branch, how the best way to do it?
Just fork it, update it, then create a PR?

@AppPear AppPear added this to In progress in version 2.0 via automation May 24, 2020
@AppPear AppPear removed this from In progress in version 2.0 May 24, 2020
@AppPear
Copy link
Owner Author

AppPear commented May 24, 2020

Yes, please fork it and create a PR for the new-version branch.
You can find some task under the issues with a v2 tag or you can go to the project board and find the tickets I created and would be very helpful if you could work on those.

Thanks!

@satan87
Copy link
Contributor

satan87 commented May 24, 2020

ok, I'll try working on the PieChart, but no promises;(.

@satan87
Copy link
Contributor

satan87 commented May 24, 2020

I created a first PR with minimum changes, to make sure I follow your guidelines.
Sorry for the double commit on the PR.
I added PieChart and multicolor for Bar and Pie.
I also added a swiftlint file, it helps me. You can remove it, or adapt it to your style.

Maybe we could create chat somewhere to coordinate.

@AdrianBinDC
Copy link

@AppPear I love the philosophy re: building the charts w/ the bare minimum and building upon it. One suggestion I have is writing unit tests to go along with committed code, rather than treating it as an afterthought. I'll take a peek at code coverage and see what I can unearth that's testable.

- write unit tests for CGPoint+Extension.swift
- clean up formatting on CGPoint+Extension.swift
@L1cardo
Copy link

L1cardo commented May 25, 2020

Looking forward to this!!
This will be awesome!

satan87 and others added 2 commits May 25, 2020 14:20
* Add ColorGradient example
Add ColorGradient single color constructor
Add preview for BarChart

* Add PieChart
Allow multi color for Pie and Bar
Add linter
@AppPear
Copy link
Owner Author

AppPear commented May 25, 2020

I created a first PR with minimum changes, to make sure I follow your guidelines.

Thanks, I merged it! Only small issue was accentColor:self.style.foregroundColor.rotate(for: index) that .rotate() functions was undefined so I had to remove it if you could do a fix PR defining it and reimplementing that would be awesome! @satan87

@AppPear AppPear added the v2 label May 25, 2020
@satan87
Copy link
Contributor

satan87 commented May 25, 2020

I created a first PR with minimum changes, to make sure I follow your guidelines.

Thanks, I merged it! Only small issue was accentColor:self.style.foregroundColor.rotate(for: index) that .rotate() functions was undefined so I had to remove it if you could do a fix PR defining it and reimplementing that would be awesome! @satan87

The extension file wasn't in my commit;( sorry.
PR #102

Fix for making text work with both Dark/Light mode.

Also solves line chart background to appear white in dark mode
@LucasCarioca
Copy link
Contributor

Tried out the Beta and it is looking pretty cool. How close is this to getting released?

danwood and others added 5 commits August 24, 2020 16:24
Co-authored-by: Dan Wood <danwood@users.noreply.github.com>
* Starting on filling in documentation.

* First pass on most/all files

* more descriptions filled in

* Some documentation but TBH the author would be better suited to explain how this works!

* more basic stuff filled in

* Add a description and bunch of discussion text for most of the view `body` declarations

* more explanations

Co-authored-by: Dan Wood <danwood@users.noreply.github.com>
Co-authored-by: Dan Wood <danwood@users.noreply.github.com>
* Add PieChart interaction PR changes to v2

* Add custom string format for ChartLabel when interactionInProgress = true (#151)

* Dark/Light mode fixes (#148)

Fix for making text work with both Dark/Light mode.

Also solves line chart background to appear white in dark mode

* Add custom string format for ChartLabel when interactionInProgress = true

Co-authored-by: Sagar Patel <s.72427patel@gmail.com>

* Prepare charts to display x and y values souch as a value for a given point

Co-authored-by: Roddy Munro <roddymunro@icloud.com>
Co-authored-by: Sagar Patel <s.72427patel@gmail.com>
@shreyaspapi
Copy link

Waiting for the release😁

@kakashilw
Copy link

In my widget i import SwiftUICharts. 2.0.0-beta.1,and my code

import SwiftUICharts

...............

struct TestWidgetView : View {

var entry: TestEntry


var body: some SwiftUI.View {
    
    let orangeStyle = ChartStyle(backgroundColor: .white,
                                 foregroundColor: [ColorGradient(ChartColors.orangeBright, ChartColors.orangeDark)])
    LineChart()
    .data([0, 5, 6, 2, 13, 4, 3, 6])
    .chartStyle(orangeStyle)

}

}

and run,the errors:

Showing Recent Messages
Undefined symbol: nominal type descriptor for SwiftUICharts.ChartStyle

Undefined symbol: nominal type descriptor for SwiftUICharts.LineChart

Undefined symbol: nominal type descriptor for SwiftUICharts.ChartData

Undefined symbol: nominal type descriptor for SwiftUICharts.ChartValue

Undefined symbol: protocol conformance descriptor for SwiftUICharts.LineChart : SwiftUI.View in SwiftUICharts

Undefined symbol: SwiftUICharts.ColorGradient.init(SwiftUI.Color, SwiftUI.Color) -> SwiftUICharts.ColorGradient

Undefined symbol: SwiftUICharts.ChartColors.orangeDark.unsafeMutableAddressor : SwiftUI.Color

Undefined symbol: type metadata accessor for SwiftUICharts.ChartStyle

Undefined symbol: SwiftUICharts.LineChart.init() -> SwiftUICharts.LineChart

Undefined symbol: type metadata for SwiftUICharts.ColorGradient

Undefined symbol: SwiftUICharts.ChartColors.orangeBright.unsafeMutableAddressor : SwiftUI.Color

Undefined symbol: type metadata for SwiftUICharts.LineChart

Undefined symbol: protocol witness table for SwiftUICharts.LineChart : SwiftUICharts.ChartBase in SwiftUICharts

Undefined symbol: SwiftUICharts.ChartStyle.__allocating_init(backgroundColor: SwiftUI.Color, foregroundColor: [SwiftUICharts.ColorGradient]) -> SwiftUICharts.ChartStyle

Undefined symbol: (extension in SwiftUICharts):SwiftUI.View< where A: SwiftUICharts.ChartBase>.data([Swift.Double]) -> some

Undefined symbol: (extension in SwiftUICharts):SwiftUI.View.chartStyle(SwiftUICharts.ChartStyle) -> some

@sgallo0692
Copy link

@kakashilw isn't this line:

var body: some SwiftUI.View {

Supposed to be

var body: some View {

@ghost
Copy link

ghost commented Jan 13, 2021

Hi,
are you still working on this? Last commits are from october 2020. 😢

@kevinmun
Copy link

I actually tried importing this and using it in Widget, but it draws blank on both the preview and simulator. ANyone able to get it working?

@ghost
Copy link

ghost commented Jan 19, 2021

@kevinmun yes, it works in my application.

@kevinmun
Copy link

@kevinmun yes, it works in my application.

I see, I tested it out again, and it seems, it's ok if it's deployed to device. Somehow on preview / simulator, it appears as blank. Weird.

@JanC
Copy link

JanC commented Jan 23, 2021

hey, is the v2 still being worked on or is this library not maintained anymore?

@AppPear
Copy link
Owner Author

AppPear commented Jan 24, 2021

hey, is the v2 still being worked on or is this library not maintained anymore?

Yes, currently I'm on organising a bigger help to maintain and take this lib to next level and release v2 as soon as possible

@ghost
Copy link

ghost commented Jan 24, 2021

Hi,
I've got a question to BarChart. Tthis is used with key value pairs (String -> Double). If I touch a single Bar in V1, both values are presented.
image
But in V2 only the Double value is shown.
image
Is this a bug, a forgotten feature or wrong usage from my side?

@Prince2k3
Copy link

@AppPear I'd like to join as a member. I currently have a candlestick chart working using the new-version branch on my machine. I'm interested in helping out. I like to chat about data structure for support of that type of chart and others.

@AppPear
Copy link
Owner Author

AppPear commented Jan 31, 2021

@AppPear I'd like to join as a member. I currently have a candlestick chart working using the new-version branch on my machine. I'm interested in helping out. I like to chat about data structure for support of that type of chart and others.

Can you please join the slack channel?

@tpgmeligmeyling
Copy link

tpgmeligmeyling commented Mar 3, 2021

@AppPear Can you update the Slack invite link?
Edit found it in the readme.

@AppPear
Copy link
Owner Author

AppPear commented Apr 5, 2021

Hi,
I've got a question to BarChart. Tthis is used with key value pairs (String -> Double). If I touch a single Bar in V1, both values are presented.
image
But in V2 only the Double value is shown.
image
Is this a bug, a forgotten feature or wrong usage from my side?

it's a missing feature for now, but it is coming soon to v2 as well

@m8xp0w3r
Copy link

m8xp0w3r commented Apr 7, 2021

it's a missing feature for now, but it is coming soon to v2 as well

Thank for the answer.

now it is possible to add background lines precisely as charts are displayed at correct size
also rewrote basics to conform with Shapes and Animatable protocol
@rodri0315
Copy link

Hello! How's V2 going? Anything we can help?

AppPear and others added 6 commits August 11, 2021 22:01
* feat: add linechart interaction point

* feat: add ability to show current data point on linechart
#252)

* feat: new protocol for chained functions, and added support for explicit Y ranges. X coming as well

* feat: add new axis interface (#253)
* feat: new protocol for chained functions, and added support for explicit Y ranges. X coming as well

* feat: add new axis interface (#253)
Co-authored-by: “Andras <“andras.samu@supercharge.io”>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet