Skip to content

Commit

Permalink
cheetah working
Browse files Browse the repository at this point in the history
  • Loading branch information
awb99 committed Oct 26, 2024
1 parent 8f7f53d commit 9b72de5
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 55 deletions.
14 changes: 11 additions & 3 deletions dali/src/dali/viewer.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
[dali.util.resolve :refer [resolve-symbol]]))

(defn transform-data [transform-fn data]
(info "transforming: " transform-fn " data: " data)
(-> (resolve-symbol transform-fn)
(p/then (fn [transform]
(transform data)))))
(info "transform-fn resolve success. Now transforming.")
(info "transform: " transform)
(let [r (transform data)]
(info "data successfully transformed to: " r)
r
)
))))


(defn process [{:keys [viewer-fn transform-fn data] :as _dali-spec}]
Expand All @@ -27,6 +34,7 @@

(defn viewer [{:keys [viewer-fn transform-fn data] :as dali-spec}]
(let [a (r/atom nil)]
(info "viewer viewer-fn: " viewer-fn " transform-fn: " transform-fn)
(-> (process dali-spec)
(p/then (fn [r]
(info "load and transform complete!")
Expand All @@ -35,9 +43,9 @@
(error "load and transform error: " err)
(reset! a {:error err}))))
(fn [{:keys [viewer-fn transform-fn data]}]
(let [{:keys [viewer data error]} @a]
(let [{:keys [viewer data error] :as aval} @a]
(cond
(nil? @a)
(nil? aval)
[:p "loading.."]
error
[:p "error!"]
Expand Down
85 changes: 41 additions & 44 deletions demo/src/demo/page/cheetah.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(ns demo.page.cheetah
(:require
;[pinkgorilla.goog.string :refer [format]]
[rtable.render.cheetah :refer [cheetah cheetah-ds]]
[rtable.viewer.cheetah :refer [cheetah cheetah-ds]]
[dali.viewer :refer [viewer]]
[demo.helper.ui :refer [sample-selector]]))

(def data [{"make" "Toyota" "model" "Celica" "price" 35000}
Expand All @@ -16,7 +17,7 @@
[cheetah {:style {:width "800px" :height "600px"}
:columns [{:field "make" :caption "m" :width 50}
{:field "model" :caption "model" :width 50}
{:field "price" :caption "$$$" :width 50
{:field "price" :caption "$$$" :width 50
:format 'demo.helper.format2/format-hidden}]
:data data}]

Expand All @@ -30,51 +31,47 @@
{:make "Porsche" :model "Boxter" :price 72000}]}]

:dataset
[cheetah-ds {:style {:width "1800px" :height "600px"}
:columns [; bar
{:field "asset" :caption "a" :width 90}
{:field "date" :caption "d" :width 220
[viewer
{:viewer-fn 'rtable.viewer.cheetah/cheetah-ds
:transform-fn 'rtable.transform.cheetah/load-and-transform-cheetah
:data {:url "/r/bars-1m-full.transit-json"
:style {:width "1800px" :height "600px"}
:columns [; bar
{:field "asset" :caption "a" :width 90}
{:field "date" :caption "d" :width 220
;:style 'demo.page.cheetah/bad-fn
}
{:field "open" :caption "o" :width 90
:style 'demo.helper.format2/red-color}
{:field "high" :caption "h" :width 90
:format 'demo.helper.format2/format-hidden}
{:field "low" :caption "l" :width 90
}
{:field "open" :caption "o" :width 90
:style 'demo.helper.format2/red-color}
{:field "high" :caption "h" :width 90
:format 'demo.helper.format2/format-hidden}
{:field "low" :caption "l" :width 90
;; this namespace does not work.
:format 'demo.helper.format2/format-number
:format-args ["Low: %.5f"]
}
{:field "close" :caption "c" :width 90
:style 'demo.helper.format2/blue-color
:format 'demo.helper.format2/format-number
:format-args ["Low: %.5f"]}
{:field "close" :caption "c" :width 90
:style 'demo.helper.format2/blue-color
;:format format
:format-args "Cost: %.2f"
}
{:field "volume" :caption "v" :width 90}
:format-args "Cost: %.2f"}
{:field "volume" :caption "v" :width 90}
;
{:field "atr-band-lower" :caption "BL" :width 50}
{:field "atr-band-upper" :caption "BU" :width 50}
{:field "doji" :caption "doji" :width 50}
{:field "atr-band-lower" :caption "BL" :width 50}
{:field "atr-band-upper" :caption "BU" :width 50}
{:field "doji" :caption "doji" :width 50}

{:field "below-band" :caption "B?" :width 50
:style {:bgColor "#5f5"}}
{:field "cross-down" :caption "XD" :width 50}
{:field "cross-down-c" :caption "XD_" :width 50}
{:field "long-signal" :caption "LS" :width 50}
{:field "below-band" :caption "B?" :width 50
:style {:bgColor "#5f5"}}
{:field "cross-down" :caption "XD" :width 50}
{:field "cross-down-c" :caption "XD_" :width 50}
{:field "long-signal" :caption "LS" :width 50}

{:field "above-band" :caption "A?" :width 50 :format 'demo.helper.format2/format-bool}
{:field "cross-up" :caption "XU" :width 50 :format 'demo.helper.format2/format-bool}
{:field "cross-up-c" :caption "XU_" :width 50
:style 'demo.helper.format2/bool-color
:format 'demo.helper.format2/format-bool2
:format-args [false]
}
{:field "short-signal" :caption "SS" :width 50
:format 'demo.helper.format2/format-bool2
:format-args [true]
}

{:field "entry" :caption "entry" :width 50

}]
:url "/r/bars-1m-full.transit-json"}]}]])
{:field "above-band" :caption "A?" :width 50 :format 'demo.helper.format2/format-bool}
{:field "cross-up" :caption "XU" :width 50 :format 'demo.helper.format2/format-bool}
{:field "cross-up-c" :caption "XU_" :width 50
:style 'demo.helper.format2/bool-color
:format 'demo.helper.format2/format-bool2
:format-args [false]}
{:field "short-signal" :caption "SS" :width 50
:format 'demo.helper.format2/format-bool2
:format-args [true]}
{:field "entry" :caption "entry" :width 50}]}}]}]])
4 changes: 2 additions & 2 deletions demo/src/demo/page/highcharts.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require
[reagent.core :as r]
[ui.highcharts :as highchart-old]
[rtable.render.highcharts :refer [highstock highstock-ds]]
[rtable.viewer.highcharts :refer [highstock highstock-ds]]
[demo.highcharts.spec :refer [highchart-spec]]
[demo.highcharts.spec-annotations :as annotations]
[demo.helper.ui :refer [link-href link-dispatch sample-selector]]))
Expand All @@ -26,7 +26,7 @@
:annotation [highchart-old/highchart {:data annotations/spec :box :lg}]}]

;; new version that provides :style and :class
[:p.bg-red-500.p-3 "NEW rtable.render.highcharts"]
[:p.bg-red-500.p-3 "NEW rtable.viewer.highcharts"]
[sample-selector
{:lg-new
[highstock {:style {:width "1000px"
Expand Down
4 changes: 2 additions & 2 deletions demo/src/demo/page/pixi.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns demo.page.pixi
(:require
[tech.v3.dataset :as tmlds]
[rtable.render.pixi :refer [pixi pixi-ds]]
[rtable.viewer.pixi :refer [pixi pixi-ds]]
[demo.helper.ui :refer [link-href link-dispatch sample-selector]]))


Expand All @@ -16,7 +16,7 @@
[:div {:class "h-screen w-screen"} ; .grid.grid-cols-2
[link-href "/" "main"]
;; new version that provides :style and :class
[:p.bg-red-500.p-3 "rtable.render.pixi"]
[:p.bg-red-500.p-3 "rtable.viewer.pixi"]
[sample-selector
{:test-dataset
[pixi {:style {:width "1000px"
Expand Down
9 changes: 7 additions & 2 deletions resources/ext/rtable-cheetah.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
; build
:lazy true
:depends-on #{:techml-dataset-cljs :dali}
:cljs-namespace [rtable.viewer.cheetah]
:cljs-namespace [rtable.viewer.cheetah
rtable.transform.cheetah]
:cljs-ns-bindings {'rtable.viewer.cheetah {'cheetah rtable.viewer.cheetah/cheetah
'cheetah-ds rtable.viewer.cheetah/cheetah-ds}}
'cheetah-ds rtable.viewer.cheetah/cheetah-ds}
'rtable.transform.cheetah {'load-and-transform-cheetah rtable.transform.cheetah/load-and-transform-cheetah}


}

;
}
2 changes: 1 addition & 1 deletion src/rtable/plot/cheetah.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns rtable.plot.cheetah)
(:require
[rtable.render.cheetah :refer [cheetah-ds]])
[rtable.viewer.cheetah :refer [cheetah-ds]])

(defn cheetah-table [opts data]
(let [cols (:columns opts)
Expand Down
3 changes: 2 additions & 1 deletion src/rtable/transform/cheetah.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
[taoensso.timbre :refer-macros [info warn error]]
[promesa.core :as p]
[dali.transform.transit :refer [load-transit]]
[rtable.resolve :refer [resolve-col]]))
[dali.util.resolve :refer [resolve-col]]))

(defn load-and-transform-cheetah [{:keys [columns url] :as opts}]
(info "cheetah transform opts: " opts)
(let [ds-p (load-transit url)
columns-p (resolve-col columns [:style
:format])]
Expand Down

0 comments on commit 9b72de5

Please sign in to comment.