Skip to content

Commit

Permalink
[wip]
Browse files Browse the repository at this point in the history
  • Loading branch information
kimo-k committed Nov 5, 2024
1 parent bb46b85 commit 26f0450
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 79 deletions.
28 changes: 10 additions & 18 deletions src/re_com/nested_grid/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,15 @@

(defn walk-size [{:keys [window-start window-end tree size-cache]}]
(let [sum-size (volatile! 0)
level->space (volatile! {})
depth (volatile! 0)
windowed-paths (volatile! [])
windowed-leaf-paths (volatile! [])
windowed-sizes (volatile! [])
windowed-sums (volatile! [])
collect-space! (fn [level space]
(vswap! level->space
(fn [m] (cond-> m
(not (get m level)) (assoc level space)))))
collect-depth! (fn [n] (vswap! depth max n))
collect-size! (fn [size] (vswap! windowed-sizes conj size))
forget-size! #(vswap! windowed-sizes pop)
collect-leaf-path! (fn [path] (vswap! windowed-leaf-paths conj path))
forget-leaf-path! #(vswap! windowed-leaf-paths pop)
collect-sum! (fn [sum] (vswap! windowed-sums conj sum))
forget-sum! #(vswap! windowed-sums pop)
collect-path! (fn [size] (vswap! windowed-paths conj size))
Expand Down Expand Up @@ -132,8 +128,7 @@
(when (and (intersection? bounds) collect-me?)
(collect-path! leaf-path)
(collect-sum! sum)
(collect-size! leaf-size)
(collect-space! level sum))
(collect-size! leaf-size))
(vreset! sum-size (+ sum leaf-size))
leaf-size)
(branch? node) (let [sum @sum-size
Expand All @@ -150,22 +145,20 @@
_ (collect-path! own-path)
_ (collect-size! own-size)
_ (collect-sum! sum)
_ (collect-depth! (count own-path))
descend-tx (map (partial walk own-path))
total-size (+ own-size
(transduce descend-tx + (children node)))
total-bounds [sum (+ sum total-size)]]
(if (intersection? total-bounds)
(collect-space! level sum)
(do
(forget-path!)

(forget-sum!)
(forget-size!)))
(when-not (intersection? total-bounds)
(forget-path!)
(forget-sum!)
(forget-size!))
(when-not csize (cache! node total-size))
total-size)))))]
(walk [] tree)
{:sum-size @sum-size
:level->space (into (sorted-map) @level->space) ;;TODO remove this.
:depth (inc @depth)
:windowed-sums @windowed-sums
:windowed-paths @windowed-paths
:windowed-sizes @windowed-sizes
Expand Down Expand Up @@ -196,8 +189,7 @@
:size-cache (volatile! {})
:tree test-tree})

