-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4661 from hashicorp/f-ui-line-chart
UI: line chart
- Loading branch information
Showing
17 changed files
with
999 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}, | ||
}); |
Oops, something went wrong.