From 977ca82999febc32c390bd102aa0f17810b11aa4 Mon Sep 17 00:00:00 2001 From: Keith Bennett Date: Thu, 1 May 2014 15:19:48 -0400 Subject: [PATCH 1/2] Add functions to expose the x and y scales for external use. --- README.md | 8 ++++++++ d3-grid.js | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1f76573..9d1599f 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,14 @@ If nodeSize is set, returns the current nodeSize. If instead [size](#size) is set, returns the actual size of a node after [grid](#grid) has been called. +# grid.xScale() + +Returns the x scale used by this instance. + +# grid.yScale() + +Returns the y scale used by this instance. + ## Examples diff --git a/d3-grid.js b/d3-grid.js index 88f7d04..5280048 100644 --- a/d3-grid.js +++ b/d3-grid.js @@ -118,6 +118,10 @@ return grid; } + grid.xScale = function() { return x } + + grid.yScale = function() { return y } + return grid; }; -})(); \ No newline at end of file +})(); From acb5e01ea0c682bb4e82a184897bc8ebe657f31a Mon Sep 17 00:00:00 2001 From: Keith Bennett Date: Thu, 1 May 2014 16:11:27 -0400 Subject: [PATCH 2/2] Add row and col fields to each node. --- README.md | 3 +++ d3-grid.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index 9d1599f..20e3c18 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,9 @@ Computes the layout for nodes. Per default, the layout tries to keep the * x – the computed x-coordinate of the node position. * y – the computed y-coordinate of the node position. +In addition, row and col are added to each node so that they can be queried and used, for example, +to look up row- or column-specific data. + # grid.points() Configure the grid to treat nodes as points, cf. [d3.scale.ordinal().rangePoints()](https://github.com/mbostock/d3/wiki/Ordinal-Scales#wiki-ordinal_rangePoints). diff --git a/d3-grid.js b/d3-grid.js index 5280048..911d8f3 100644 --- a/d3-grid.js +++ b/d3-grid.js @@ -61,6 +61,9 @@ nodes[i].x = x(col); nodes[i].y = y(row); + + nodes[i].col = col; + nodes[i].row = row; } return nodes;