(def td {:level->space {1 0, 2 180, 3 240, 4 260},
:sum-size 660,
(def td {:sum-size 660,
:window-end 342,
:window-start 242,
:windowed-paths [[:z] [:z :h] [:z :h :y] [:z :h :y 40] [:z :h :z] [:z :h :z 20]
Expand Down
124 changes: 63 additions & 61 deletions src/re_demo/nested_grid.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,12 +1069,12 @@
(let [internal-row-tree (r/atom (u/deref-or-value row-tree))
internal-column-tree (r/atom (u/deref-or-value column-tree))

row-traversal (r/reaction (ngu/walk-size {:tree @internal-row-tree
:window-start (* 2 @wy)
:window-end (+ (* 2 @wy) @wh)}))
column-traversal (r/reaction (ngu/walk-size {:tree @internal-column-tree
:window-start @wx
:window-end (+ @wx @ww)}))]
row-traversal (r/reaction (ngu/walk-size {:tree @internal-row-tree
:window-start (* 2 @wy)
:window-end (+ (* 2 @wy) @wh)}))
column-traversal (r/reaction (ngu/walk-size {:tree @internal-column-tree
:window-start @wx
:window-end (+ @wx @ww)}))]
(r/create-class
{:component-did-update
#(let [[_ {:keys [row-tree column-tree]}] (r/argv %)]
Expand All @@ -1090,65 +1090,67 @@
:grid-column-start (ngu/path->grid-line-name column-path)}}])}}]
(u/deref-or-value row-tree)
(u/deref-or-value column-tree)
(let [{row-space :level->space
(let [{row-depth :depth
row-space :level->space
row-height-total :sum-size
windowed-row-paths :windowed-paths
windowed-row-leaf-paths :windowed-leaf-paths} @row-traversal
{column-space :level->space
windowed-row-leaf-paths :windowed-leaf-paths}
@row-traversal
{column-depth :depth
column-space :level->space
column-width-total :sum-size
windowed-column-paths :windowed-paths
windowed-column-leaf-paths :windowed-leaf-paths} @column-traversal
column-depth (count column-space)
column-header-heights (repeat column-depth column-header-height)
column-header-height-total (apply + column-header-heights)
row-depth (count row-space)
row-header-widths (repeat row-depth row-header-width)
row-header-width-total (apply + row-header-widths)
row-tokens (ngu/lazy-grid-tokens @row-traversal)
row-template (ngu/lazy-grid-template row-tokens)
row-spans (ngu/grid-spans row-tokens)
column-tokens (ngu/lazy-grid-tokens @column-traversal)
column-template (ngu/lazy-grid-template column-tokens)
column-spans (ngu/grid-spans column-tokens)
spacer-container [:div {:style {:border "thin solid lightblue"}}]
row-header-container [:div {:style {:display :grid
:grid-template-rows row-template
:grid-template-columns (ngu/grid-template row-header-widths)}}]
row-header-cells (for [path windowed-row-paths]
[:div {:style {:grid-row-start (ngu/path->grid-line-name path)
:grid-row-end (str "span " (get row-spans path))
:grid-column-start (count path)
:grid-column-end (str "span " (+ 1 (- row-depth (count path))))
:border-top "thin solid green"
:border-left "thin solid green"
:overflow :hidden
:font-size 8}}
(pr-str path)])
column-header-container [:div {:style {:display :grid
:grid-template-rows (ngu/grid-template column-header-heights)
:grid-template-columns column-template}}]
column-header-cells (for [path windowed-column-paths]
[:div {:style {:grid-column-start (ngu/path->grid-line-name path)
:grid-column-end (str "span " (get column-spans path))
:grid-row-start (count path)
:grid-row-end (str "span " (+ 1 (- column-depth (count path))))
:border-top "thin solid green"
:border-left "thin solid green"
:overflow :hidden
:font-size 8}}
(pr-str path)])
main-container [:div
{:style {:flex "0 0 auto"
:border "2px solid grey"
:display :grid
:grid-template-rows (ngu/grid-template [column-header-height-total row-height-total])
:grid-template-columns (ngu/grid-template [row-header-width-total column-width-total])}}]
cell-grid-container [:div {:style {:display :grid
:grid-template-rows row-template
:grid-template-columns column-template}}]
cells (for [row-path windowed-row-leaf-paths
column-path windowed-column-leaf-paths]
(u/part cell {:row-path row-path :column-path column-path}))]
windowed-column-leaf-paths :windowed-leaf-paths}
@column-traversal
column-header-heights (repeat column-depth column-header-height)
column-header-height-total (apply + column-header-heights)
row-header-widths (repeat row-depth row-header-width)
row-header-width-total (apply + row-header-widths)
row-tokens (ngu/lazy-grid-tokens @row-traversal)
row-template (ngu/lazy-grid-template row-tokens)
row-spans (ngu/grid-spans row-tokens)
column-tokens (ngu/lazy-grid-tokens @column-traversal)
column-template (ngu/lazy-grid-template column-tokens)
column-spans (ngu/grid-spans column-tokens)
spacer-container [:div {:style {:border "thin solid lightblue"}}]
row-header-container [:div {:style {:display :grid
:grid-template-rows row-template
:grid-template-columns (ngu/grid-template row-header-widths)}}]
row-header-cells (for [path windowed-row-paths]
[:div {:style {:grid-row-start (ngu/path->grid-line-name path)
:grid-row-end (str "span " (get row-spans path))
:grid-column-start (count path)
:grid-column-end (str "span " (+ 1 (- row-depth (count path))))
:border-top "thin solid green"
:border-left "thin solid green"
:overflow :hidden
:font-size 8}}
(pr-str path)])
column-header-container [:div {:style {:display :grid
:grid-template-rows (ngu/grid-template column-header-heights)
:grid-template-columns column-template}}]
column-header-cells (for [path windowed-column-paths]
[:div {:style {:grid-column-start (ngu/path->grid-line-name path)
:grid-column-end (str "span " (get column-spans path))
:grid-row-start (count path)
:grid-row-end (str "span " (+ 1 (- column-depth (count path))))
:border-top "thin solid green"
:border-left "thin solid green"
:overflow :hidden
:font-size 8}}
(pr-str path)])
main-container [:div
{:style {:flex "0 0 auto"
:border "2px solid grey"
:display :grid
:grid-template-rows (ngu/grid-template [column-header-height-total row-height-total])
:grid-template-columns (ngu/grid-template [row-header-width-total column-width-total])}}]
cell-grid-container [:div {:style {:display :grid
:grid-template-rows row-template
:grid-template-columns column-template}}]
cells (for [row-path windowed-row-leaf-paths
column-path windowed-column-leaf-paths]
(u/part cell {:row-path row-path :column-path column-path}))]
[rc/v-box
:style {:position :relative}
:children
Expand Down

0 comments on commit 26f0450

Please sign in to comment.