Commit 09706526 authored by Sascha Herzinger's avatar Sascha Herzinger
Browse files

small refactor

parent c9956180
......@@ -9,10 +9,19 @@ export default class {
throw Error('name getter not implemented.');
}
update() {
render() {
throw Error('update() not implemented.');
}
resize() {
this.container.style['font-size'] = `${this.containerWidth / 50}pt`;
}
update(args) {
this.resize();
this.render(args);
}
prepareSVGForCapture() {
throw Error('prepareSVGForCapture() not implemented.');
}
......
......@@ -49,7 +49,7 @@ export default class extends Chart {
});
}
update({ values, valueRange, rows, cols, sequential }) {
render({ values, valueRange, rows, cols, sequential }) {
this.valueRange = typeof valueRange === 'undefined' ? this.valueRange : valueRange;
this.rows = typeof rows === 'undefined' ? this.rows : rows;
this.cols = typeof cols === 'undefined' ? this.cols : cols;
......@@ -68,8 +68,6 @@ export default class extends Chart {
this.width = this.containerWidth - this.margin.left - this.margin.right;
this.height = this.containerWidth - this.margin.top - this.margin.bottom;
this.container.style['font-size'] = `${this.width / 50}pt`;
this.xScale = d3.scaleBand()
.domain(this.cols)
.range([0, this.width]);
......@@ -229,7 +227,22 @@ export default class extends Chart {
.on('mouseleave', () => this.highlight({}));
const nodes = this.memory.selectAll('rect').nodes();
this.draw(nodes);
const context = this.canvas.node().getContext('2d');
const t = d3.timer((elapsed) => {
setTimeout(() => {
context.clearRect(0, 0, this.width, this.height);
nodes.forEach((node) => {
context.fillStyle = node.getAttribute('fillStyle');
context.fillRect(
node.getAttribute('x'),
node.getAttribute('y'),
node.getAttribute('width'),
node.getAttribute('height'),
);
});
}, 0);
if (elapsed > this.ANIMATION_DURATION) t.stop();
}, 0);
}
highlight({ row, col }) {
......@@ -264,23 +277,4 @@ Col &nbsp; &nbsp; &nbsp; ${col}</br>
.filter(d => d === col && typeof col !== 'undefined')
.classed('highlight', true);
}
draw(nodes) {
const context = this.canvas.node().getContext('2d');
const t = d3.timer((elapsed) => {
setTimeout(() => {
context.clearRect(0, 0, this.width, this.height);
nodes.forEach((node) => {
context.fillStyle = node.getAttribute('fillStyle');
context.fillRect(
node.getAttribute('x'),
node.getAttribute('y'),
node.getAttribute('width'),
node.getAttribute('height'),
);
});
}, 0);
if (elapsed > this.ANIMATION_DURATION) t.stop();
}, 0);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment