-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
awb99
committed
Sep 29, 2024
1 parent
474d023
commit b7c2de6
Showing
6 changed files
with
139 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
(ns rtable.render.pixi.bars | ||
(:require | ||
[tech.v3.dataset :as tmlds] | ||
["pixi.js" :as pixi :refer [Application Container Graphics Text]] | ||
[rtable.render.pixi.scale :refer [scale-bars]] | ||
)) | ||
|
||
|
||
(defn add-bar [graphics idx row] | ||
(let [{:keys [high low]} row | ||
bar-width 8 | ||
x (+ (* idx bar-width) (/ bar-width 2)) | ||
height (abs (- high low))] | ||
;(.moveTo graphics x high) | ||
;(.lineTo graphics x low) | ||
(.stroke graphics (clj->js {:width 2 :color 0xffffff})) | ||
(.fill graphics (clj->js {:color 0xaa4f08})); | ||
|
||
; (.rect graphics 530 50 140 100) | ||
(println "adding bar x: " x " y: " low " width: " bar-width " height: " height) | ||
(.rect graphics | ||
x low | ||
bar-width | ||
height) | ||
(.fill graphics (clj->js {:color 0xaa4f08})); | ||
(.stroke graphics (clj->js {:width 2 :color 0xffffff})))) | ||
|
||
|
||
|
||
(defn draw-bars [state] | ||
(let [{:keys [ds-visible container]} @state | ||
ds-visible (scale-bars ds-visible) | ||
rows (tmlds/rows ds-visible) | ||
graphics (Graphics.)] | ||
(println "scaled ds:") | ||
(println ds-visible) | ||
(println "container: " container) | ||
|
||
(doall (map-indexed (partial add-bar graphics) rows)) | ||
(.addChild container graphics) | ||
(println "draw-bars done."))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
(ns rtable.render.pixi.nav | ||
(:require | ||
[rtable.render.pixi.state :refer [adjust-visible]] | ||
[rtable.render.pixi.bars :refer [draw-bars]])) | ||
|
||
(defn pixi-render [state] | ||
(draw-bars state) | ||
(println "pixi-render done.") | ||
nil) | ||
|
||
(defn nav [state op] | ||
(let [{:keys [end-idx row-count row-count-visible container]} @state | ||
set-end-idx (fn [end-idx] | ||
(swap! state assoc :end-idx end-idx))] | ||
|
||
(case op | ||
:begin | ||
(set-end-idx row-count-visible) | ||
:end | ||
(set-end-idx row-count) | ||
:prior | ||
(set-end-idx (max row-count-visible (- end-idx row-count-visible))) | ||
:next | ||
(set-end-idx (min row-count (+ end-idx row-count-visible)))) | ||
(adjust-visible state) | ||
(.removeChildren container) | ||
(pixi-render state))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
(ns rtable.render.pixi.state | ||
(:require | ||
[tech.v3.dataset :as tmlds])) | ||
|
||
|
||
(defn adjust-visible [state] | ||
(let [{:keys [width step-px ds end-idx]} @state | ||
row-count-visible (int (/ width step-px)) | ||
start-idx (max 0 (- end-idx row-count-visible)) | ||
ds-visible (tmlds/select-rows ds (range start-idx end-idx))] | ||
|
||
(swap! state assoc | ||
:start-idx start-idx | ||
:ds-visible ds-visible | ||
:row-count-visible row-count-visible | ||
))) | ||
|
||
|
||
|
||
(defn create-state [{:keys [width height | ||
step-px]} container ds] | ||
(let [row-count (tmlds/row-count ds) | ||
state (atom {:width width | ||
:height height | ||
:step-px step-px | ||
:row-count row-count | ||
:ds ds | ||
:end-idx row-count | ||
:container container | ||
})] | ||
(adjust-visible state) | ||
(println "state: " (dissoc @state :ds)) | ||
state)) | ||
|
||
|
||
|