MCPcopy Create free account
hub / github.com/Marus/cortex-debug / updateGraph

Method updateGraph

src/grapher/timeseriesgraph.ts:171–223  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

169 }
170
171 public updateGraph() {
172 if (!this.stopped) {
173 const now = new Date().getTime();
174 this.x.domain([now - this.span, now]);
175 this.xAxis.call(d3.axisBottom(this.x));
176
177 const visAnnotations = this.annotations.filter((a) => a.timestamp >= now - this.span && a.timestamp <= now);
178
179 // tslint:disable-next-line:max-line-length
180 const lines = this.ag.selectAll('line.annotation').data(visAnnotations).attr('x1', (d: any) => this.x(d.timestamp)).attr('x2', (d: any) => this.x(d.timestamp));
181 // tslint:disable-next-line:max-line-length
182 lines.enter().append('line').classed('annotation', true).attr('stroke', (d: any) => d.type === 'continued' ? 'rgba(0, 255, 0, 0.25)' : 'rgba(255, 0, 0, 0.25)').attr('stroke-width', 1).attr('y1', 0).attr('y2', this.height).attr('x1', (d: any) => this.x(d.timestamp)).attr('x2', (d: any) => this.x(d.timestamp));
183 lines.exit().remove();
184
185 this.paths.forEach((path) => {
186 try {
187 const data = this.datasource.getData(path.graphId, now - this.span, now, true);
188 path.path.datum(data).attr('d', this.line);
189 }
190 catch (e) {
191 console.log('Error Updating Plot: ', e);
192 }
193 });
194
195 let startTime = this.start;
196
197 this.spaths.forEach((path) => {
198 const oldest = this.datasource.oldestPoint(path.graphId);
199 if (oldest && oldest.timestamp < startTime) { startTime = oldest.timestamp; }
200 });
201
202 this.sx.domain([startTime, now]);
203 this.sxAxis.call(d3.axisBottom(this.sx));
204
205 this.spaths.forEach((path) => {
206 try {
207 const data = this.datasource.sampleData(path.graphId, this.width, startTime, now);
208 path.path.datum(data).attr('d', this.sline);
209 }
210 catch (e) {
211 console.log('Error Updating Plot: ', e);
212 }
213 });
214
215 let st = now - this.span;
216 if (st < startTime) { st = startTime; }
217 const startX = this.sx(st);
218 const endX = this.sx(now);
219 this.hrect.attr('x', startX).attr('width', endX - startX);
220 }
221
222 window.requestAnimationFrame(this.updateGraph.bind(this));
223 }
224}

Callers

nothing calls this directly

Calls 7

removeMethod · 0.80
exitMethod · 0.80
getDataMethod · 0.80
logMethod · 0.80
oldestPointMethod · 0.80
sampleDataMethod · 0.80
requestAnimationFrameMethod · 0.65

Tested by

no test coverage detected