From 2f333f2202962457b2bccfa297faa00777551c37 Mon Sep 17 00:00:00 2001 From: Oscar Quinde Date: Fri, 23 Feb 2024 02:53:18 -0500 Subject: [PATCH 1/2] # Support for 8.12 and improved visual styles Added percentage to hover tooltips, in nodes and links Removed node strokes borders Highlight the set of links coming from a node --- package.json | 6 +++-- public/legacy/sankey_vis_controller.js | 34 ++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index f48fb71..fb4042f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kbn-sankey-vis", - "version": "8.8.9", + "version": "8.12.1", "kibana": { "version": "kibana" }, @@ -21,7 +21,9 @@ "test": "nyc --all mocha", "build": "node ../../scripts/plugin_helpers.js build", "compile-and-build": "node ../../scripts/plugin_helpers.js build", - "compile": "rm -rf ./target && export NODE_OPTIONS=--openssl-legacy-provider && node ../../scripts/plugin_helpers.js build --kibana-version none --skip-archive && mv build/kibana/kbnSankeyVis/target . && rm -rf build/*" + "compile": "rm -rf ./target && export NODE_OPTIONS=--openssl-legacy-provider && node ../../scripts/plugin_helpers.js build --kibana-version none --skip-archive && mv build/kibana/kbnSankeyVis/target . && rm -rf build/*", + "plugin-helpers": "node ../../scripts/plugin_helpers", + "dev": "yarn plugin-helpers dev" }, "dependencies": { "angular": "^1.8.0", diff --git a/public/legacy/sankey_vis_controller.js b/public/legacy/sankey_vis_controller.js index c71d839..bc0530e 100644 --- a/public/legacy/sankey_vis_controller.js +++ b/public/legacy/sankey_vis_controller.js @@ -81,7 +81,15 @@ function KbnSankeyVisController($scope, $element, config) { link.append('title') .text(function (d) { - return d.source.name + ' → ' + d.target.name + '\n' + d.value; + return d.source.name + ' → ' + d.target.name + '\n' + d.value + ' ('+(Math.round(d.value/d.source.value * 1000) / 10).toFixed(1)+'%)'; + }); + + // OQMod, gets total of source nodes + var total = d3.sum(energy.nodes, function(d) { + if (d.targetLinks.length>0) + return 0; //node is not source, exclude it from the total + else + return d.value; //node is a source: add its value to the sum }); let node = svg.append('g').selectAll('.node') @@ -98,7 +106,22 @@ function KbnSankeyVisController($scope, $element, config) { .on('dragstart', function () { this.parentNode.appendChild(this); }) - .on('drag', dragmove)); + .on('drag', dragmove)) + // OQMod: Highlight the set of links coming from a node + .on("mouseover", function(d) { + link + .transition() + .duration(300) + .style("stroke-opacity", function(l) { + return l.source === d || l.target === d ? 0.5 : 0.2; + }); + }) + .on("mouseleave", function(d) { + link + .transition() + .duration(300) + .style("stroke-opacity", 0.2); + }); node.append('rect') .attr('height', function (d) { @@ -109,12 +132,13 @@ function KbnSankeyVisController($scope, $element, config) { d.color = color(d.name); return d.color; }) - .style('stroke', function (d) { + .attr("rx", 2) // OQMod: Rounded all corners + /*.style('stroke', function (d) { return getConfig('theme:darkMode') ? d3.rgb(d.color).brighter(2) : d3.rgb(d.color).darker(2); - }) + })*/ // OQMod: Hide stroke border .append('title') .text(function (d) { - return d.name + '\n' + d.value; + return d.name + '\n' + d.value + ' ('+(Math.round(d.value/total * 1000) / 10).toFixed(1)+'%)'; }); node.append('text') From 3320973a203f4af84fb39da8090a8ddb551fe145 Mon Sep 17 00:00:00 2001 From: Oscar Quinde Date: Mon, 10 Jun 2024 16:36:55 -0500 Subject: [PATCH 2/2] # Support for 8.14.0 --- package.json | 2 +- public/legacy/sankey_vis_controller.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index fb4042f..15c6675 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kbn-sankey-vis", - "version": "8.12.1", + "version": "8.14.0", "kibana": { "version": "kibana" }, diff --git a/public/legacy/sankey_vis_controller.js b/public/legacy/sankey_vis_controller.js index bc0530e..bd55e78 100644 --- a/public/legacy/sankey_vis_controller.js +++ b/public/legacy/sankey_vis_controller.js @@ -19,6 +19,7 @@ function KbnSankeyVisController($scope, $element, config) { * - one of the view options changes (vis.params) */ const getConfig = (...args) => config.get(...args); + let darkMode = getConfig('theme:darkMode'); const lightTextColor = "#CBCFCB"; const darkTextColor = "#000000"; let svgRoot = $element[0]; @@ -147,7 +148,7 @@ function KbnSankeyVisController($scope, $element, config) { return d.dy / 2; }) .attr('dy', '.35em') - .style('fill', getConfig('theme:darkMode') ? lightTextColor : darkTextColor) + .style('fill', darkMode === 'enabled' || darkMode === true ? lightTextColor : darkTextColor) .attr('text-anchor', 'end') .attr('transform', null) .text(function (d) {