2222
2323import eventHelpers from '../lib/eventHelpers.js' ;
2424
25+ const bufferSize = 20000 ;
26+
2527/** @abstract */
2628export default class MCTChartSeriesElement {
2729 constructor ( series , chart , offset ) {
2830 this . series = series ;
2931 this . chart = chart ;
3032 this . offset = offset ;
31- this . buffer = new Float32Array ( 20000 ) ;
33+ this . buffer = new Float32Array ( bufferSize ) ;
3234 this . count = 0 ;
35+ this . indexCount = 0 ;
3336
3437 eventHelpers . extend ( this ) ;
3538
@@ -94,7 +97,7 @@ export default class MCTChartSeriesElement {
9497
9598 makePoint ( point , series ) {
9699 if ( ! this . offset . xVal ) {
97- this . chart . setOffset ( point , undefined , series ) ;
100+ this . chart . setOffset ( point , series ) ;
98101 }
99102
100103 return {
@@ -104,12 +107,15 @@ export default class MCTChartSeriesElement {
104107 }
105108
106109 append ( point , index , series ) {
107- const pointsRequired = this . vertexCountForPointAtIndex ( index ) ;
108- const insertionPoint = this . startIndexForPointAtIndex ( index ) ;
109- this . growIfNeeded ( pointsRequired ) ;
110- this . makeInsertionPoint ( insertionPoint , pointsRequired ) ;
111- this . addPoint ( this . makePoint ( point , series ) , insertionPoint ) ;
112- this . count += pointsRequired / 2 ;
110+ if ( this . chart . pointIsInRange ( point , series ) ) {
111+ const pointsRequired = this . vertexCountForPointAtIndex ( this . indexCount ) ;
112+ const insertionPoint = this . startIndexForPointAtIndex ( this . indexCount ) ;
113+ this . growIfNeeded ( pointsRequired ) ;
114+ this . makeInsertionPoint ( insertionPoint , pointsRequired ) ;
115+ this . addPoint ( this . makePoint ( point , series ) , insertionPoint ) ;
116+ this . count += pointsRequired / 2 ;
117+ this . indexCount ++ ;
118+ }
113119 }
114120
115121 makeInsertionPoint ( insertionPoint , pointsRequired ) {
@@ -128,9 +134,13 @@ export default class MCTChartSeriesElement {
128134 }
129135
130136 reset ( ) {
131- this . buffer = new Float32Array ( 20000 ) ;
137+ this . buffer = new Float32Array ( bufferSize ) ;
132138 this . count = 0 ;
139+ this . indexCount = 0 ;
133140 if ( this . offset . x ) {
141+ // reset the offset since we're starting over
142+ // TODO: handle what happens when we zoom out - do we request the data again?
143+ this . chart . resetOffsets ( this . offset ) ;
134144 this . series . getSeriesData ( ) . forEach ( function ( point , index ) {
135145 this . append ( point , index , this . series ) ;
136146 } , this ) ;
@@ -142,7 +152,7 @@ export default class MCTChartSeriesElement {
142152 let temp ;
143153
144154 if ( remainingPoints <= pointsRequired ) {
145- temp = new Float32Array ( this . buffer . length + 20000 ) ;
155+ temp = new Float32Array ( this . buffer . length + bufferSize ) ;
146156 temp . set ( this . buffer ) ;
147157 this . buffer = temp ;
148158 }
0 commit comments