1
- namespace Highcharts
1
+ using System . Linq ;
2
+
3
+ namespace Highcharts
2
4
{
3
5
using System ;
4
6
using System . Collections . Generic ;
@@ -135,16 +137,18 @@ public void RecalcCategories()
135
137
cachedCategoriesStep = cachedPlotWidth ;
136
138
else
137
139
cachedCategoriesStep = ( float ) cachedPlotWidth / ( cachedCategories . Length - 1 ) ;
138
-
140
+
139
141
if ( cachedCategoriesStep < categoriesMinStep )
140
142
{
141
143
cachedCategoriesStep = categoriesMinStep ;
142
144
143
145
// Filter categories.
144
146
cachedCategoriesFiltered = new List < string > ( ) ;
145
147
for ( float i = 0 ; i < cachedCategories . Length ; i += skipFactor )
146
- cachedCategoriesFiltered . Add ( cachedCategories [ ( int ) i ] ) ;
148
+ cachedCategoriesFiltered . Add ( cachedCategories [ ( int ) i ] ) ;
147
149
}
150
+ else
151
+ cachedCategoriesFiltered = cachedCategories . ToList ( ) ;
148
152
}
149
153
}
150
154
}
@@ -321,6 +325,7 @@ private void DrawSeries(Graphics g, Series s)
321
325
{
322
326
double currentValue = s . data [ ( int ) i ] ;
323
327
328
+ bool last = i + pointInterval >= sdataCount ;
324
329
float currentValueYCoef = ( float ) ( ( currentValue - cachedPlotMin ) / valueRange ) ;
325
330
float currentValueX = cachedPlotLeft + xStep * categoriesIndex ;
326
331
float currentValueY = cachedPlotTop + cachedPlotHeight - cachedPlotHeight * currentValueYCoef ;
@@ -333,7 +338,7 @@ private void DrawSeries(Graphics g, Series s)
333
338
{
334
339
if ( locationX + currentValueX < - uwfOffset . X ) // Left side.
335
340
clipHorizontal = true ;
336
- if ( locationX + currentValueX + xStep + uwfOffset . X > parentWidth ) // Right side.
341
+ if ( locationX + currentValueX + uwfOffset . X > parentWidth ) // Right side.
337
342
clipHorizontal = true ;
338
343
}
339
344
@@ -344,8 +349,6 @@ private void DrawSeries(Graphics g, Series s)
344
349
{
345
350
if ( i > 0 )
346
351
{
347
- bool last = i + pointInterval >= sdataCount ;
348
-
349
352
float prevValueYCoef = ( float ) ( ( prevValue - cachedPlotMin ) / valueRange ) ;
350
353
float prevValueX = cachedPlotLeft + ( categoriesIndex - 1 ) * xStep ;
351
354
float prevValueY = cachedPlotTop + cachedPlotHeight - cachedPlotHeight * prevValueYCoef ;
@@ -366,8 +369,6 @@ private void DrawSeries(Graphics g, Series s)
366
369
float prevValueX = cachedPlotLeft + ( categoriesIndex - 1 ) * xStep ;
367
370
float prevValueY = cachedPlotTop + cachedPlotHeight - cachedPlotHeight * prevValueYCoef ;
368
371
369
- bool last = i + pointInterval >= sdataCount ;
370
-
371
372
if ( s . linearGradient == false )
372
373
{
373
374
g . uwfFillRectangle ( areaColor , prevValueX , prevValueY , currentValueX - prevValueX ,
@@ -408,10 +409,13 @@ private void DrawSeries(Graphics g, Series s)
408
409
break ;
409
410
case SeriesTypes . line :
410
411
{
411
- float prevValueYCoef = ( float ) ( ( prevValue - cachedPlotMin ) / valueRange ) ;
412
- float prevValueX = cachedPlotLeft + ( categoriesIndex - 1 ) * xStep ;
413
- float prevValueY = cachedPlotTop + cachedPlotHeight - cachedPlotHeight * prevValueYCoef ;
414
- g . DrawLine ( s . pen , prevValueX , prevValueY , currentValueX + 1 , currentValueY ) ;
412
+ if ( i > 0 )
413
+ {
414
+ float prevValueYCoef = ( float ) ( ( prevValue - cachedPlotMin ) / valueRange ) ;
415
+ float prevValueX = cachedPlotLeft + ( categoriesIndex - 1 ) * xStep ;
416
+ float prevValueY = cachedPlotTop + cachedPlotHeight - cachedPlotHeight * prevValueYCoef ;
417
+ g . DrawLine ( s . pen , prevValueX , prevValueY , currentValueX + 1 , currentValueY ) ;
418
+ }
415
419
}
416
420
break ;
417
421
case SeriesTypes . lineSolid :
@@ -723,17 +727,12 @@ private double ValueAtX(Series s, int x)
723
727
var sdataCount = s . data . Count ;
724
728
if ( sdataCount == 0 ) return 0 ;
725
729
726
- float pointInterval = s . pointInterval ;
727
- float xStep = cachedCategoriesStep ;
728
- if ( sdataCount > 1 )
729
- xStep = ( float ) cachedPlotWidth / ( sdataCount - 1 ) ;
730
- xStep *= pointInterval ;
731
-
732
- var categoriesIndex = ( int ) ( ( x - cachedPlotLeft ) / xStep ) ;
733
- if ( categoriesIndex < 0 || categoriesIndex >= sdataCount )
730
+ var xCoef = ( float ) ( x - cachedPlotLeft ) / cachedPlotWidth ;
731
+ var dataIndex = ( int ) ( xCoef * sdataCount ) ;
732
+ if ( dataIndex > sdataCount )
734
733
return 0 ;
735
734
736
- return s . data [ categoriesIndex ] ;
735
+ return s . data [ dataIndex ] ;
737
736
}
738
737
}
739
738
}
0 commit comments