From 1d95208d6d99b582d10706f2c5d726bc703200d5 Mon Sep 17 00:00:00 2001 From: Curran Kelleher <68416+curran@users.noreply.github.com> Date: Mon, 26 Sep 2022 16:54:32 -0400 Subject: [PATCH 1/3] Adopt fat arrow syntax in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 69e4f7e8..1dcf9396 100644 --- a/README.md +++ b/README.md @@ -283,8 +283,8 @@ To convert to a hierarchy: ```js var root = d3.stratify() - .id(function(d) { return d.name; }) - .parentId(function(d) { return d.parent; }) + .id((d) => d.name) + .parentId((d) => d.parent) (table); ``` From a3b6931b48b5e8906c1eb380c70509f3961dd3b6 Mon Sep 17 00:00:00 2001 From: Curran Kelleher <68416+curran@users.noreply.github.com> Date: Mon, 24 Oct 2022 03:28:07 -0400 Subject: [PATCH 2/3] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Philippe Rivière --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1dcf9396..bf19c2df 100644 --- a/README.md +++ b/README.md @@ -283,8 +283,8 @@ To convert to a hierarchy: ```js var root = d3.stratify() - .id((d) => d.name) - .parentId((d) => d.parent) + .id(d => d.name) + .parentId(d => d.parent) (table); ``` From 1926644d1d9539f0c5171257f0e93a0a9be2caf2 Mon Sep 17 00:00:00 2001 From: Curran Kelleher <68416+curran@users.noreply.github.com> Date: Mon, 24 Oct 2022 03:31:43 -0400 Subject: [PATCH 3/3] Convert more functions to fat arrow in README --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index bf19c2df..bc76815a 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,7 @@ Returns an array of links for this *node* and its descendants, where each *link* Evaluates the specified *value* function for this *node* and each descendant in [post-order traversal](#node_eachAfter), and returns this *node*. The *node*.value property of each node is set to the numeric value returned by the specified function plus the combined value of all children. The function is passed the node’s data, and must return a non-negative number. The *value* accessor is evaluated for *node* and every descendant, including internal nodes; if you only want leaf nodes to have internal value, then return zero for any node with children. [For example](https://observablehq.com/@d3/treemap-by-count), as an alternative to [*node*.count](#node_count): ```js -root.sum(function(d) { return d.value ? 1 : 0; }); +root.sum(d => d.value ? 1 : 0); ``` You must call *node*.sum or [*node*.count](#node_count) before invoking a hierarchical layout that requires *node*.value, such as [d3.treemap](#treemap). Since the API supports [method chaining](https://en.wikipedia.org/wiki/Method_chaining), you can invoke *node*.sum and [*node*.sort](#node_sort) before computing the layout, and then subsequently generate an array of all [descendant nodes](#node_descendants) like so: @@ -159,8 +159,8 @@ var treemap = d3.treemap() .padding(2); var nodes = treemap(root - .sum(function(d) { return d.value; }) - .sort(function(a, b) { return b.height - a.height || b.value - a.value; })) + .sum(d => d.value) + .sort((a, b) => b.height - a.height || b.value - a.value)) .descendants(); ``` @@ -178,24 +178,24 @@ Unlike [*node*.sum](#node_sum), the *compare* function is passed two [nodes](#hi ```js root - .sum(function(d) { return d.value; }) - .sort(function(a, b) { return b.value - a.value; }); + .sum(d => d.value) + .sort((a, b) => b.value - a.value); `````` Similarly, to sort nodes by descending height (greatest distance from any descendant leaf) and then descending value, as is recommended for [treemaps](#treemap) and [icicles](#partition): ```js root - .sum(function(d) { return d.value; }) - .sort(function(a, b) { return b.height - a.height || b.value - a.value; }); + .sum(d => d.value) + .sort((a, b) => b.height - a.height || b.value - a.value); ``` To sort nodes by descending height and then ascending id, as is recommended for [trees](#tree) and [dendrograms](#cluster): ```js root - .sum(function(d) { return d.value; }) - .sort(function(a, b) { return b.height - a.height || a.id.localeCompare(b.id); }); + .sum(d => d.value) + .sort((a, b) => b.height - a.height || a.id.localeCompare(b.id)); ``` You must call *node*.sort before invoking a hierarchical layout if you want the new sort order to affect the layout; see [*node*.sum](#node_sum) for an example.