Refactored old canvas pattern.
This commit is contained in:
parent
f5d97b560c
commit
1ffb0b159a
@ -1,10 +1,16 @@
|
||||
"use strict";
|
||||
import Visualizer from "../visualization/Visualizer.js";
|
||||
|
||||
function bindHorizontalBar(canvasElement, visualizerCore) {
|
||||
/**
|
||||
* Accepts a canvas and uses the entire canvas to draw a horizontal visualizer.
|
||||
*
|
||||
* @param {HTMLCanvasElement} canvasElement the canvas element to use to draw this horizontal visualizer.
|
||||
* @param {Visualizer} visualizer the visualizer in which the data to display is obtained.
|
||||
*/
|
||||
export function horizontalVisualizer(canvasElement, visualizer) {
|
||||
let _width = canvasElement.width;
|
||||
let _height = canvasElement.height;
|
||||
let _canvasCtx = canvasElement.getContext("2d");
|
||||
let _visualizerCore = visualizerCore;
|
||||
let _visualizer = visualizer;
|
||||
let update = function (delta, bins) {
|
||||
_canvasCtx.clearRect(0, 0, _width, _height); // clear canvas.
|
||||
let barWidth = Math.floor(_width / bins.length) - 1; // -1 for 1 pixel gap between bars.
|
||||
@ -17,5 +23,5 @@ function bindHorizontalBar(canvasElement, visualizerCore) {
|
||||
barIndex += 1;
|
||||
});
|
||||
};
|
||||
_visualizerCore.addUpdateListener(update);
|
||||
_visualizer.addUpdateListener(update);
|
||||
}
|
Loading…
Reference in New Issue
Block a user