Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/d3plus.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ d3plus <- function(d, type, width = NULL, height = NULL,...) {
attributes <- args$attributes %||% NULL

if(type == "tree"){
vars <- c("id","size","color") # add vars to opts
vars <- c("id","size","color","url") # add vars to opts
data_names <- as.list(names(data))
names(data_names) <- vars[1:length(data_names)]
settings <- list(
Expand Down
27 changes: 23 additions & 4 deletions inst/htmlwidgets/d3plus.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,33 @@ HTMLWidgets.widget({
var id = x.settings.data_names.id;
var size = x.settings.data_names.size;
var color = x.settings.data_names.color;

// include legend when color supplied
var color_opt = (sample_data[0].hasOwnProperty('color')) ? true : false;

var mouse_opt;
if (sample_data[0].hasOwnProperty('url')) {
mouse_opt = {"move": false,
"over": false,
"click": function(value, viz){
window.open(value.url, '_blank');
}
};
color_opt = false; // switch off legend when using URL
} else {
mouse_opt = true; // maintain default when url missing
}

d3plus
.container("#" + vizId) // container DIV to hold the visualization
.data(sample_data) // data to use with the visualization
.type("tree_map") // visualization type
.id(id) // nesting keys
.size(size) // key name to size bubbles
.color(color)
.draw()
.mouse(mouse_opt)
.legend(color_opt) // in future, better to enable legend attribute
.draw();
}

function draw_lines(el, x, d3plus) {
Expand Down Expand Up @@ -140,7 +159,7 @@ HTMLWidgets.widget({
} else {
var text = "label"
}
var lang = x.settings.lang || "en_US"; // "zh_CN","en_US","es_ES","pt_BR"
var lang = x.settings.lang || "en_US"; // "zh_CN","en_US","es_ES","pt_BR"
var focus = x.settings.focus || false;
var showTooltip = x.settings.showTooltip;
if(!showTooltip){
Expand All @@ -164,7 +183,7 @@ HTMLWidgets.widget({
.size(vars.size)
.id(["id"])
// https://groups.google.com/forum/#!topic/d3plus/q4iXv0rpzQo
// .text("label")
// .text("label")
// .id(["group","id"])
.text(text)
.tooltip(["id", "label"])
Expand Down Expand Up @@ -201,7 +220,7 @@ HTMLWidgets.widget({
}
console.log(x.data)
var focusDropdown = x.settings.focusDropdown;
var lang = x.settings.lang || "en_US"; // "zh_CN","en_US","es_ES","pt_BR"
var lang = x.settings.lang || "en_US"; // "zh_CN","en_US","es_ES","pt_BR"
var showLegend = x.settings.showLegend || false
var ui = [];
if (focusDropdown) {
Expand Down