12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- ;(function() {
- 'use strict';
- sigma.utils.pkg('sigma.canvas.edgehovers');
- /**
- * This hover renderer will display the edge with a different color or size.
- *
- * @param {object} edge The edge object.
- * @param {object} source node The edge source node.
- * @param {object} target node The edge target node.
- * @param {CanvasRenderingContext2D} context The canvas context.
- * @param {configurable} settings The settings function.
- */
- sigma.canvas.edgehovers.dashed =
- function(edge, source, target, context, settings) {
- var color = edge.active ?
- edge.active_color || settings('defaultEdgeActiveColor') :
- edge.color,
- prefix = settings('prefix') || '',
- size = edge[prefix + 'size'] || 1,
- edgeColor = settings('edgeColor'),
- defaultNodeColor = settings('defaultNodeColor'),
- defaultEdgeColor = settings('defaultEdgeColor');
- if (!color)
- switch (edgeColor) {
- case 'source':
- color = source.color || defaultNodeColor;
- break;
- case 'target':
- color = target.color || defaultNodeColor;
- break;
- default:
- color = defaultEdgeColor;
- break;
- }
- if (settings('edgeHoverColor') === 'edge') {
- color = edge.hover_color || color;
- } else {
- color = edge.hover_color || settings('defaultEdgeHoverColor') || color;
- }
- size *= settings('edgeHoverSizeRatio');
- context.save();
- context.setLineDash([8,3]);
- context.strokeStyle = color;
- context.lineWidth = size;
- context.beginPath();
- context.moveTo(
- source[prefix + 'x'],
- source[prefix + 'y']
- );
- context.lineTo(
- target[prefix + 'x'],
- target[prefix + 'y']
- );
- context.stroke();
- context.restore();
- };
- })();
|