Skip to content

Commit b0babbd

Browse files
cmreigrutbocytko
authored andcommitted
Cleanup/enhancenments to links
This changes a few things about links: 1. Links are now always enabled for blips Previously, it was only enabled for blips if there is no legend (config.print_layout = true) 2. hrefs are only added if there is actually a link Previously, there were always href created--if there was no link, the href was #. This caused a page refresh and a blink of the tech radar. 3. Use xlink:href everywhere Previously, blips used xlink:href, but text still used href. xlink:href has actually been deprecated, but currently still has better cross-platform support. 4. Links can now open in new tabs Previously, links always opened in the existing tab. This adds a new config: links_in_new_tabs. Setting that to true will add a target="_blank" for all hrefs, causing the link to be opened in a new tab. Setting config.links_in_new_tabs to false or not including it at all retains the old behavior.
1 parent 6d1db5f commit b0babbd

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

docs/radar.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,14 @@ function radar_visualization(config) {
306306
.data(segmented[quadrant][ring])
307307
.enter()
308308
.append("a")
309-
.attr("href", function (d, i) {
310-
return d.link ? d.link : "#"; // stay on same page if no link was provided
311-
})
309+
// Add an href if (and only if) there is a link
310+
.attr("href", function (d, i) {
311+
return d.link ? d.link : null;
312+
})
313+
// Add a target if (and only if) there is a link and we want new tabs
314+
.attr("target", function (d, i) {
315+
return (d.link && config.links_in_new_tabs) ? "_blank" : null;
316+
})
312317
.append("text")
313318
.attr("transform", function(d, i) { return legend_transform(quadrant, ring, i); })
314319
.attr("class", "legend" + quadrant + ring)
@@ -397,9 +402,13 @@ function radar_visualization(config) {
397402
var blip = d3.select(this);
398403

399404
// blip link
400-
if (!config.print_layout && d.active && d.hasOwnProperty("link")) {
405+
if (d.active && d.hasOwnProperty("link") && d.link) {
401406
blip = blip.append("a")
402407
.attr("xlink:href", d.link);
408+
409+
if (config.links_in_new_tabs) {
410+
blip.attr("target", "_blank");
411+
}
403412
}
404413

405414
// blip shape

0 commit comments

Comments
 (0)