Skip to content

Commit 1f17f40

Browse files
committed
Bufix: Shallow trees not rendered to tables properly
1 parent d187f92 commit 1f17f40

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Change Log
22

3+
## [1.1.2] - 2019-06-04
4+
### Fixed
5+
- If the first level of the tree is a leaf, `accounting-table` doesn't walk it
6+
correctly.
7+
### Added
8+
- Can pass through a custom `:min-leaf-depth` key to `tree` (replaces binding a
9+
dynamic var in earlier versions).
10+
11+
## [1.1.1] - 2019-06-01
12+
### Fixed
13+
- Total rows were not always being displayed correctly for trees
14+
315
## [1.1.0] - 2019-05-28
416
### Added
517
- More flexible tree rendering/aggregation

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ common sense styling.
88

99
Lein:
1010
```
11-
[org.clojars.mjdowney/excel-clj "1.1.1"]
11+
[org.clojars.mjdowney/excel-clj "1.1.2"]
1212
```
1313

1414
- [Getting Started](#getting-started)

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject org.clojars.mjdowney/excel-clj "1.1.1"
1+
(defproject org.clojars.mjdowney/excel-clj "1.1.2"
22
:description "Generate Excel documents & PDFs from Clojure data."
33
:url "https://github.com/matthewdowney/excel-clj"
44
:license {:name "Eclipse Public License"

src/excel_clj/core.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,13 @@
200200
If provided, the formatters argument is a function that takes the integer
201201
depth of a category (increases with nesting) and returns a cell format for
202202
the row, and total-formatters is the same for rows that are totals."
203-
[t & {:keys [headers formatters total-formatters data-format]
203+
[t & {:keys [headers formatters total-formatters min-leaf-depth data-format]
204204
:or {formatters style/default-tree-formatters
205205
total-formatters style/default-tree-total-formatters
206+
min-leaf-depth 2
206207
data-format :accounting}}]
207208
(try
208-
(let [tabular (tree/accounting-table (second t))
209+
(let [tabular (tree/accounting-table (second t) :min-leaf-depth min-leaf-depth)
209210
fmt-or-max (fn [fs n]
210211
(or (get fs n) (second (apply max-key first fs))))
211212
all-colls (or headers

src/excel_clj/tree.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,17 @@
161161
[{::depth 0 ::label (label node) ::header? true}]
162162
;; Then the children & their values
163163
(mapv #(update % ::depth inc) children)
164+
164165
;; And finally an aggregation if there are multiple header children
165166
;; or any leaf children
166167
(let [fchild (first children)
167168
siblings (get (group-by :depth children) (:depth fchild))]
168169
(when (or (>= (count siblings) 2) (not (::header? fchild)))
169170
[(merge {::depth 0 ::label "" ::total? true} (value node aggregate-with))])))
171+
170172
;; A leaf just has its label & value attrs. The depth is inc'd by each
171173
;; parent back to the root, so it does not stay at 0.
172-
(merge {::depth 0 ::label (label node)} (value node aggregate-with))))
174+
[(merge {::depth 0 ::label (label node)} (value node aggregate-with))]))
173175
tree)))
174176
(map
175177
(fn [table-row]

0 commit comments

Comments
 (0)