Skip to content

Commit

Permalink
WIP highlights for frame queries
Browse files Browse the repository at this point in the history
  • Loading branch information
prabhanshuguptagit committed Jun 29, 2024
1 parent e2e3cc9 commit 1906cf4
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 29 deletions.
2 changes: 1 addition & 1 deletion public/demos.edn

Large diffs are not rendered by default.

42 changes: 19 additions & 23 deletions src/bean/functions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@
[end-r end-c] (:end frame)
cols (range start-c (inc end-c))
rows (map first (mapcat identity selection))
new-selection (->> (for [r rows]
(for [col cols]
[r col]))
minimum-matrix)]
{:matrix (address-matrix->cells-matrix sheet new-selection)
new-selection (for [r rows]
(for [col cols]
[r col]))]
{:matrix (address-matrix->cells-matrix sheet (minimum-matrix new-selection))
:frame (merge frame-result {:selection new-selection})})
(first args)))

Expand All @@ -70,11 +69,10 @@
[end-r end-c] (:end frame)
cols (set (map second (mapcat identity selection)))
rows (range start-r (inc end-r))
new-selection (->> (for [r rows]
(for [col cols]
[r col]))
minimum-matrix)]
{:matrix (address-matrix->cells-matrix sheet new-selection)
new-selection (for [r rows]
(for [col cols]
[r col]))]
{:matrix (address-matrix->cells-matrix sheet (minimum-matrix new-selection))
:frame (merge frame-result {:selection new-selection})})
(first args)))

Expand All @@ -95,7 +93,8 @@
;; These don't work for matrices right now
;; It should: eval-matrix should perhaps return a :selection also
(defn bean-filter [sheet args]
(if-not (:error (first args))
(if (and (not (:error (first args)))
(second args))
(let [frame-result (:frame (first args))
f (second args)
new-selection (->> (:selection frame-result)
Expand All @@ -105,9 +104,8 @@
sheet f [(util/get-cell (:grid sheet) %)]))
%))
remove-nil-columns
remove-nil-rows
minimum-matrix)]
{:matrix (address-matrix->cells-matrix sheet new-selection)
remove-nil-rows)]
{:matrix (address-matrix->cells-matrix sheet (minimum-matrix new-selection))
:frame (merge frame-result {:selection new-selection})})
(first args)))

Expand All @@ -126,12 +124,11 @@

new-selection
(->> (util/map-on-matrix
#(get first-match (:representation (util/get-cell (:grid sheet) %)))
(:selection from-frame))
remove-nil-columns
remove-nil-rows
minimum-matrix)]
{:matrix (address-matrix->cells-matrix sheet new-selection)
#(get first-match (:representation (util/get-cell (:grid sheet) %)))
(:selection from-frame))
remove-nil-columns
remove-nil-rows)]
{:matrix (address-matrix->cells-matrix sheet (minimum-matrix new-selection))
:frame {:selection new-selection
:name (:name to-frame)}})))
(first args)))
Expand All @@ -150,9 +147,8 @@
(and (contains? (:skips frame-result) %)
(contains? (:skips label-cells) %))) %))
remove-nil-columns
remove-nil-rows
minimum-matrix)]
{:matrix (address-matrix->cells-matrix sheet new-selection)
remove-nil-rows)]
{:matrix (address-matrix->cells-matrix sheet (minimum-matrix new-selection))
:frame (merge frame-result {:selection new-selection})})
(errors/label-not-found
(:scalar (interpreter/eval-ast (second asts) sheet)))))
Expand Down
3 changes: 3 additions & 0 deletions src/bean/grid.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@
(defn parse-grid [grid]
(util/map-on-matrix value/from-cell grid))

(defn eval-content [sheet content]
(interpreter/eval-ast (parser/parse content) sheet))

(defn- eval-cell* [cell sheet]
(if-not (empty-spilled-cell? cell)
(let [parsed-cell (assoc cell :ast (parser/parse (:content cell)))]
Expand Down
3 changes: 2 additions & 1 deletion src/bean/ui/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ average:{x.sum() / x.count()}"))
:col-widths (vec (repeat num-cols (:cell-w styles/sizes)))}))
:ui {:help-display false
:grid {:editing-cell nil
:selection nil}}}))
:selection nil
:highlighted-cells #{}}}}))
9 changes: 9 additions & 0 deletions src/bean/ui/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,15 @@
(fn edit-frame [db [_ frame-name]]
(assoc-in db [:ui :renaming-frame] frame-name)))

(rf/reg-event-db
::highlight-matrix
(undoable)
(fn highlight-matrix [db [_ content]]
(assoc-in db [:ui :grid :highlighted-cells]
(set (mapcat identity (get-in
(grid/eval-content (:sheet db) content)
[:frame :selection]))))))

(rf/reg-event-db
::rename-frame
(undoable)
Expand Down
20 changes: 16 additions & 4 deletions src/bean/ui/views/sheet.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,10 @@
(cell-h label-r (get-in sheet [:grid label-r label-c]) row-heights))
(when (= dirn :top-left)
(draw-top-left-label-indicator g
(+ (nth xs label-c)
(cell-w label-c (get-in sheet [:grid label-r label-c]) col-widths))
(+ (nth ys label-r)
(cell-h label-r (get-in sheet [:grid label-r label-c]) row-heights)))))
(+ (nth xs label-c)
(cell-w label-c (get-in sheet [:grid label-r label-c]) col-widths))
(+ (nth ys label-r)
(cell-h label-r (get-in sheet [:grid label-r label-c]) row-heights)))))
(draw-skipped-cells g textures sheet skipped-cells row-heights col-widths xs ys)
(.endFill g))
g))
Expand Down Expand Up @@ -607,6 +607,16 @@
(when selection
(selection->rect g selection row-heights col-widths))))

(defn- draw-highlighted-cells
[^js grid-g highlighted-cells row-heights col-widths]
(.beginFill grid-g "0xaa0011" 0.25)
(doall
(map
#(let [[x y w h]
(area->xywh {:start % :end %} row-heights col-widths)]
(.drawRect grid-g x y w h))
highlighted-cells)))

(defn- draw-cell-text
([] (new pixi/Graphics))
([^js g {:keys [grid]} row-heights col-widths]
Expand Down Expand Up @@ -712,6 +722,7 @@
(draw-cell-text (:cell-text @pixi-app) sheet row-heights col-widths)
(draw-frames (:frames @pixi-app) (:textures @pixi-app) sheet grid-ui (:grid @pixi-app) row-heights col-widths)
(draw-selection (:selection @pixi-app) (:selection grid-ui) row-heights col-widths)
(draw-highlighted-cells (:grid @pixi-app) (:highlighted-cells grid-ui) row-heights col-widths)
(draw-top-heading (:top-heading @pixi-app) col-widths v)
(draw-left-heading (:left-heading @pixi-app) row-heights v)
(draw-corner (:corner @pixi-app) v)))
Expand Down Expand Up @@ -807,6 +818,7 @@
:on-pointer-up #(let [canvas (.querySelector js/document "#grid-container canvas")]
(.dispatchEvent canvas (new js/MouseEvent "pointerup" %)))
:on-key-down #(handle-cell-navigation % [r c] @sheet)
:on-input #(rf/dispatch [::events/highlight-matrix (.-textContent (.-target %))])
:on-paste cell-paste-text}
(:content cell)])))

Expand Down

0 comments on commit 1906cf4

Please sign in to comment.