Created
January 5, 2018 12:30
-
-
Save lolmaus/c7032ab0400c32c44d085f48f508fd57 to your computer and use it in GitHub Desktop.
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
// Datepicker component | |
import Ember from 'ember'; | |
import moment from 'moment'; | |
import service from 'ember-service/inject'; | |
const { | |
get, | |
computed, | |
observer | |
} = Ember; | |
export default Ember.Component.extend({ | |
classNames: ['float-right', 'fw-performance-date-range'], | |
performance: service(), | |
startDate: computed({ | |
get() { | |
return get(this, 'performance.startDate'); | |
} | |
}), | |
endDate: computed({ | |
get() { | |
return get(this, 'performance.endDate'); | |
} | |
}), | |
range: computed({ | |
get() { | |
return { | |
start: get(this, 'startDate'), | |
end: get(this, 'endDate') | |
} | |
} | |
}), | |
formattedRange: computed('range', { | |
get() { | |
const range = get(this, 'range'); | |
let textValue; | |
if (Ember.isEmpty(range)) { | |
textValue = ''; | |
} else { | |
textValue = `${moment(get(this, 'range.start')).format('DD/MM/YY')} - ${Ember.isEmpty(get(this, 'range.end')) ? '?' : moment(get(this, 'range.end')).format('DD/MM/YY')}`; | |
} | |
return textValue; | |
} | |
}), | |
rangeChanged: observer('range', function() { | |
const range = get(this, 'range'); | |
const performance = get(this, 'performance'); | |
if (get(range, 'start') && get(range, 'end')) { | |
performance.setProperties({ | |
startDate: moment(get(range, 'start')).format('DD-MM-YYYY'), | |
endDate: moment(get(range, 'end')).format('DD-MM-YYYY') | |
}); | |
} | |
}) | |
}); |
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
// Chart component | |
// Should catch any performance service changes | |
import Ember from 'ember'; | |
import Plotly from 'plotly'; | |
import service from 'ember-service/inject'; | |
const { | |
get, | |
computed, | |
observer | |
} = Ember; | |
const layout = { | |
title: 'Time series chart title', | |
margin: { | |
l: 30, | |
r: 30, | |
t: 30, | |
b: 30 | |
} | |
}; | |
export default Ember.Component.extend({ | |
performance: service(), | |
classNames: ['time-series-chart'], | |
chartId: 'time-series-chart-place', | |
plotlyName: 'time-series-chart-place', | |
endDate: computed({ | |
get() { | |
return get(this, 'performance.endDate'); | |
} | |
}), | |
dataArr: computed({ | |
get() { | |
return get(this, 'timeSeriesDataArr'); | |
} | |
}), | |
dateRangeChanged: observer('endDate', function() { | |
debugger; | |
console.log('fire'); | |
}), | |
didInsertElement() { | |
this._super(...arguments); | |
this.$(get(this, 'chartId')); | |
Plotly.newPlot(get(this, 'plotlyName'), get(this, 'dataArr'), layout); | |
} | |
}); |
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
// service | |
import Ember from 'ember'; | |
export default Ember.Service.extend({ | |
startDate: '', | |
endDate: '' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment