From 7ecae915c06e79645965f5648d11cc988e53bac5 Mon Sep 17 00:00:00 2001 From: Tyler Maclachlan Date: Thu, 19 Mar 2020 14:40:06 +0200 Subject: [PATCH 01/21] Fix: https://github.com/visjs/vis-network/issues/226 --- lib/network/modules/CanvasRenderer.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/network/modules/CanvasRenderer.js b/lib/network/modules/CanvasRenderer.js index 20f47f9178..7f0a97ce34 100644 --- a/lib/network/modules/CanvasRenderer.js +++ b/lib/network/modules/CanvasRenderer.js @@ -343,6 +343,7 @@ class CanvasRenderer { let nodeIndices = this.body.nodeIndices; let node; let selected = []; + let hovered = []; let margin = 20; let topLeft = this.canvas.DOMtoCanvas({x:-margin,y:-margin}); let bottomRight = this.canvas.DOMtoCanvas({ @@ -354,8 +355,10 @@ class CanvasRenderer { // draw unselected nodes; for (let i = 0; i < nodeIndices.length; i++) { node = nodes[nodeIndices[i]]; - // set selected nodes aside - if (node.isSelected()) { + // set selected and hovered nodes aside + if (node.hovered) { + hovered.push(nodeIndices[i]); + } else if (node.isSelected()) { selected.push(nodeIndices[i]); } else { @@ -371,11 +374,22 @@ class CanvasRenderer { } } + let i; + const selectedLength = selected.length; + const hoveredLength = hovered.length; + // draw the selected nodes on top - for (let i = 0; i < selected.length; i++) { + for (i = 0; i < selectedLength; i++) { + node = nodes[selected[i]]; + node.draw(ctx); + } + + // draw hovered nodes above everything else: fixes https://github.com/visjs/vis-network/issues/226 + for (i = 0; i < hoveredLength; i++) { node = nodes[selected[i]]; node.draw(ctx); } + } From c6d446d2faed9a3c7a8a86ea2693a044d9736c66 Mon Sep 17 00:00:00 2001 From: Tyler Maclachlan Date: Thu, 19 Mar 2020 14:40:19 +0200 Subject: [PATCH 02/21] Add opacity option to nodes --- lib/network/modules/NodesHandler.js | 1 + lib/network/modules/components/Node.js | 11 +++- .../modules/components/nodes/shapes/Image.js | 5 +- .../components/nodes/util/CircleImageBase.js | 2 +- .../modules/components/shared/Color.ts | 61 +++++++++++++++++++ lib/network/options.js | 2 + 6 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 lib/network/modules/components/shared/Color.ts diff --git a/lib/network/modules/NodesHandler.js b/lib/network/modules/NodesHandler.js index 70b9a5d88f..9086a8c592 100644 --- a/lib/network/modules/NodesHandler.js +++ b/lib/network/modules/NodesHandler.js @@ -43,6 +43,7 @@ class NodesHandler { background: '#D2E5FF' } }, + opacity: 1, // number between 0 and 1 fixed: { x: false, y: false diff --git a/lib/network/modules/components/Node.js b/lib/network/modules/components/Node.js index cd1822a954..c5339f554a 100644 --- a/lib/network/modules/components/Node.js +++ b/lib/network/modules/components/Node.js @@ -18,6 +18,7 @@ import Text from './nodes/shapes/Text'; import Triangle from './nodes/shapes/Triangle'; import TriangleDown from './nodes/shapes/TriangleDown'; import { printStyle } from "../../../shared/Validator"; +import { setColorOptionsWithOpacity } from './shared/Color'; /** @@ -45,7 +46,7 @@ class Node { * for parameter `globalOptions`. */ constructor(options, body, imagelist, grouplist, globalOptions, defaultOptions) { - this.options = util.bridgeObject(globalOptions); + this.options = {...defaultOptions, ...globalOptions, ...options}; this.globalOptions = globalOptions; this.defaultOptions = defaultOptions; this.body = body; @@ -102,6 +103,7 @@ class Node { * @returns {null|boolean} */ setOptions(options) { + let currentShape = this.options.shape; if (!options) { return; // Note that the return value will be 'undefined'! This is OK. @@ -218,6 +220,7 @@ class Node { if (!hasGroup) return; // current node has no group, no need to merge var groupObj = groupList.get(group); + groupObj.opacity = newOptions.opacity || parentOptions.opacity || 1; // Skip merging of group font options into parent; these are required to be distinct for labels // Also skip mergin of color IF it is already defined in the node itself. This is to avoid the color of the @@ -245,15 +248,16 @@ class Node { * @static */ static parseOptions(parentOptions, newOptions, allowDeletion = false, globalOptions = {}, groupList) { - var fields = [ 'color', + 'opacity', 'fixed', 'shadow' ]; util.selectiveNotDeepExtend(fields, parentOptions, newOptions, allowDeletion); Node.checkMass(newOptions); + parentOptions.opacity = newOptions.opacity || parentOptions.opacity || 1; // merge the shadow options into the parent. util.mergeOptions(parentOptions, newOptions, 'shadow', globalOptions); @@ -303,6 +307,7 @@ class Node { getFormattingValues() { let values = { color: this.options.color.background, + opacity: this.options.opacity, borderWidth: this.options.borderWidth, borderColor: this.options.color.border, size: this.options.size, @@ -340,7 +345,7 @@ class Node { } else { values.shadow = this.options.shadow.enabled; } - return values; + return setColorOptionsWithOpacity(values); } diff --git a/lib/network/modules/components/nodes/shapes/Image.js b/lib/network/modules/components/nodes/shapes/Image.js index 1aa2a9580d..349ce13cb3 100644 --- a/lib/network/modules/components/nodes/shapes/Image.js +++ b/lib/network/modules/components/nodes/shapes/Image.js @@ -1,6 +1,7 @@ 'use strict'; import CircleImageBase from '../util/CircleImageBase' +import { setColorOpacity } from '../../shared/Color'; /** @@ -69,10 +70,10 @@ class Image extends CircleImageBase { ctx.beginPath(); // setup the line properties. - ctx.strokeStyle = selected ? this.options.color.highlight.border : hover ? this.options.color.hover.border : this.options.color.border; + ctx.strokeStyle = setColorOpacity(selected ? this.options.color.highlight.border : hover ? this.options.color.hover.border : this.options.color.border, values.opacity || 1); // set a fillstyle - ctx.fillStyle = selected ? this.options.color.highlight.background : hover ? this.options.color.hover.background : this.options.color.background; + ctx.fillStyle = setColorOpacity(selected ? this.options.color.highlight.background : hover ? this.options.color.hover.background : this.options.color.background, values.opacity || 1); // draw a rectangle to form the border around. This rectangle is filled so the opacity of a picture (in future vis releases?) can be used to tint the image ctx.rect(this.left - 0.5 * ctx.lineWidth, diff --git a/lib/network/modules/components/nodes/util/CircleImageBase.js b/lib/network/modules/components/nodes/util/CircleImageBase.js index 1c0f4c82d7..cd7ba4d97c 100644 --- a/lib/network/modules/components/nodes/util/CircleImageBase.js +++ b/lib/network/modules/components/nodes/util/CircleImageBase.js @@ -170,7 +170,7 @@ class CircleImageBase extends NodeBase { _drawImageAtPosition(ctx, values) { if (this.imageObj.width != 0) { // draw the image - ctx.globalAlpha = 1.0; + ctx.globalAlpha = values.opacity; // draw shadow if enabled this.enableShadow(ctx, values); diff --git a/lib/network/modules/components/shared/Color.ts b/lib/network/modules/components/shared/Color.ts new file mode 100644 index 0000000000..8ded4ff689 --- /dev/null +++ b/lib/network/modules/components/shared/Color.ts @@ -0,0 +1,61 @@ +export function setColorOptionsWithOpacity (values: any) { + const opacity = values.opacity || 1; + if (values.color) { + values.color = setColorOpacity(values.color, opacity); + } + if (values.borderColor) { + values.borderColor = setColorOpacity(values.borderColor, opacity); + } + if (values.shadowColor) { + values.shadowColor = setColorOpacity(values.shadowColor, opacity); + } + + return values +} + + +/** + * opacity must be between 0 and 1 + */ + +export function setColorOpacity (color: string, opacity: number) { + // Make sure opacity is rounded to 2 decimal places + opacity = Math.round(opacity * 100) * 0.01; + + if (color.startsWith('rgba')) { + return setRgbaOpacity(color, opacity); + } else if (color.startsWith('#')) { + return setHexOpacity(color, opacity); + } else if (color.startsWith('rgb')) { + return setRgbOpacity(color, opacity); + } +} + +function setRgbaOpacity(rgba: string, opacity: number) { + return rgba.replace(/\d*.\d/, opacity + ''); +} + +function setHexOpacity(hex: string, opacity: number) { + const {r, g, b } = hexToRgb(hex)!; + return `rgb(${r},${g},${b},${opacity})`; +} + +function setRgbOpacity(rgb: string, opacity: number) { + return rgb.replace(')', `,${opacity})`).replace('rgb', 'rgba'); +} + + +function hexToRgb(hex: string) { + // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") + var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; + hex = hex.replace(shorthandRegex, function(m, r, g, b) { + return r + r + g + g + b + b; + }); + + var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); + return result ? { + r: parseInt(result[1], 16), + g: parseInt(result[2], 16), + b: parseInt(result[3], 16) + } : null; +} \ No newline at end of file diff --git a/lib/network/options.js b/lib/network/options.js index 14451c3750..abb66f7d3e 100644 --- a/lib/network/options.js +++ b/lib/network/options.js @@ -272,6 +272,7 @@ let allOptions = { }, __type__: { object, string } }, + opacity: { number, 'undefined': 'undefined' }, fixed: { x: { boolean: bool }, y: { boolean: bool }, @@ -520,6 +521,7 @@ let configureOptions = { background: ['color', '#D2E5FF'] } }, + opacity: 1, fixed: { x: false, y: false From a783f87e31eaaa434c567aa86b2c48a3b4916bf8 Mon Sep 17 00:00:00 2001 From: Tyler Maclachlan Date: Thu, 19 Mar 2020 15:31:07 +0200 Subject: [PATCH 03/21] Fix shadow color being mangled --- lib/network/modules/components/shared/Color.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/network/modules/components/shared/Color.ts b/lib/network/modules/components/shared/Color.ts index 8ded4ff689..7ce0558a8c 100644 --- a/lib/network/modules/components/shared/Color.ts +++ b/lib/network/modules/components/shared/Color.ts @@ -7,6 +7,7 @@ export function setColorOptionsWithOpacity (values: any) { values.borderColor = setColorOpacity(values.borderColor, opacity); } if (values.shadowColor) { + console.log(values.shadowColor); values.shadowColor = setColorOpacity(values.shadowColor, opacity); } @@ -32,7 +33,7 @@ export function setColorOpacity (color: string, opacity: number) { } function setRgbaOpacity(rgba: string, opacity: number) { - return rgba.replace(/\d*.\d/, opacity + ''); + return rgba.replace(/\d*.\d\)/, opacity + ')'); } function setHexOpacity(hex: string, opacity: number) { From 24e251f76e2e2584744aeec08e93137ff0a846f5 Mon Sep 17 00:00:00 2001 From: Tyler Maclachlan Date: Thu, 19 Mar 2020 15:33:43 +0200 Subject: [PATCH 04/21] Remove console.log --- lib/network/modules/components/shared/Color.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/network/modules/components/shared/Color.ts b/lib/network/modules/components/shared/Color.ts index 7ce0558a8c..32f8d90043 100644 --- a/lib/network/modules/components/shared/Color.ts +++ b/lib/network/modules/components/shared/Color.ts @@ -7,7 +7,6 @@ export function setColorOptionsWithOpacity (values: any) { values.borderColor = setColorOpacity(values.borderColor, opacity); } if (values.shadowColor) { - console.log(values.shadowColor); values.shadowColor = setColorOpacity(values.shadowColor, opacity); } From c8b1a9ac0581437c04313ea6c31e4fd41e6f6fa5 Mon Sep 17 00:00:00 2001 From: Tyler Maclachlan Date: Thu, 19 Mar 2020 16:13:31 +0200 Subject: [PATCH 05/21] Change to use util version of overrideOpacity --- lib/network/modules/components/Node.js | 12 +++- .../modules/components/nodes/shapes/Image.js | 13 ++-- .../modules/components/shared/Color.ts | 61 ------------------- lib/network/options.js | 2 +- 4 files changed, 19 insertions(+), 69 deletions(-) delete mode 100644 lib/network/modules/components/shared/Color.ts diff --git a/lib/network/modules/components/Node.js b/lib/network/modules/components/Node.js index c5339f554a..c38850b4a2 100644 --- a/lib/network/modules/components/Node.js +++ b/lib/network/modules/components/Node.js @@ -18,7 +18,6 @@ import Text from './nodes/shapes/Text'; import Triangle from './nodes/shapes/Triangle'; import TriangleDown from './nodes/shapes/TriangleDown'; import { printStyle } from "../../../shared/Validator"; -import { setColorOptionsWithOpacity } from './shared/Color'; /** @@ -46,7 +45,7 @@ class Node { * for parameter `globalOptions`. */ constructor(options, body, imagelist, grouplist, globalOptions, defaultOptions) { - this.options = {...defaultOptions, ...globalOptions, ...options}; + this.options = util.bridgeObject(globalOptions); this.globalOptions = globalOptions; this.defaultOptions = defaultOptions; this.body = body; @@ -345,7 +344,14 @@ class Node { } else { values.shadow = this.options.shadow.enabled; } - return setColorOptionsWithOpacity(values); + if (this.options.opacity) { + const opacity = this.options.opacity; + values.borderColor = util.overrideOpacity(values.borderColor, opacity); + values.color = util.overrideOpacity(values.color, opacity); + values.shadowColor = util.overrideOpacity(values.shadowColor, opacity); + } + + return values; } diff --git a/lib/network/modules/components/nodes/shapes/Image.js b/lib/network/modules/components/nodes/shapes/Image.js index 349ce13cb3..c03d1bd601 100644 --- a/lib/network/modules/components/nodes/shapes/Image.js +++ b/lib/network/modules/components/nodes/shapes/Image.js @@ -1,8 +1,7 @@ 'use strict'; import CircleImageBase from '../util/CircleImageBase' -import { setColorOpacity } from '../../shared/Color'; - +import * as util from 'vis-util/esnext'; /** * An image-based replacement for the default Node shape. @@ -68,12 +67,18 @@ class Image extends CircleImageBase { ctx.lineWidth = Math.min(this.width, borderWidth); ctx.beginPath(); + let strokeStyle = selected ? this.options.color.highlight.border : hover ? this.options.color.hover.border : this.options.color.border; + let fillStyle = selected ? this.options.color.highlight.background : hover ? this.options.color.hover.background : this.options.color.background; + if (values.opacity) { + strokeStyle = util.overrideOpacity(strokeStyle, values.opacity); + fillStyle = util.overrideOpacity(fillStyle, values.opacity); + } // setup the line properties. - ctx.strokeStyle = setColorOpacity(selected ? this.options.color.highlight.border : hover ? this.options.color.hover.border : this.options.color.border, values.opacity || 1); + ctx.strokeStyle = strokeStyle; // set a fillstyle - ctx.fillStyle = setColorOpacity(selected ? this.options.color.highlight.background : hover ? this.options.color.hover.background : this.options.color.background, values.opacity || 1); + ctx.fillStyle = fillStyle; // draw a rectangle to form the border around. This rectangle is filled so the opacity of a picture (in future vis releases?) can be used to tint the image ctx.rect(this.left - 0.5 * ctx.lineWidth, diff --git a/lib/network/modules/components/shared/Color.ts b/lib/network/modules/components/shared/Color.ts deleted file mode 100644 index 32f8d90043..0000000000 --- a/lib/network/modules/components/shared/Color.ts +++ /dev/null @@ -1,61 +0,0 @@ -export function setColorOptionsWithOpacity (values: any) { - const opacity = values.opacity || 1; - if (values.color) { - values.color = setColorOpacity(values.color, opacity); - } - if (values.borderColor) { - values.borderColor = setColorOpacity(values.borderColor, opacity); - } - if (values.shadowColor) { - values.shadowColor = setColorOpacity(values.shadowColor, opacity); - } - - return values -} - - -/** - * opacity must be between 0 and 1 - */ - -export function setColorOpacity (color: string, opacity: number) { - // Make sure opacity is rounded to 2 decimal places - opacity = Math.round(opacity * 100) * 0.01; - - if (color.startsWith('rgba')) { - return setRgbaOpacity(color, opacity); - } else if (color.startsWith('#')) { - return setHexOpacity(color, opacity); - } else if (color.startsWith('rgb')) { - return setRgbOpacity(color, opacity); - } -} - -function setRgbaOpacity(rgba: string, opacity: number) { - return rgba.replace(/\d*.\d\)/, opacity + ')'); -} - -function setHexOpacity(hex: string, opacity: number) { - const {r, g, b } = hexToRgb(hex)!; - return `rgb(${r},${g},${b},${opacity})`; -} - -function setRgbOpacity(rgb: string, opacity: number) { - return rgb.replace(')', `,${opacity})`).replace('rgb', 'rgba'); -} - - -function hexToRgb(hex: string) { - // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") - var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; - hex = hex.replace(shorthandRegex, function(m, r, g, b) { - return r + r + g + g + b + b; - }); - - var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); - return result ? { - r: parseInt(result[1], 16), - g: parseInt(result[2], 16), - b: parseInt(result[3], 16) - } : null; -} \ No newline at end of file diff --git a/lib/network/options.js b/lib/network/options.js index abb66f7d3e..46e788f473 100644 --- a/lib/network/options.js +++ b/lib/network/options.js @@ -521,7 +521,7 @@ let configureOptions = { background: ['color', '#D2E5FF'] } }, - opacity: 1, + opacity: [0, 0, 1, 0.1], fixed: { x: false, y: false From 1e06b9c32197b160ef70e2659a0cc8f9f9cefbad Mon Sep 17 00:00:00 2001 From: Tyler Maclachlan Date: Fri, 20 Mar 2020 00:55:19 +0200 Subject: [PATCH 06/21] Fix updating groups instead of node Change import to only import overrideOpacity --- lib/network/modules/NodesHandler.js | 6 +++++- lib/network/modules/components/Node.js | 6 +++--- lib/network/modules/components/nodes/shapes/Image.js | 6 +++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/network/modules/NodesHandler.js b/lib/network/modules/NodesHandler.js index 9086a8c592..4b40b47852 100644 --- a/lib/network/modules/NodesHandler.js +++ b/lib/network/modules/NodesHandler.js @@ -43,7 +43,7 @@ class NodesHandler { background: '#D2E5FF' } }, - opacity: 1, // number between 0 and 1 + opacity: undefined, // number between 0 and 1 fixed: { x: false, y: false @@ -179,6 +179,10 @@ class NodesHandler { setOptions(options) { if (options !== undefined) { Node.parseOptions(this.options, options); + + if (options.opacity) { + this.options.opacity = options.opacity; + } // update the shape in all nodes if (options.shape !== undefined) { diff --git a/lib/network/modules/components/Node.js b/lib/network/modules/components/Node.js index c38850b4a2..ecfd0f1685 100644 --- a/lib/network/modules/components/Node.js +++ b/lib/network/modules/components/Node.js @@ -102,7 +102,6 @@ class Node { * @returns {null|boolean} */ setOptions(options) { - let currentShape = this.options.shape; if (!options) { return; // Note that the return value will be 'undefined'! This is OK. @@ -219,7 +218,6 @@ class Node { if (!hasGroup) return; // current node has no group, no need to merge var groupObj = groupList.get(group); - groupObj.opacity = newOptions.opacity || parentOptions.opacity || 1; // Skip merging of group font options into parent; these are required to be distinct for labels // Also skip mergin of color IF it is already defined in the node itself. This is to avoid the color of the @@ -256,7 +254,9 @@ class Node { util.selectiveNotDeepExtend(fields, parentOptions, newOptions, allowDeletion); Node.checkMass(newOptions); - parentOptions.opacity = newOptions.opacity || parentOptions.opacity || 1; + if (globalOptions.opacity) { + newOptions.opacity = globalOptions.opacity; + } // merge the shadow options into the parent. util.mergeOptions(parentOptions, newOptions, 'shadow', globalOptions); diff --git a/lib/network/modules/components/nodes/shapes/Image.js b/lib/network/modules/components/nodes/shapes/Image.js index c03d1bd601..d58efca33c 100644 --- a/lib/network/modules/components/nodes/shapes/Image.js +++ b/lib/network/modules/components/nodes/shapes/Image.js @@ -1,7 +1,7 @@ 'use strict'; import CircleImageBase from '../util/CircleImageBase' -import * as util from 'vis-util/esnext'; +import { overrideOpacity } from 'vis-util/esnext'; /** * An image-based replacement for the default Node shape. @@ -71,8 +71,8 @@ class Image extends CircleImageBase { let fillStyle = selected ? this.options.color.highlight.background : hover ? this.options.color.hover.background : this.options.color.background; if (values.opacity) { - strokeStyle = util.overrideOpacity(strokeStyle, values.opacity); - fillStyle = util.overrideOpacity(fillStyle, values.opacity); + strokeStyle = overrideOpacity(strokeStyle, values.opacity); + fillStyle = overrideOpacity(fillStyle, values.opacity); } // setup the line properties. ctx.strokeStyle = strokeStyle; From 9614ea894cf35f3efed171d604407f391028453e Mon Sep 17 00:00:00 2001 From: Tyler Maclachlan Date: Fri, 20 Mar 2020 01:07:30 +0200 Subject: [PATCH 07/21] Fix local opacity not being applied --- .../network/nodeStyles/imagesWithOpacity.html | 85 +++++++++++++++++++ lib/network/modules/components/Node.js | 6 +- 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 examples/network/nodeStyles/imagesWithOpacity.html diff --git a/examples/network/nodeStyles/imagesWithOpacity.html b/examples/network/nodeStyles/imagesWithOpacity.html new file mode 100644 index 0000000000..f9afd15a5a --- /dev/null +++ b/examples/network/nodeStyles/imagesWithOpacity.html @@ -0,0 +1,85 @@ + + + + Vis Network | Node Styles | Images + + + + + + + + + + +

+ Display nodes as images. +

+
+ + + diff --git a/lib/network/modules/components/Node.js b/lib/network/modules/components/Node.js index ecfd0f1685..9fd0c5de54 100644 --- a/lib/network/modules/components/Node.js +++ b/lib/network/modules/components/Node.js @@ -140,6 +140,10 @@ class Node { // this transforms all shorthands into fully defined options Node.parseOptions(this.options, options, true, this.globalOptions, this.grouplist); + if (options.opacity !== undefined) { + this.options.opacity = options.opacity; + } + let pile = [options, this.options, this.defaultOptions]; this.chooser = ComponentUtil.choosify('node', pile); @@ -254,7 +258,7 @@ class Node { util.selectiveNotDeepExtend(fields, parentOptions, newOptions, allowDeletion); Node.checkMass(newOptions); - if (globalOptions.opacity) { + if (globalOptions.opacity && newOptions.opacity === undefined) { newOptions.opacity = globalOptions.opacity; } From b85caaa58e3f2bddd3d1fbafd5aa8d99e979e6fa Mon Sep 17 00:00:00 2001 From: Tyler Maclachlan Date: Fri, 20 Mar 2020 10:54:58 +0200 Subject: [PATCH 08/21] Fix wrong property name --- lib/network/modules/CanvasRenderer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/network/modules/CanvasRenderer.js b/lib/network/modules/CanvasRenderer.js index 7f0a97ce34..7663e47b1f 100644 --- a/lib/network/modules/CanvasRenderer.js +++ b/lib/network/modules/CanvasRenderer.js @@ -356,7 +356,7 @@ class CanvasRenderer { for (let i = 0; i < nodeIndices.length; i++) { node = nodes[nodeIndices[i]]; // set selected and hovered nodes aside - if (node.hovered) { + if (node.hover) { hovered.push(nodeIndices[i]); } else if (node.isSelected()) { selected.push(nodeIndices[i]); From a685dd2652a2ea5c035624389734d04c0d0b369f Mon Sep 17 00:00:00 2001 From: Tyler Maclachlan Date: Fri, 20 Mar 2020 10:55:49 +0200 Subject: [PATCH 09/21] Fix drawing selected instead of hovered --- lib/network/modules/CanvasRenderer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/network/modules/CanvasRenderer.js b/lib/network/modules/CanvasRenderer.js index 7663e47b1f..802f31e396 100644 --- a/lib/network/modules/CanvasRenderer.js +++ b/lib/network/modules/CanvasRenderer.js @@ -386,7 +386,7 @@ class CanvasRenderer { // draw hovered nodes above everything else: fixes https://github.com/visjs/vis-network/issues/226 for (i = 0; i < hoveredLength; i++) { - node = nodes[selected[i]]; + node = nodes[hovered[i]]; node.draw(ctx); } From fcc0956fe2df06268323fde08b3577d7dd88edcf Mon Sep 17 00:00:00 2001 From: Tyler Maclachlan Date: Fri, 20 Mar 2020 10:57:49 +0200 Subject: [PATCH 10/21] Update example --- examples/network/nodeStyles/imagesWithOpacity.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/network/nodeStyles/imagesWithOpacity.html b/examples/network/nodeStyles/imagesWithOpacity.html index f9afd15a5a..a7b6e0da91 100644 --- a/examples/network/nodeStyles/imagesWithOpacity.html +++ b/examples/network/nodeStyles/imagesWithOpacity.html @@ -1,7 +1,7 @@ - Vis Network | Node Styles | Images + Vis Network | Node Styles | Images with Opacity