Navigation Menu

Skip to content

Commit

Permalink
Consistent handling of extra attr argument in (append).
Browse files Browse the repository at this point in the history
  • Loading branch information
lynaghk committed Sep 21, 2011
1 parent 924308e commit 6fcbff4
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/cljs/cljs_d3/core.cljs
Expand Up @@ -80,23 +80,25 @@
If passed :svg, call .append('svg:svg'), and also add namespace declarations so the resulting element is also valid XML.
Automatically make nodes take on the namespace of the first element in the selection (this may be removed if Mike incorporates this feature into D3 itself; see D3 issue #272)."
;;Handle some special cases
(condp = node-type
:svg (append-svg sel)
;;else
(let [[namespace nt] (cond
;;user-specified namespace
(re-find #":" node-type) (s/split node-type #":" 2)

;;inhert parent element namespaceURI; this only works on simple (append)s, not on, say, (enter) selections.
(.node sel) [(ns-abbv (.namespaceURI (. sel (node)))) node-type]

;;no namespace found...
true [nil node-type])
sel (.append sel (if (nil? namespace)
nt
(str (name namespace) ":" nt)))]

(attr sel (or attr-map {})))))
(let [new-el (condp = node-type
:svg (append-svg sel)
;;else
(let [[namespace nt] (cond
;;user-specified namespace
(re-find #":" node-type) (s/split node-type #":" 2)

;;inhert parent element namespaceURI; this only works on simple (append)s, not on, say, (enter) selections.
(.node sel) [(ns-abbv (.namespaceURI (. sel (node)))) node-type]

;;no namespace found...
true [nil node-type])]
(.append sel (if (nil? namespace)
nt
(str (name namespace) ":" nt)))

))]
;;Apply attr-map, if it was given
(attr new-el (or attr-map {}))))

(defn append-svg [sel]
;;See SVG authoring guidelines for more info: https://jwatt.org/svg/authoring/
Expand Down

0 comments on commit 6fcbff4

Please sign in to comment.