Skip to content

Commit

Permalink
scatterPlot: updated using margin convention
Browse files Browse the repository at this point in the history
  • Loading branch information
mikima committed Jun 5, 2018
1 parent b0e28a5 commit dc7714e
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions charts/scatterPlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,22 @@
var x = points.dimensions().get('x'),
y = points.dimensions().get('y');

var g = selection
.attr("width", +width())
.attr("height", +height())
.append("g");

//define margins
var margin = {
top: 0,
right: 0,
bottom: 20,
top: +maxRadius(),
right: +maxRadius(),
bottom: 20 + maxRadius(),
left: marginLeft()
};

var w = width() - margin.left,
h = height() - margin.bottom;
var w = width() - margin.left - margin.right,
h = height() - margin.bottom - margin.top;

var g = selection
.attr("width", +width())
.attr("height", +height())
.append("g")
.attr('transform','translate(' + margin.left + ',' + margin.top + ')')

var xExtent = !useZero() ? d3.extent(data, d => {
return d.x;
Expand All @@ -73,31 +74,33 @@
})];

var xScale = x.type() == "Date" ?
d3.scaleTime().range([margin.left, width() - maxRadius()]).domain(xExtent) :
d3.scaleLinear().range([margin.left, width() - maxRadius()]).domain(xExtent),
d3.scaleTime().range([0, w]).domain(xExtent) :
d3.scaleLinear().range([0, w]).domain(xExtent),
yScale = y.type() == "Date" ?
d3.scaleTime().range([h - maxRadius(), maxRadius()]).domain(yExtent) :
d3.scaleLinear().range([h - maxRadius(), maxRadius()]).domain(yExtent),
sizeScale = d3.scaleLinear().range([1, Math.pow(+maxRadius(), 2) * Math.PI]).domain([0, d3.max(data, d => {
return d.size;
})]),
xAxis = d3.axisBottom(xScale).tickSize(-h + maxRadius() * 2) //.tickSubdivide(true),
yAxis = d3.axisLeft(yScale).ticks(10).tickSize(-w + maxRadius());
d3.scaleTime().range([h, 0]).domain(yExtent) :
d3.scaleLinear().range([h, 0]).domain(yExtent),
sizeScale = d3.scaleSqrt().range([1, +maxRadius()])
.domain([0, d3.max(data, d => {
return d.size;
})]),
xAxis = d3.axisBottom(xScale).tickSize(-h) //.tickSubdivide(true),
yAxis = d3.axisLeft(yScale).ticks(10).tickSize(-w);

g.append("g")
.attr("class", "x axis")
.style("stroke-width", "1px")
.style("font-size", "10px")
.style("font-family", "Arial, Helvetica")
.attr("transform", `translate(0, ${h - maxRadius()})`)
//.attr("transform", `translate(0, ${h - maxRadius()})`)
.attr('transform', 'translate(0,' + h + ')')
.call(xAxis);

g.append("g")
.attr("class", "y axis")
.style("stroke-width", "1px")
.style("font-size", "10px")
.style("font-family", "Arial, Helvetica")
.attr("transform", `translate(${margin.left}, 0)`)
//.attr("transform", `translate(${margin.left}, 0)`)
.call(yAxis);

d3.selectAll(".y.axis line, .x.axis line, .y.axis path, .x.axis path")
Expand Down Expand Up @@ -128,7 +131,7 @@
return `translate(${xScale(d.x)}, ${yScale(d.y)})`;
})
.attr("r", d => {
return Math.sqrt(sizeScale(d.size) / Math.PI);
return sizeScale(d.size);
});

point.append("circle")
Expand Down

0 comments on commit dc7714e

Please sign in to comment.