I have a d3 visualization that works fine with the current stable version ( 3.x), however I wanted to implement Pan and Zoom , so I upgraded to 4.alpha.
This led to a lot of errors when changing the syntax. I updated the variable names, however there is one error related to the second line of the following code:
function type(d) {
d.date = formatDate.parse(d.date);
d.Flux = +d.Flux;
return d;
}
Opening the page source through a browser, I see that formatDate.parse is not a function.Visualization is currently not a rendering.
I tried combing the D3 documentation 4.alpha , but to no avail.
Further in the code formatDateis defined as follows:
var formatDate = d3.timeFormat("%d-%b-%y");
I am happy to publish the original code, its about 70 lines in length and hack a little tho:
var margin = {top: 20, right: 20, bottom: 30, left: 50},
width = 1400
height = 1400
var formatDate = d3.timeFormat("%d-%b-%y");
var x = d3.scaleLinear()
.range([0, width]);
var y = d3.scaleLinear()
.range([height, 0]);
var line = d3.line()
.x(function(d) { return x(d.date); })
.y(function(d) { return y(d.Flux); });
var svg = d3.selectAll("#ExoPlanet, #ExoPlanet2").append("svg")
.attr("width", '90%')
.attr("height", '70%')
.attr('viewBox','0 0 '+Math.min(width,height)+' '+Math.min(width,height))
.attr('preserveAspectRatio','xMinYMin')
.append("g")
.call(d3.zoom()
.scaleExtent([1 / 2, 4])
.on("zoom", zoomed)) ;
function zoomed() {
var transform = d3.event.transform;
circle.attr("transform", function(d) {
return "translate(" + transform.applyX(d[0]) + "," + transform.applyY(d[1]) + ")";
});
}
d3.tsv("/FluxTime.tsv", type, function(error, data) {
if (error) throw error;
x.domain(d3.extent(data, function(d) { return d.date; }));
y.domain(d3.extent(data, function(d) { return d.Flux; }));
svg.selectAll("dot")
.data(data)
.enter().append("circle")
.attr("r", 2.0)
.attr("cx", function(d) { return x(d.date); })
.attr("cy", function(d) { return y(d.Flux); })
.attr("stroke", "#CE9A76");
});
function type(d) {
d.date = formatDate.parse(d.date));
d.Flux = +d.Flux;
return d;
}
8 :
