// o---------------------------------------------------------------------------------o // | This file is part of the RGraph package - you can learn more at: | // | | // | https://www.rgraph.net/license.html | // | | // | RGraph is dual-licensed under the Open Source GPL license. That means that it's | // | free to use and there are no restrictions on what you can use RGraph for! | // | If the GPL license does not suit you however, then there's an inexpensive | // | commercial license option available. See the URL above for more details. | // o---------------------------------------------------------------------------------o RGraph = window.RGraph || {isrgraph:true,isRGraph: true,rgraph:true}; RGraph.HTML = RGraph.HTML || {}; // Module pattern (function (win, doc, undefined) { // // Draws the graph key (used by various graphs) // RGraph.drawKey = function () { var args = RGraph.getArgs(arguments, 'object,key,colors'); if (!args.key) { return; } var prop = args.object.properties, properties = args.object.properties, // Key positioned in the margin keypos = properties.keyPosition, textsize = properties.textSize, key_non_null = [], colors_non_null = []; args.object.context.lineWidth = 1; args.object.context.beginPath(); // // Change the older keyVpos to keyPositionY // if (typeof properties.keyVpos == 'number') { args.object.set('keyPositionY', properties.keyVpos * args.object.get('marginTop')); } // Account for the key now (March 2023) being able to be // a string if (RGraph.isString(args.key)) { var len = 0; if (RGraph.isNumber(args.object.properties.keyFormattedItemsCount)) { len = args.object.properties.keyFormattedItemsCount; } else { len = args.object.getKeyNumDatapoints(); } args.key = (new Array(len)).fill(args.key); } // // Account for null values in the key // for (var i=0; i=0; i--) { var j = Number(i) + 1; // // Draw the blob of color // // An array element, string if (typeof properties.keyColorShape === 'object' && typeof properties.keyColorShape[i] === 'string') { var blob_shape = properties.keyColorShape[i]; // An array element, function } else if (typeof properties.keyColorShape === 'object' && typeof properties.keyColorShape[i] === 'function') { var blob_shape = properties.keyColorShape[i]; // No array - just a string } else if (typeof properties.keyColorShape === 'string') { var blob_shape = properties.keyColorShape; // No array - just a function } else if (typeof properties.keyColorShape === 'function') { var blob_shape = properties.keyColorShape; // Unknown } else { var blob_shape = 'rect'; } if (blob_shape == 'circle') { args.object.context.beginPath(); args.object.context.fillStyle = colors[i]; args.object.context.arc(hpos + 5 + (blob_size / 2), vpos + (5 * j) + (text_size * j) - text_size + (blob_size / 2), blob_size / 2, 0, 6.26, 0); args.object.context.fill(); } else if (blob_shape == 'line') { args.object.context.beginPath(); args.object.context.strokeStyle = colors[i]; args.object.context.moveTo(hpos + 5, vpos + (5 * j) + (text_size * j) - text_size + (blob_size / 2)); args.object.context.lineTo(hpos + blob_size + 5, vpos + (5 * j) + (text_size * j) - text_size + (blob_size / 2)); args.object.context.stroke(); } else if (blob_shape == 'triangle') { args.object.context.beginPath(); args.object.context.strokeStyle = colors[i]; args.object.context.moveTo(hpos + 5, vpos + (5 * j) + (text_size * j) - text_size + blob_size); args.object.context.lineTo(hpos + (blob_size / 2) + 5, vpos + (5 * j) + (text_size * j) - text_size ); args.object.context.lineTo(hpos + blob_size + 5, vpos + (5 * j) + (text_size * j) - text_size + blob_size); args.object.context.closePath(); args.object.context.fillStyle = colors[i]; args.object.context.fill(); } else if (typeof blob_shape === 'function') { blob_shape({ object: args.object, color: colors[i], x: hpos + 5, y: vpos + (5 * j) + (text_size * j) - text_size, width: text_size, height: text_size + 1 }); } else { args.object.context.fillStyle = colors[i]; args.object.context.fillRect( hpos + 5, vpos + (5 * j) + (text_size * j) - text_size, text_size, text_size + 1 ); } /////////////////////////////////////////////////////////////////////////////////////////////////////////// args.object.context.beginPath(); //args.object.context.fillStyle = typeof text_color == 'object' ? text_color[i] : text_color; ret = RGraph.text({ object: args.object, font: textConf.font, size: textConf.size, bold: textConf.bold, italic: textConf.italic, color: typeof textConf.color == 'object' ? textConf.color[i] : textConf.color, x: hpos + blob_size + 5 + 5 + (properties.keyLabelsOffsetx || 0), y: vpos + (5 * j) + (text_size * j) + 3 + (properties.keyLabelsOffsety || 0), text: key[i], accessible: textAccessible }); args.object.coords.key[i] = [ ret.x, ret.y, ret.width, ret.height, key[i], colors[i], args.object ]; } args.object.context.fill(); } // // This does the actual drawing of the key when it's in the margin // var drawKey_margin = function () { var text_size = typeof properties.keyLabelsSize == 'number' ? properties.keyLabelsSize : properties.textSize, text_bold = properties.keyLabelsBold, text_italic = properties.keyLabelsItalic, text_font = properties.keyLabelsFont || properties.keyFont || properties.textFont, text_color = properties.keyLabelsColor || properties.textColor, marginLeft = args.object.marginLeft, marginRight = args.object.marginRight, marginTop = args.object.marginTop, marginBottom = args.object.marginBottom, hpos = ((args.object.canvas.width - marginLeft - marginRight) / 2) + args.object.marginLeft, vpos = marginTop - text_size - 5, title = properties.title, blob_size = text_size, // The blob of color hmargin = 8, // This is the size of the gaps between the blob of color and the text vmargin = 4, // This is the vertical margin of the key fillstyle = properties.keyBackground, strokestyle = '#999', length = 0; if (!args.object.coords) { args.object.coords = {}; } args.object.coords.key = []; // Need to work out the length of the key first args.object.context.font = (args.object.properties.keyLabelsItalic ? 'italic ' : '') + (args.object.properties.keyLabelsBold ? 'bold ' : '') + text_size + 'pt ' + text_font; for (i=0; i'; // // // Add the individual key elements // for (var i=0; i ' + (properties.links && properties.links[i] ? '' : '') + '' + properties.labels[i] + '' + (properties.links && properties.links[i] ? '' : '') + ''; } div.innerHTML += (str + ''); for (var i=0; i