0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 08:50:57 -05:00

Improve ruler scale calculation.

This commit is contained in:
Andrey Antukh 2020-05-12 08:45:41 +02:00
parent 994a1fa144
commit f3e1d35f3d
2 changed files with 21 additions and 6 deletions

View file

@ -36,16 +36,16 @@
profile (:profile storage) profile (:profile storage)
authed? (and (not (nil? profile)) authed? (and (not (nil? profile))
(not= (:id profile) uuid/zero))] (not= (:id profile) uuid/zero))]
(cond (cond
(and (or (= path "") (and (or (= path "")
(nil? match)) (nil? match))
(not authed?)) (not authed?))
(st/emit! (rt/nav :login)) (st/emit! (rt/nav :login))
(and (= path "") authed?) (and (nil? match) authed?)
(st/emit! (rt/nav :dashboard-team {:team-id (:default-team-id profile)})) (st/emit! (rt/nav :dashboard-team {:team-id (:default-team-id profile)}))
(nil? match) (nil? match)
(st/emit! (rt/nav :not-found)) (st/emit! (rt/nav :not-found))

View file

@ -13,15 +13,30 @@
[uxbox.util.math :as mth] [uxbox.util.math :as mth]
[uxbox.util.object :as obj])) [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! (defn draw-rule!
[dctx {:keys [zoom size start count type] :or {count 200}}] [dctx {:keys [zoom size start count type] :or {count 200}}]
(let [txfm (- (* (- 0 start) zoom) 20) (let [txfm (- (* (- 0 start) zoom) 20)
minv (mth/round start) minv (mth/round start)
maxv (mth/round (+ start (/ size zoom))) maxv (mth/round (+ start (/ size zoom)))
step (calculate-step-size zoom)]
step (mth/round (/ (mth/abs (- maxv minv)) count))
step (max (* 1 (* 10 step)) 1)]
(obj/set! dctx "fillStyle" "#E8E9EA") (obj/set! dctx "fillStyle" "#E8E9EA")
(if (= type :horizontal) (if (= type :horizontal)
(do (do