Skip to content

Commit

Permalink
code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mblackstock committed Dec 30, 2020
1 parent 683eed2 commit ce5e403
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions dataview.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,30 +128,29 @@
});

// array of all data for each node
const latestData = {}
const latestData = {};
// ui state and functions for updates
const chartInfo = {}
const chartInfo = {};

var remove = function(id) {
const $chart = document.getElementById(`data-view-output-chart-${id}`)
const $bubble = document.getElementById(`data-view-output-bubble-${id}`)
const $chart = document.getElementById(`data-view-output-chart-${id}`);
const $bubble = document.getElementById(`data-view-output-bubble-${id}`);

$chart && $chart.remove()
$bubble && $bubble.remove()
$chart && $chart.remove();
$bubble && $bubble.remove();
}

var reset = function (id) {
remove(id)

delete latestData[id]
delete chartInfo[id]
delete latestData[id];
delete chartInfo[id];
}

var redraw = function (node) {
let id = node.id
remove(id);
if (latestData[id] && (node.active || !node.hide)) {
render(id, latestData[id], node)
render(id, latestData[id], node);
}
}

Expand Down Expand Up @@ -235,17 +234,17 @@
.attr("class", "y axis")
.call(yAxis);

$chart = chartGroup
let previousWidth = chartWidth;

// save for updates to the chart
chartInfo[id] = { xScale, yScale, xAxis, yAxis, valueLine, previousWidth };

d3chart.selectAll(".axis line")
.style(AXIS_STYLE);

d3chart.selectAll(".axis path")
.style(AXIS_STYLE);

$chart = chartGroup
let previousWidth = chartWidth;

// save for updates to the chart
chartInfo[id] = { xScale, yScale, xAxis, yAxis, valueLine, previousWidth };
} else {
// updating chart
let d3chart = d3.select($chart).transition();
Expand Down Expand Up @@ -277,11 +276,11 @@
chartInfo[id].previousWidth = newWidth;
}

d3chart.select(".chart-line") // change the line
d3chart.select(".chart-line")
.duration(200)
.attr("d", valueLine(data));

d3chart.select(".x.axis") // change the x axis
d3chart.select(".x.axis")
.duration(200)
.call(xAxis);
}
Expand Down

0 comments on commit ce5e403

Please sign in to comment.