Skip to content

Commit

Permalink
arearange added
Browse files Browse the repository at this point in the history
  • Loading branch information
awb99 committed Sep 30, 2024
1 parent 842db0d commit a2bc9bd
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 9 deletions.
1 change: 1 addition & 0 deletions demo/src/demo/page/pixi.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
;:close {:type :line}
{:type :line :col :daily-atr-lower :color "blue-3"}
{:type :line :col :daily-atr-upper :color "blue-7"}
{:type :range :col [:daily-atr-lower :daily-atr-upper] :color "red-3"}
{:type :line :col :p0-low :color "red-3"}
{:type :line :col :p1-low :color "red-4"}
{:type :line :col :pweek-low :color "red-5"}
Expand Down
44 changes: 44 additions & 0 deletions src/rtable/render/pixi/arearange.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
(ns rtable.render.pixi.arearange
(:require
[tech.v3.dataset :as tmlds]
["pixi.js" :as pixi :refer [Application Container Graphics Text]]
[rtable.render.pixi.scale :refer [scale-bars scale-col]]
[rtable.color :refer [set-color]]
))


(defn add-bar [graphics step-px height col1 col2 color idx row]
(let [; x
bar-width step-px
x-center (* idx step-px)
x x-center
; y
c1 (min height (max 0 (get row col1)))
c2 (min height (max 0 (get row col2)))
y (min c1 c2)
height (abs (- c1 c2))]
; BAR
(println "adding range-bar x: " x "y: " y
" c1: " c1 " c2: " c2 " width: " bar-width " height: " height "color: " color)
(.rect graphics x y bar-width height)
(.fill graphics (clj->js {:color color
:alpha 0.5
}));
;(.stroke graphics (clj->js {:width 1 :color 0xffffff}))

))

(defn draw-range [state container height price-range col1 col2 color]
(let [{:keys [ds-visible step-px]} @state
color2 (set-color color)
ds (-> ds-visible
(scale-col height price-range col1)
(scale-col height price-range col2))
rows (tmlds/rows ds)
graphics (Graphics.)]
;(println "scaled ds:")
;(println ds-visible)
(doall (map-indexed (partial add-bar graphics step-px height col1 col2 color2) rows))
(.addChild container graphics)
(println "draw-bars done.")))

41 changes: 32 additions & 9 deletions src/rtable/render/pixi/nav.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,44 @@
[rtable.render.pixi.state :refer [adjust-visible]]
[rtable.render.pixi.scale :refer [determine-range-bars determine-range-col]]
[rtable.render.pixi.bars :refer [draw-bars]]
[rtable.render.pixi.line :refer [draw-line draw-points]]))
[rtable.render.pixi.line :refer [draw-line draw-points]]
[rtable.render.pixi.arearange :refer [draw-range]]

))

(defn col-kw-ok? [state col]
(let [{:keys [ds-visible]} @state]
(get ds-visible col)))

(defn col-vec-ok? [state col]
(println "col-ok vector: " col)
(reduce (fn [r c]
(and r (col-kw-ok? state c)))
true col))

(defn col-ok? [state col]
(if (keyword? col)
(col-kw-ok? state col)
(col-vec-ok? state col)))


(defn draw-series [state container height {:keys [type col color]}]
(let [{:keys [ds-visible]} @state
ds-col (get ds-visible col)
color (or color "blue-5")]
(if ds-col
(if (col-ok? state col)
(let [price-range (determine-range-col ds-visible col)]
;price-range (determine-range-bars ds-visible)
(case type
:line
(draw-line state container height price-range col color)
:point
(draw-points state container height price-range col color)
(println "unsupported type: " type)
:line
(draw-line state container height price-range col color)
:point
(draw-points state container height price-range col color)
:range
(let [[col1 col2] col
price-range (determine-range-bars ds-visible)]
(draw-range state container height price-range col1 col2 color))
;

(println "unsupported type: " type)
))
(do (println "cannot draw linechart. col missing: " col)
(println "cols: " (tmlds/column-names ds-visible))))))
Expand Down

0 comments on commit a2bc9bd

Please sign in to comment.