// version: 2017-11-25 /** * o--------------------------------------------------------------------------------o * | This file is part of the RGraph package - you can learn more at: | * | | * | http://www.rgraph.net | * | | * | RGraph is licensed under the Open Source MIT license. That means that it's | * | totally free to use and there are no restrictions on what you can do with it! | * o--------------------------------------------------------------------------------o */ RGraph = window.RGraph || {isRGraph: true}; // Module pattern (function (win, doc, undefined) { var RG = RGraph, ua = navigator.userAgent, ma = Math; /** * This is a useful function which is basically a shortcut for drawing left, right, top and bottom alligned text. * * @param object context The context * @param string font The font * @param int size The size of the text * @param int x The X coordinate * @param int y The Y coordinate * @param string text The text to draw * @parm string The vertical alignment. Can be null. "center" gives center aligned text, "top" gives top aligned text. * Anything else produces bottom aligned text. Default is bottom. * @param string The horizontal alignment. Can be null. "center" gives center aligned text, "right" gives right aligned text. * Anything else produces left aligned text. Default is left. * @param bool Whether to show a bounding box around the text. Defaults not to * @param int The angle that the text should be rotate at (IN DEGREES) * @param string Background color for the text * @param bool Whether the text is bold or not */ RG.text = RG.Text = function (context, font, size, x, y, text) { // "Cache" the args as a local variable var args = arguments; // Handle undefined - change it to an empty string if ((typeof(text) != 'string' && typeof(text) != 'number') || text == 'undefined') { return; } /** * This accommodates multi-line text */ if (typeof(text) == 'string' && text.match(/\r\n/)) { var dimensions = RGraph.MeasureText('M', args[11], font, size); /** * Measure the text (width and height) */ var arr = text.split('\r\n'); /** * Adjust the Y position */ // This adjusts the initial y position if (args[6] && args[6] == 'center') y = (y - (dimensions[1] * ((arr.length - 1) / 2))); for (var i=1; i