Skip to content
Browse files

Remove unused cljs layout namespace. Add constraint-based layout syst…

…em to TODO.
  • Loading branch information...
1 parent 4d7c573 commit eaa437c87afd69477bef08f57b19385bdcb838a7 @lynaghk committed May 5, 2012
Showing with 4 additions and 74 deletions.
  1. +4 −5 TODO.markdown
  2. +0 −69 src/cljs/c2/layout.cljs
View
9 TODO.markdown
@@ -9,6 +9,10 @@ Declarative behavior?
http://jbeard4.github.com/SCION/
+Constraint-based layout
+ http://github.com/lynaghk/cassowary-coffee
+
+
Is it possible to use pre/post conditions in development, but then strip them out when compiling to JS to save space?
ticks#search should take optional kwarg to find ticks that are a proper subset or superset of the data range
@@ -22,8 +26,3 @@ Pretty stack traces
-Design decisions
-================
-
-Should thing like svg.arc be higher order functions (as in D3), or just work as basic utilities?
-The latter is simpler, and I'm not convinced of the advantages of defining things like arc helpers away from where they'll be used.
View
69 src/cljs/c2/layout.cljs
@@ -1,69 +0,0 @@
-(comment
-
-(ns c2.layout
- (:refer-clojure :exclude [+ - =])
- (:use-macros [c2.util :only [p half]])
- (:use [c2.core :only [translate children select select-all]]
- [cassowary.core :only [+ - = cvar constrain! stay! simplex-solver]]))
-
- (defn distribute! [selector]
- (let [solver (simplex-solver)
- spacing (cvar 0)
- nodes (dom/query selector)
- container (dom/parent (first nodes))
- container-height (js/parseFloat (dom/attr container :height))
- positions (map #(let [base {:top (cvar (dom/attr % :top))
- :left (cvar (dom/attr % :left))
- :height (cvar (dom/attr % :height))
- :width (cvar (dom/attr % :width))}
- bottom (cvar)
- right (cvar)]
-
- (doto solver
- (stay! (:height base))
- (stay! (:width base))
- (constrain! (= bottom (+ (:top base) (:height base))))
- (constrain! (= right (+ (:left base) (:width base)))))
- (merge base {:bottom bottom, :right right}))
- nodes)]
-
- ;;Constraints to distribute the elements across the entire height
- (constrain! solver (= 0 (:top (first positions))))
- (constrain! solver (= container-height
- (:bottom (last positions))))
-
- (doseq [[t b] (partition 2 1 positions)]
- (constrain! solver (= (:top b) (+ (:bottom t) spacing))))
-
- (doseq [[node pos] (map vector nodes positions)]
- (dom/attr node (translate (.value (:left pos))
- (.value (:top pos)))))))
-
- (defn grid [n ncol container-width]
- (let [sep-width (/ container-width (inc ncol))]
- {:positions (map (fn [idx]
- {:top (* sep-width (Math/floor (/ idx ncol)))
- :left (* sep-width (mod idx ncol))})
- (range n))
- :sep-width sep-width
- :container-width container-width
- :container-height (* sep-width (inc (Math/floor (/ n ncol))))}))
-
- (defn grid!
- "Positions objects in parent container to form a grid ncol items wide"
- [container ncol & {:keys [selector]}]
- (when-let [container (select container)]
- (let [nodes (if selector
- (select-all selector)
- (children container))
- container-width (js/parseFloat (dom/css container :width))
- sep-width (/ container-width (inc ncol))
- {:keys [positions container-height]} (grid (count nodes) ncol container-width)]
-
- ;;Position the nodes
- (doseq [[{:keys [top left]} node] (map vector positions nodes)]
- (dom/css node {:-webkit-transform (str "translate(" left "px" ", " top "px" ")")}))
-
- ;;Manually set container height according to the number of rows
- (dom/css container :height (str container-height "px")))))
-)

0 comments on commit eaa437c

Please sign in to comment.
Something went wrong with that request. Please try again.