-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Added gradient line drawing to LineChartRenderer. based on PR #3142 #3415
Conversation
First glance looks okay. Please fix build failures. What do you mean by "stabilization"? I'll review thoroughly once fixed. |
context.setStrokeColor(drawingColor.cgColor) | ||
context.strokePath() | ||
} | ||
drawLine(context: context, dataSet: dataSet, spline: cubicPath, matrix: valueToPixelMatrix, drawingColor: drawingColor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about doing this. I think this correct way to do it is
if dataSet.isDrawLineWithGradientEnabled
{
drawGradientLine(context: context, dataSet: dataSet, spline: cubicPath, matrix: valueToPixelMatrix)
}
else
{
drawLine(in: ...)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I exposed this logic into a separate function with the name drawLine
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm aware. I'm saying that drawLine
and drawGradientLine
should be separate methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pushed a change. I think that this's correct now.
@@ -795,6 +806,12 @@ open class LineChartRenderer: LineRadarRenderer | |||
|
|||
func drawGradientLine(context: CGContext, dataSet: LineChartDataSetProtocol, spline: CGPath, matrix: CGAffineTransform) | |||
{ | |||
guard let gradientPositions = dataSet.gradientPositions else | |||
{ | |||
assertionFailure("Must set `gradientPositions if `dataSet.isDrawLineWithGradientEnabled` is true") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I think we could use more of this.
|
I'll fix the crash. It's because different return parameters of the |
Codecov Report
@@ Coverage Diff @@
## 4.0.0 #3415 +/- ##
==========================================
- Coverage 29.42% 29.26% -0.16%
==========================================
Files 114 114
Lines 12605 12683 +78
==========================================
+ Hits 3709 3712 +3
- Misses 8896 8971 +75
Continue to review full report at Codecov.
|
It looks that gradient locations are calculated wrong. I hope that I'll fix it tomorrow. |
context: CGContext, | ||
dataSet: LineChartDataSetProtocol, | ||
spline: CGMutablePath, | ||
matrix: CGAffineTransform, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
||
private func drawLine( | ||
context: CGContext, | ||
dataSet: LineChartDataSetProtocol, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
5bfb844
to
98d4148
Compare
98d4148
to
7389b76
Compare
What anyone thing about implementing similar approach like for fill, i.e.
|
That sounds like a great idea. I think the properties can all be |
@jjatie what do you think about class name? is it fine? or better LineChartGradient, LineChartLineGradient? |
Hold off on doing it in this PR, a separate one would be greatly appreciated where you implement this across all gradient usage in the framework. |
@@ -785,6 +796,11 @@ open class LineChartRenderer: LineRadarRenderer | |||
|
|||
// create a new path | |||
let to = Int(ceil(CGFloat(to - from) * phaseX + CGFloat(from))) | |||
|
|||
guard (from + 1) < to else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this?
Maybe let from = from + 1
instead?
Would be nice to have a comment for why we use + 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this?
this's because path generations starts from command move
for the first point, and then add line
.
{ | ||
fatalError("Must set `gradientPositions if `dataSet.isDrawLineWithGradientEnabled` is true") | ||
let boundingBox = spline.boundingBox | ||
guard !boundingBox.isNull && !boundingBox.isInfinite && !boundingBox.isEmpty else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comma instead of ampersand. We're listing requirements, not performing Boolean logic.
Source/Charts/Utils/Platform.swift
Outdated
@@ -304,6 +320,26 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple | |||
} | |||
} | |||
|
|||
extension NSUIColor | |||
{ | |||
var nsuiRGBA: (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat)? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to rgba
Source/Charts/Utils/Platform.swift
Outdated
|
||
extension NSUIColor | ||
{ | ||
var nsuiRGBA: (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat)? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rgba
@jjatie I think it would be great to rebase this PR into |
73aa129
to
729fb18
Compare
617fa81
to
3c20de9
Compare
3c20de9
to
aee20f0
Compare
Thanks 👍 |
Some stabilization and code cleanup.
@jjatie could you please take a look at this PR. This PR stabilises and improves your PR #3142