Sizing support

This commit is contained in:
Henri Bergius 2017-11-30 21:50:33 +01:00
parent 88cabb3eed
commit f6f6c8435b

View file

@ -1,5 +1,6 @@
import { withComponent, props } from 'skatejs'; import { withComponent, props } from 'skatejs';
import { Timeseries } from '../lib/timeseries'; import { Timeseries } from '../lib/timeseries';
import injectCss from '../lib/plotly-shadowdom';
const Component = withComponent(); const Component = withComponent();
@ -10,6 +11,8 @@ class Heatmap extends Component {
interpolate: props.boolean, interpolate: props.boolean,
accumulate: props.boolean, accumulate: props.boolean,
data: props.array, data: props.array,
width: props.number,
height: props.number,
}; };
connected() { connected() {
if (!this.timeseries) { if (!this.timeseries) {
@ -28,16 +31,21 @@ class Heatmap extends Component {
} }
renderer(renderRoot, render) { renderer(renderRoot, render) {
const root = renderRoot; const root = renderRoot;
root.innerHtml = ''; while (root.firstChild) {
root.removeChild(root.firstChild);
}
root.appendChild(render()); root.appendChild(render());
injectCss(root);
} }
render({ data, ts }) { render({ data, ts, width, height }) {
const el = document.createElement('div'); const el = document.createElement('div');
if (!data || !data.length || !ts) { if (!data || !data.length || !ts) {
// No data yet // No data yet
return el; return el;
} }
const graphWidth = Math.floor((window.innerWidth / 100) * (width || 40));
const graphHeight = Math.floor((window.innerHeight / 100) * (height || 50));
const graphData = [{ const graphData = [{
x: ts.getSlotLabels(), x: ts.getSlotLabels(),
y: ts.getDayLabels(), y: ts.getDayLabels(),
@ -52,6 +60,9 @@ class Heatmap extends Component {
showscale: false, showscale: false,
}]; }];
const layout = { const layout = {
autosize: false,
width: graphWidth,
height: graphHeight,
yaxis: { yaxis: {
autorange: 'reversed', autorange: 'reversed',
tickfont: { tickfont: {