From fcb11b002456f2e522b0644d7df09a19332f7c96 Mon Sep 17 00:00:00 2001 From: timelyportfolio Date: Mon, 26 Feb 2018 19:38:41 -0600 Subject: [PATCH] fix bug to not duplicate breadcrumb trail --- inst/htmlwidgets/sunburst.js | 15 +++++++++++---- javascript/src/sunburst-chart.js | 17 ++++++++++++----- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/inst/htmlwidgets/sunburst.js b/inst/htmlwidgets/sunburst.js index 7590d37..abe692b 100644 --- a/inst/htmlwidgets/sunburst.js +++ b/inst/htmlwidgets/sunburst.js @@ -307,12 +307,19 @@ function draw (el, instance, dispatch_) { function initializeBreadcrumbTrail() { // Add the svg area. - var trail = d3Selection.select(el).select(".sunburst-sequence").append("svg") - .attr("width", width) - //.attr("height", 50) + var trail = d3Selection.select(el).select(".sunburst-sequence").select("svg"); + if(trail.nodes().length === 0) { + trail = d3Selection.select(el).select(".sunburst-sequence").append("svg") .attr("id", el.id + "-trail"); + trail.append("text"); + } + + trail + .attr("width", width); + //.attr("height", 50) + // Add the label at the end, for the percentage. - trail.append("text") + trail.select("text") .attr("id", el.id + "-endlabel") .style("fill", "#000"); } diff --git a/javascript/src/sunburst-chart.js b/javascript/src/sunburst-chart.js index a62a893..1267904 100644 --- a/javascript/src/sunburst-chart.js +++ b/javascript/src/sunburst-chart.js @@ -304,12 +304,19 @@ export default function (el, instance, dispatch_) { function initializeBreadcrumbTrail() { // Add the svg area. - var trail = select(el).select(".sunburst-sequence").append("svg") - .attr("width", width) - //.attr("height", 50) - .attr("id", el.id + "-trail"); + var trail = select(el).select(".sunburst-sequence").select("svg") + if(trail.nodes().length === 0) { + trail = select(el).select(".sunburst-sequence").append("svg") + .attr("id", el.id + "-trail") + trail.append("text") + } + + trail + .attr("width", width); + //.attr("height", 50) + // Add the label at the end, for the percentage. - trail.append("text") + trail.select("text") .attr("id", el.id + "-endlabel") .style("fill", "#000"); }