UNPKG

fin-hypergrid

Version:
75 lines (67 loc) 2.64 kB
'use strict'; var Base = require('../Base'); /** @typedef paintFunction * @type {function} * @this {CellEditor} * @param {CanvasRenderingContext2D} gc * @param {object} config * @param {Rectangle} config.bounds - The clipping rect of the cell to be rendered. * @param {number} config.x - the "translated" index into the `behavior.allColumns` array * @param {number} config.normalizedY - the vertical grid coordinate normalized to first data row * @param {number} config.untranslatedX - the horizontal grid coordinate measured from first data column * @param {number} config.y - the vertical grid coordinate measured from top header row */ /** @constructor * @desc Instances of `CellRenderer` are used to render the 2D graphics context within the bound of a cell. Extend this base class to implement your own cell renderer * * * See also {@tutorial cell-renderer}. */ var CellRenderer = Base.extend('CellRenderer', { /** * @desc An empty implementation of a cell renderer, see [the null object pattern](http://c2.com/cgi/wiki?NullObject). * @implements paintFunction * @memberOf CellRenderer.prototype */ paint: function(gc, config) {}, /** * @desc A simple implementation of rounding a cell. * @param {CanvasRenderingContext2D} gc * @param {number} x - the x grid coordinate of my origin * @param {number} y - the y grid coordinate of my origin * @param {number} width - the width I'm allowed to draw within * @param {number} height - the height I'm allowed to draw within * @param {number} radius * @param {number} fill * @param {number} stroke * @memberOf CellRenderer.prototype */ roundRect: function(gc, x, y, width, height, radius, fill, stroke) { if (!stroke) { stroke = true; } if (!radius) { radius = 5; } gc.beginPath(); gc.moveTo(x + radius, y); gc.lineTo(x + width - radius, y); gc.quadraticCurveTo(x + width, y, x + width, y + radius); gc.lineTo(x + width, y + height - radius); gc.quadraticCurveTo(x + width, y + height, x + width - radius, y + height); gc.lineTo(x + radius, y + height); gc.quadraticCurveTo(x, y + height, x, y + height - radius); gc.lineTo(x, y + radius); gc.quadraticCurveTo(x, y, x + radius, y); gc.closePath(); if (stroke) { gc.stroke(); } if (fill) { gc.fill(); } gc.closePath(); } }); CellRenderer.abstract = true; // don't instantiate directly module.exports = CellRenderer;