2017-11-28 21:57:05 +01:00
|
|
|
import { withComponent, props } from 'skatejs';
|
|
|
|
import { Timeseries } from '../lib/timeseries';
|
|
|
|
|
|
|
|
const Component = withComponent();
|
|
|
|
|
|
|
|
class Heatmap extends Component {
|
|
|
|
static props = {
|
|
|
|
timeseries: props.string,
|
2017-11-28 22:46:49 +01:00
|
|
|
days: props.number,
|
2017-11-28 21:57:05 +01:00
|
|
|
interpolate: props.boolean,
|
|
|
|
accumulate: props.boolean,
|
2017-11-30 16:09:18 +01:00
|
|
|
data: props.array,
|
2017-11-28 21:57:05 +01:00
|
|
|
};
|
|
|
|
connected() {
|
2017-11-30 16:09:18 +01:00
|
|
|
if (!this.timeseries) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const daySlots = this.days || 7;
|
|
|
|
this.ts = new Timeseries(this.timeseries, new Date(), daySlots);
|
|
|
|
this.ts.getData({
|
|
|
|
interpolate: this.interpolate,
|
|
|
|
accumulate: this.accumulate,
|
|
|
|
usePreviousValue: false,
|
|
|
|
})
|
|
|
|
.then((values) => {
|
|
|
|
this.data = values;
|
|
|
|
});
|
2017-11-28 21:57:05 +01:00
|
|
|
}
|
|
|
|
renderer(renderRoot, render) {
|
|
|
|
const root = renderRoot;
|
|
|
|
root.innerHtml = '';
|
|
|
|
root.appendChild(render());
|
|
|
|
}
|
|
|
|
|
2017-11-30 16:09:18 +01:00
|
|
|
render({ data, ts }) {
|
2017-11-28 21:57:05 +01:00
|
|
|
const el = document.createElement('div');
|
2017-11-30 16:09:18 +01:00
|
|
|
if (!data || !data.length || !ts) {
|
|
|
|
// No data yet
|
2017-11-28 21:57:05 +01:00
|
|
|
return el;
|
|
|
|
}
|
2017-11-30 16:09:18 +01:00
|
|
|
const graphData = [{
|
2017-11-28 21:57:05 +01:00
|
|
|
x: ts.getSlotLabels(),
|
|
|
|
y: ts.getDayLabels(),
|
2017-11-30 16:09:18 +01:00
|
|
|
z: data,
|
2017-11-28 21:57:05 +01:00
|
|
|
type: 'heatmap',
|
|
|
|
colorscale: [
|
|
|
|
['0.0', 'rgb(0, 0, 0)'],
|
|
|
|
['0.9', 'rgb(255, 0, 0)'],
|
|
|
|
['1.0', 'rgb(128, 0, 0)'],
|
|
|
|
],
|
|
|
|
showlegend: false,
|
|
|
|
showscale: false,
|
|
|
|
}];
|
|
|
|
const layout = {
|
|
|
|
yaxis: {
|
|
|
|
autorange: 'reversed',
|
|
|
|
tickfont: {
|
|
|
|
family: 'Source Code Pro',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
xaxis: {
|
|
|
|
type: 'category',
|
|
|
|
tickfont: {
|
|
|
|
family: 'Source Code Pro',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
paper_bgcolor: 'transparent',
|
2017-11-30 15:45:16 +01:00
|
|
|
margin: {
|
|
|
|
r: 0,
|
|
|
|
t: 0,
|
|
|
|
b: 0,
|
|
|
|
},
|
2017-11-28 21:57:05 +01:00
|
|
|
};
|
2017-11-30 16:09:18 +01:00
|
|
|
Plotly.newPlot(el, graphData, layout, {
|
|
|
|
staticPlot: true,
|
|
|
|
});
|
2017-11-28 21:57:05 +01:00
|
|
|
return el;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define('cbase-heatmap', Heatmap);
|