@@ -316,123 +316,63 @@ open class LineChartRenderer: LineRadarRenderer
316
316
317
317
context. saveGState ( )
318
318
319
- // more than 1 color
320
- if dataSet. colors. count > 1
321
- {
322
319
if _lineSegments. count != pointsPerEntryPair
323
320
{
324
321
// Allocate once in correct size
325
322
_lineSegments = [ CGPoint] ( repeating: CGPoint ( ) , count: pointsPerEntryPair)
326
323
}
327
324
328
- for j in _xBounds
325
+ for j in stride ( from: _xBounds. min, through: _xBounds. range + _xBounds. min, by: 1 )
326
+ {
327
+ var e : ChartDataEntry ! = dataSet. entryForIndex ( j)
328
+
329
+ if e == nil { continue }
330
+
331
+ _lineSegments [ 0 ] . x = CGFloat ( e. x)
332
+ _lineSegments [ 0 ] . y = CGFloat ( e. y * phaseY)
333
+
334
+ if j < _xBounds. max
329
335
{
330
- var e : ChartDataEntry ! = dataSet. entryForIndex ( j)
331
-
332
- if e == nil { continue }
336
+ e = dataSet. entryForIndex ( j + 1 )
333
337
334
- _lineSegments [ 0 ] . x = CGFloat ( e. x)
335
- _lineSegments [ 0 ] . y = CGFloat ( e. y * phaseY)
338
+ if e == nil { break }
336
339
337
- if j < _xBounds . max
340
+ if isDrawSteppedEnabled
338
341
{
339
- e = dataSet. entryForIndex ( j + 1 )
340
-
341
- if e == nil { break }
342
-
343
- if isDrawSteppedEnabled
344
- {
345
- _lineSegments [ 1 ] = CGPoint ( x: CGFloat ( e. x) , y: _lineSegments [ 0 ] . y)
346
- _lineSegments [ 2 ] = _lineSegments [ 1 ]
347
- _lineSegments [ 3 ] = CGPoint ( x: CGFloat ( e. x) , y: CGFloat ( e. y * phaseY) )
348
- }
349
- else
350
- {
351
- _lineSegments [ 1 ] = CGPoint ( x: CGFloat ( e. x) , y: CGFloat ( e. y * phaseY) )
352
- }
342
+ _lineSegments [ 1 ] = CGPoint ( x: CGFloat ( e. x) , y: _lineSegments [ 0 ] . y)
343
+ _lineSegments [ 2 ] = _lineSegments [ 1 ]
344
+ _lineSegments [ 3 ] = CGPoint ( x: CGFloat ( e. x) , y: CGFloat ( e. y * phaseY) )
353
345
}
354
346
else
355
347
{
356
- _lineSegments [ 1 ] = _lineSegments [ 0 ]
348
+ _lineSegments [ 1 ] = CGPoint ( x : CGFloat ( e . x ) , y : CGFloat ( e . y * phaseY ) )
357
349
}
350
+ }
351
+ else
352
+ {
353
+ _lineSegments [ 1 ] = _lineSegments [ 0 ]
354
+ }
358
355
359
- for i in 0 ..< _lineSegments. count
360
- {
361
- _lineSegments [ i] = _lineSegments [ i] . applying ( valueToPixelMatrix)
362
- }
363
-
364
- if ( !viewPortHandler. isInBoundsRight ( _lineSegments [ 0 ] . x) )
365
- {
366
- break
367
- }
368
-
369
- // make sure the lines don't do shitty things outside bounds
370
- if !viewPortHandler. isInBoundsLeft ( _lineSegments [ 1 ] . x)
371
- || ( !viewPortHandler. isInBoundsTop ( _lineSegments [ 0 ] . y) && !viewPortHandler. isInBoundsBottom ( _lineSegments [ 1 ] . y) )
372
- {
373
- continue
374
- }
375
-
376
- // get the color that is set for this line-segment
377
- context. setStrokeColor ( dataSet. color ( atIndex: j) . cgColor)
378
- context. strokeLineSegments ( between: _lineSegments)
356
+ for i in 0 ..< _lineSegments. count
357
+ {
358
+ _lineSegments [ i] = _lineSegments [ i] . applying ( valueToPixelMatrix)
379
359
}
380
- }
381
- else
382
- { // only one color per dataset
383
360
384
- var e1 : ChartDataEntry !
385
- var e2 : ChartDataEntry !
386
-
387
- e1 = dataSet . entryForIndex ( _xBounds . min )
361
+ if ( !viewPortHandler . isInBoundsRight ( _lineSegments [ 0 ] . x ) )
362
+ {
363
+ break
364
+ }
388
365
389
- if e1 != nil
366
+ // make sure the lines don't do shitty things outside bounds
367
+ if !viewPortHandler. isInBoundsLeft ( _lineSegments [ 1 ] . x)
368
+ || ( !viewPortHandler. isInBoundsTop ( _lineSegments [ 0 ] . y) && !viewPortHandler. isInBoundsBottom ( _lineSegments [ 1 ] . y) )
390
369
{
391
- context. beginPath ( )
392
- var firstPoint = true
393
-
394
- for x in _xBounds
395
- {
396
- e1 = dataSet. entryForIndex ( x == 0 ? 0 : ( x - 1 ) )
397
- e2 = dataSet. entryForIndex ( x)
398
-
399
- if e1 == nil || e2 == nil { continue }
400
-
401
- let pt = CGPoint (
402
- x: CGFloat ( e1. x) ,
403
- y: CGFloat ( e1. y * phaseY)
404
- ) . applying ( valueToPixelMatrix)
405
-
406
- if firstPoint
407
- {
408
- context. move ( to: pt)
409
- firstPoint = false
410
- }
411
- else
412
- {
413
- context. addLine ( to: pt)
414
- }
415
-
416
- if isDrawSteppedEnabled
417
- {
418
- context. addLine ( to: CGPoint (
419
- x: CGFloat ( e2. x) ,
420
- y: CGFloat ( e1. y * phaseY)
421
- ) . applying ( valueToPixelMatrix) )
422
- }
423
-
424
- context. addLine ( to: CGPoint (
425
- x: CGFloat ( e2. x) ,
426
- y: CGFloat ( e2. y * phaseY)
427
- ) . applying ( valueToPixelMatrix) )
428
- }
429
-
430
- if !firstPoint
431
- {
432
- context. setStrokeColor ( dataSet. color ( atIndex: 0 ) . cgColor)
433
- context. strokePath ( )
434
- }
370
+ continue
435
371
}
372
+
373
+ // get the color that is set for this line-segment
374
+ context. setStrokeColor ( dataSet. color ( atIndex: j) . cgColor)
375
+ context. strokeLineSegments ( between: _lineSegments)
436
376
}
437
377
438
378
context. restoreGState ( )
0 commit comments