-
Notifications
You must be signed in to change notification settings - Fork 411
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
Cubic Area Lines with String Data #111
Comments
Hi, You can use cubic lines, you just would have to switch the layer. For cubic areas there's no layer yet. You can implement one if you want. Not sure I understood the scroll issue, cut off how? You mean make that the axis values are between chart points min / max? If yes you can use |
The areas layer would be similar to ChartPointsAreaLayer (which is the areas layer you're using now), which generates the chart points screen locations and passes them to ChartAreasView to create the path. You could maybe reuse CubicLinePathGenerator, which generates the path for the cubic lines. Ideally you would not need a new layer/view but adjust the current one to accept a generic path generator, similar to the line layer. Btw: The current cubic path generator is not very good, the curves look weird, but you can use a different algorithm/library to generate the path and pass it to the line layer. In this issue #47 near the end you find an example. It should not be very difficult to fix the algorithm in this library (by e.g. copying the one of the library referenced in the issue) but I haven't had time. In this issue #57 somebody also mentioned https://github.com/andrelind/swift-catmullrom which is written in Swift but I haven't tested this one. About cutting, it should work if you set the last x axis value to the exact coordinate of the last chart point (29.9 in this case). |
I tried adding pathGenerator to the AreaLayer, but it simply tells me that there is an extra argument 'pathGenerator' in call; let chartPointsLayer1 = ChartPointsAreaLayer(xAxis: xAxis3, yAxis: yAxis3, innerFrame: innerFrame3, chartPoints: lineChartPoints, pathGenerator: CubicLinePathGenerator(tension1: 0.3, tension2: 0.3), areaColor: csRed, animDuration: 1.5, animDelay: 0, addContainerPoints: true) Not sure if I'm over simplifying what you are suggesting. For the cutting, do you mean, add an extra point so that the value of x is the same as x of 29 and y=0 |
Yes, you are simplifying it :) the functionality to draw cubic areas as I said doesn't exist and you would have to implement it, either modifying the existing layer or creating a new one. This is an important missing feature and glad to assist you implementing it such that we can merge it in the library after it. It should not be very difficult as there's already functionality to draw an area, and to draw cubic lines, so it's just about combining this. About cutting the area, you have to ensure that the last axis value matches exactly with the corresponding max coordinate of the chart points. You can simply make that your x axis ends exactly at 29.899999618530273 (by passing this number as the value of the last axis value). If you are not showing axis labels, as it appears from your images you're already done. If you are showing axis labels you probably don't want to show this number. Something similar to this:
The max x value of chart points here may be, say, 2008, so in swiftcharts the x axis values you would have to pass would be [1900, 1920, 1940, 1960, 1980, 2000, 2008]. In order to not display 2008 (in your case 29.899999618530273) you have to set its |
Okay, thanks for the help. I really appreciate it. Also, I was wondering, is it possible to reverse the animations so that the animation started on the end and finished at the start, particularly with the line graph? |
To reverse the animation I think if you pass the chart points to the respective layer(s) in reversed order it should work. This may not work for the area layer due to the way the path is completed. Try it out and if something doesn't work we look further. |
Wouldn't passing the data in a reverse order also cause the chart to be drawn in reverse, so from my pictures, 29.9 would end up being at the start rather than at the end |
The chart uses the internal values of the points to determine the screen location so it doesn't matter where they are in the array. This only affects the animation. |
So, if my original array is;
I could reverse it, using
|
Hmm I just did a quick test with the original areas example, calling |
Ah, my mistake. I was reversing the original array that is used to create the charts rather than reversing the lineChartPoints. Thanks for clearing that up :) |
I think you may be reversing the points used to generate the axis values. Please ensure that you reverse only the chart points you pass to the content layers (the line/bars layer in your case). |
Yup, I realised as soon as I read what I posted. The line chart works now. Thanks for the help! I really appreciate it :) |
Ok, no problem! |
I have changed the following in
and got the following. Not sure why the area is not under the curve. I would like to add this feature and make a PR. |
The line path generator generates the path only for the line. To fill the area you need to add the points at the bottom of the chart to the path, similar to how it's done in |
|s it possible to get cubic lines with string data rather than integers?
I've got data such as;
var lineTest: [(title: String, val: Double)]! = []
where title could be something like "31/3" and double could be 27.7
The Area lines work, but I am just wondering if it is possible to make them cubic lines or cubic areas?
Also, Since it is in a scroll view, is it possible for it to cut off at the first and last values, rather than drop down to 0.
The text was updated successfully, but these errors were encountered: