var DEFAULT_RENDER_PRIORITY = 1000; /** * @typedef {import('../model').Base} Base * @typedef {import('../model').Connection} Connection * @typedef {import('../model').Shape} Shape * * @typedef {import('../core/EventBus').default} EventBus */ /** * The base implementation of shape and connection renderers. * * @param {EventBus} eventBus * @param {number} [renderPriority=1000] */ export default function BaseRenderer(eventBus, renderPriority) { var self = this; renderPriority = renderPriority || DEFAULT_RENDER_PRIORITY; eventBus.on([ 'render.shape', 'render.connection' ], renderPriority, function(evt, context) { var type = evt.type, element = context.element, visuals = context.gfx, attrs = context.attrs; if (self.canRender(element)) { if (type === 'render.shape') { return self.drawShape(visuals, element, attrs); } else { return self.drawConnection(visuals, element, attrs); } } }); eventBus.on([ 'render.getShapePath', 'render.getConnectionPath' ], renderPriority, function(evt, element) { if (self.canRender(element)) { if (evt.type === 'render.getShapePath') { return self.getShapePath(element); } else { return self.getConnectionPath(element); } } }); } /** * Checks whether an element can be rendered. * * @param {Base} element The element to be rendered. * * @returns {boolean} Whether the element can be rendered. */ BaseRenderer.prototype.canRender = function(element) {}; /** * Draws a shape. * * @param {SVGElement} visuals The SVG element to draw the shape into. * @param {Shape} shape The shape to be drawn. * * @returns {SVGElement} The SVG element of the shape drawn. */ BaseRenderer.prototype.drawShape = function(visuals, shape) {}; /** * Draws a connection. * * @param {SVGElement} visuals The SVG element to draw the connection into. * @param {Connection} connection The connection to be drawn. * * @returns {SVGElement} The SVG element of the connection drawn. */ BaseRenderer.prototype.drawConnection = function(visuals, connection) {}; /** * Gets the SVG path of the graphical representation of a shape. * * @param {Shape} shape The shape. * * @return {string} The SVG path of the shape. */ BaseRenderer.prototype.getShapePath = function(shape) {}; /** * Gets the SVG path of the graphical representation of a connection. * * @param {Connection} connection The connection. * * @return {string} The SVG path of the connection. */ BaseRenderer.prototype.getConnectionPath = function(connection) {};