Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: line chart #4661

Merged
merged 14 commits into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions ui/app/components/freestyle/sg-line-chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import Component from '@ember/component';
import { computed } from '@ember/object';
import d3TimeFormat from 'd3-time-format';

export default Component.extend({
timerTicks: 0,

startTimer: function() {
this.set(
'timer',
setInterval(() => {
this.incrementProperty('timerTicks');

const ref = this.get('lineChartLive');
ref.addObject({ ts: Date.now(), val: Math.random() * 30 + 20 });
if (ref.length > 60) {
ref.splice(0, ref.length - 60);
}
}, 500)
);
}.on('init'),

willDestroy() {
clearInterval(this.get('timer'));
},

lineChartData: computed(() => {
return [
{ year: 2010, value: 10 },
{ year: 2011, value: 10 },
{ year: 2012, value: 20 },
{ year: 2013, value: 30 },
{ year: 2014, value: 50 },
{ year: 2015, value: 80 },
{ year: 2016, value: 130 },
{ year: 2017, value: 210 },
{ year: 2018, value: 340 },
];
}),

lineChartMild: computed(() => {
return [
{ year: 2010, value: 100 },
{ year: 2011, value: 90 },
{ year: 2012, value: 120 },
{ year: 2013, value: 130 },
{ year: 2014, value: 115 },
{ year: 2015, value: 105 },
{ year: 2016, value: 90 },
{ year: 2017, value: 85 },
{ year: 2018, value: 90 },
];
}),

lineChartLive: computed(() => {
return [];
}),

secondsFormat() {
return d3TimeFormat.timeFormat('%H:%M:%S');
},
});
76 changes: 76 additions & 0 deletions ui/app/components/freestyle/sg-stats-time-series.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import Component from '@ember/component';
import { computed } from '@ember/object';
import d3TimeFormat from 'd3-time-format';
import moment from 'moment';

export default Component.extend({
timerTicks: 0,

startTimer: function() {
this.set(
'timer',
setInterval(() => {
const metricsHigh = this.get('metricsHigh');
const prev = metricsHigh.length ? metricsHigh[metricsHigh.length - 1].value : 0.9;
this.appendTSValue(
metricsHigh,
Math.min(Math.max(prev + Math.random() * 0.05 - 0.025, 0.5), 1)
);

const metricsLow = this.get('metricsLow');
const prev2 = metricsLow.length ? metricsLow[metricsLow.length - 1].value : 0.1;
this.appendTSValue(
metricsLow,
Math.min(Math.max(prev2 + Math.random() * 0.05 - 0.025, 0), 0.5)
);
}, 1000)
);
}.on('init'),

appendTSValue(array, value, maxLength = 300) {
array.addObject({
timestamp: Date.now(),
value,
});

if (array.length > maxLength) {
array.splice(0, array.length - maxLength);
}
},

willDestroy() {
clearInterval(this.get('timer'));
},

metricsHigh: computed(() => {
return [];
}),

metricsLow: computed(() => {
return [];
}),

staticMetrics: computed(() => {
const ts = offset =>
moment()
.subtract(offset, 'm')
.toDate();
return [
{ timestamp: ts(20), value: 0.5 },
{ timestamp: ts(18), value: 0.5 },
{ timestamp: ts(16), value: 0.4 },
{ timestamp: ts(14), value: 0.3 },
{ timestamp: ts(12), value: 0.9 },
{ timestamp: ts(10), value: 0.3 },
{ timestamp: ts(8), value: 0.3 },
{ timestamp: ts(6), value: 0.4 },
{ timestamp: ts(4), value: 0.5 },
{ timestamp: ts(2), value: 0.6 },
{ timestamp: ts(0), value: 0.6 },
];
}),

secondsFormat() {
return d3TimeFormat.timeFormat('%H:%M:%S');
},
});
Loading