UNPKG

sigma

Version:

A JavaScript library dedicated to graph drawing.

39 lines (38 loc) 1.58 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var node_1 = __importDefault(require("./node")); var label_1 = __importDefault(require("./label")); function drawHover(context, data, settings) { var size = settings.labelSize, font = settings.labelFont, weight = settings.labelWeight; context.font = weight + " " + size + "px " + font; // Then we draw the label background context.beginPath(); context.fillStyle = "#fff"; context.shadowOffsetX = 0; context.shadowOffsetY = 0; context.shadowBlur = 8; context.shadowColor = "#000"; var textWidth = context.measureText(data.label).width; var x = Math.round(data.x - size / 2 - 2), y = Math.round(data.y - size / 2 - 2), w = Math.round(textWidth + size / 2 + data.size + 9), h = Math.round(size + 4), e = Math.round(size / 2 + 2); context.moveTo(x, y + e); context.moveTo(x, y + e); context.arcTo(x, y, x + e, y, e); context.lineTo(x + w, y); context.lineTo(x + w, y + h); context.lineTo(x + e, y + h); context.arcTo(x, y + h, x, y + h - e, e); context.lineTo(x, y + e); context.closePath(); context.fill(); context.shadowOffsetX = 0; context.shadowOffsetY = 0; context.shadowBlur = 0; // Then we need to draw the node node_1.default(context, data); // And finally we draw the label label_1.default(context, data, settings); } exports.default = drawHover;