From f3e1d35f3dbc3f0f68056f015b022407fa76ec6d Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 12 May 2020 08:45:41 +0200 Subject: [PATCH] :sparkles: Improve ruler scale calculation. --- frontend/src/uxbox/main.cljs | 4 ++-- .../src/uxbox/main/ui/workspace/rules.cljs | 23 +++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/frontend/src/uxbox/main.cljs b/frontend/src/uxbox/main.cljs index 393dbcb79..4eccb6d62 100644 --- a/frontend/src/uxbox/main.cljs +++ b/frontend/src/uxbox/main.cljs @@ -36,16 +36,16 @@ profile (:profile storage) authed? (and (not (nil? profile)) (not= (:id profile) uuid/zero))] + (cond (and (or (= path "") (nil? match)) (not authed?)) (st/emit! (rt/nav :login)) - (and (= path "") authed?) + (and (nil? match) authed?) (st/emit! (rt/nav :dashboard-team {:team-id (:default-team-id profile)})) - (nil? match) (st/emit! (rt/nav :not-found)) diff --git a/frontend/src/uxbox/main/ui/workspace/rules.cljs b/frontend/src/uxbox/main/ui/workspace/rules.cljs index ce9160b88..8bd089567 100644 --- a/frontend/src/uxbox/main/ui/workspace/rules.cljs +++ b/frontend/src/uxbox/main/ui/workspace/rules.cljs @@ -13,15 +13,30 @@ [uxbox.util.math :as mth] [uxbox.util.object :as obj])) +(defn- calculate-step-size + [zoom] + (cond + (< 0 zoom 0.008) 10000 + (< 0.008 zoom 0.015) 5000 + (< 0.015 zoom 0.04) 2500 + (< 0.04 zoom 0.07) 1000 + (< 0.07 zoom 0.2) 500 + (< 0.2 zoom 0.5) 250 + (< 0.5 zoom 1) 100 + (< 1 zoom 2) 50 + (< 2 zoom 4) 25 + (< 4 zoom 6) 10 + (< 6 zoom 15) 5 + (< 15 zoom 25) 2 + (< 25 zoom) 1 + :else 1)) + (defn draw-rule! [dctx {:keys [zoom size start count type] :or {count 200}}] (let [txfm (- (* (- 0 start) zoom) 20) minv (mth/round start) maxv (mth/round (+ start (/ size zoom))) - - step (mth/round (/ (mth/abs (- maxv minv)) count)) - step (max (* 1 (* 10 step)) 1)] - + step (calculate-step-size zoom)] (obj/set! dctx "fillStyle" "#E8E9EA") (if (= type :horizontal) (do