UNPKG

fin-hypergrid

Version:

Canvas-based high-performance grid

41 lines (36 loc) 1.23 kB
'use strict'; var CellRenderer = require('./CellRenderer'); /** * Renders a bar chart sparkline, hence the name. * @constructor * @extends CellRenderer */ var SparkBar = CellRenderer.extend('SparkBar', { paint: function(gc, config) { var x = config.bounds.x, y = config.bounds.y, width = config.bounds.width, height = config.bounds.height; gc.beginPath(); var val = config.value; if (!val || !val.length) { return; } var count = val.length; var eWidth = width / count; var fgColor = config.isSelected ? config.foregroundSelectionColor : config.color; if (config.backgroundColor || config.isSelected) { gc.cache.fillStyle = config.isSelected ? 'blue' : config.backgroundColor; gc.fillRect(x, y, width, height); } gc.cache.fillStyle = fgColor; for (var i = 0; i < val.length; i++) { var barheight = val[i] / 110 * height; gc.fillRect(x + 5, y + height - barheight, eWidth * 0.6666, barheight); x += eWidth; } gc.closePath(); config.minWidth = count * 10; } }); module.exports = SparkBar;