import hbs from 'htmlbars-inline-precompile'; import EmberObject, { computed } from '@ember/object'; import { on } from '@ember/object/evented'; import moment from 'moment'; import DelayedArray from '../utils/delayed-array'; export default { title: 'Charts|Stats Time Series', }; let ts = offset => moment() .subtract(offset, 'm') .toDate(); export let Standard = () => { return { template: hbs`
Line charts, and therefore stats time series charts, use a letant linear gradient with a height equal to the canvas. This makes the color intensity of the gradient at values consistent across charts as long as those charts have the same y-axis domain.
This is used to great effect with stats charts since they all have a y-axis domain of 0-100%.
`, context: { data: EmberObject.extend({ timerTicks: 0, startTimer: on('init', function() { this.set( 'timer', setInterval(() => { let metricsHigh = this.metricsHigh; let prev = metricsHigh.length ? metricsHigh[metricsHigh.length - 1].percent : 0.9; this.appendTSValue( metricsHigh, Math.min(Math.max(prev + Math.random() * 0.05 - 0.025, 0.5), 1) ); let metricsLow = this.metricsLow; let prev2 = metricsLow.length ? metricsLow[metricsLow.length - 1].percent : 0.1; this.appendTSValue( metricsLow, Math.min(Math.max(prev2 + Math.random() * 0.05 - 0.025, 0), 0.5) ); }, 1000) ); }), appendTSValue(array, percent, maxLength = 300) { array.addObject({ timestamp: Date.now(), percent, }); if (array.length > maxLength) { array.splice(0, array.length - maxLength); } }, willDestroy() { clearInterval(this.timer); }, metricsHigh: computed(() => { return []; }), metricsLow: computed(() => { return []; }), secondsFormat() { return date => moment(date).format('HH:mm:ss'); }, }).create(), }, }; };