Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Charts module #143

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
Hex density: split radius into draw & pack radii
  • Loading branch information
tlwr committed May 30, 2017
commit 6cdc7d3966e19443c5d4d595ff1218eb04e6fc79
7 changes: 6 additions & 1 deletion src/core/config/OperationConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3406,10 +3406,15 @@ const OperationConfig = {
value: Charts.FIELD_DELIMITER_OPTIONS,
},
{
name: "Radius",
name: "Pack radius",
type: "number",
value: 25,
},
{
name: "Draw radius",
type: "number",
value: 15,
},
{
name: "Use column headers as labels",
type: "boolean",
Expand Down
21 changes: 11 additions & 10 deletions src/core/operations/Charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ const Charts = {
runHexDensityChart: function (input, args) {
const recordDelimiter = Utils.charRep[args[0]],
fieldDelimiter = Utils.charRep[args[1]],
radius = args[2],
columnHeadingsAreIncluded = args[3],
packRadius = args[2],
drawRadius = args[3],
columnHeadingsAreIncluded = args[4],
dimension = 500;

let xLabel = args[4],
yLabel = args[5],
let xLabel = args[5],
yLabel = args[6],
{ headings, values } = Charts._getScatterValues(
input,
recordDelimiter,
Expand Down Expand Up @@ -114,18 +115,18 @@ const Charts = {
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");

let hexbin = d3hexbin()
.radius(radius)
.radius(packRadius)
.extent([0, 0], [width, height]);

let hexPoints = hexbin(values),
maxCount = Math.max(...hexPoints.map(b => b.length));

let xExtent = d3.extent(hexPoints, d => d.x),
yExtent = d3.extent(hexPoints, d => d.y);
xExtent[0] -= 2 * radius;
xExtent[1] += 2 * radius;
yExtent[0] -= 2 * radius;
yExtent[1] += 2 * radius;
xExtent[0] -= 2 * packRadius;
xExtent[1] += 2 * packRadius;
yExtent[0] -= 2 * packRadius;
yExtent[1] += 2 * packRadius;

let xAxis = d3.scaleLinear()
.domain(xExtent)
Expand All @@ -151,7 +152,7 @@ const Charts = {
.enter()
.append("path")
.attr("d", d => {
return `M${xAxis(d.x)},${yAxis(d.y)} ${hexbin.hexagon(radius * 0.75)}`;
return `M${xAxis(d.x)},${yAxis(d.y)} ${hexbin.hexagon(drawRadius)}`;
})
.attr("fill", (d) => color(d.length))
.append("title")
Expand Down