Skip to content

Commit

Permalink
# Support for 8.12 and improved visual styles (#40)
Browse files Browse the repository at this point in the history
Added percentage to hover tooltips, in nodes and links
Removed node strokes borders
Highlight the set of links coming from a node

Co-authored-by: Oscar Quinde <oscar@plugthem.social>
  • Loading branch information
skarjoss and Oscar Quinde authored Feb 23, 2024
1 parent 118781a commit 5f2d316
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kbn-sankey-vis",
"version": "8.8.9",
"version": "8.12.1",
"kibana": {
"version": "kibana"
},
Expand All @@ -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",
Expand Down
34 changes: 29 additions & 5 deletions public/legacy/sankey_vis_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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) {
Expand All @@ -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')
Expand Down

0 comments on commit 5f2d316

Please sign in to comment.