@@ -1482,6 +1482,27 @@ mpg
14821482 ([] {:mark :line :stat :identity })
14831483 ([opts] (merge {:mark :line :stat :identity } opts)))
14841484
1485+ ; ; ### ⚙️ `render-mark` `:line`
1486+
1487+ (defmethod render-mark :line [_ stat ctx]
1488+ (let [{:keys [coord all-colors cfg]} ctx
1489+ cfg (or cfg defaults )]
1490+ (into [:g ]
1491+ (concat
1492+ (when-let [lines (:lines stat)]
1493+ (for [{:keys [color x1 y1 x2 y2]} lines
1494+ :let [c (if color (color-for all-colors color) (:default-color cfg))
1495+ [px1 py1] (coord x1 y1)
1496+ [px2 py2] (coord x2 y2)]]
1497+ [:line {:x1 px1 :y1 py1 :x2 px2 :y2 py2
1498+ :stroke c :stroke-width (:line-width cfg)}]))
1499+ (when-let [pts (:points stat)]
1500+ (for [{:keys [color xs ys]} pts
1501+ :let [c (if color (color-for all-colors color) (:default-color cfg))
1502+ projected (sort-by first (map (fn [x y] (coord x y)) xs ys))]]
1503+ [:polyline {:points (str/join " " (map (fn [[px py]] (str px " ," py)) projected))
1504+ :stroke c :stroke-width (:line-width cfg) :fill " none" }]))))))
1505+
14851506; ; ### 🧪 Line Chart (Connecting Raw Points)
14861507
14871508(-> (views {:year [2018 2019 2020 2021 2022 ]
@@ -1636,27 +1657,6 @@ mpg
16361657 :x-domain (numeric-extent (clean x))
16371658 :y-domain (numeric-extent (clean y))}))))
16381659
1639- ; ; ### ⚙️ `render-mark` `:line`
1640-
1641- (defmethod render-mark :line [_ stat ctx]
1642- (let [{:keys [coord all-colors cfg]} ctx
1643- cfg (or cfg defaults )]
1644- (into [:g ]
1645- (concat
1646- (when-let [lines (:lines stat)]
1647- (for [{:keys [color x1 y1 x2 y2]} lines
1648- :let [c (if color (color-for all-colors color) (:default-color cfg))
1649- [px1 py1] (coord x1 y1)
1650- [px2 py2] (coord x2 y2)]]
1651- [:line {:x1 px1 :y1 py1 :x2 px2 :y2 py2
1652- :stroke c :stroke-width (:line-width cfg)}]))
1653- (when-let [pts (:points stat)]
1654- (for [{:keys [color xs ys]} pts
1655- :let [c (if color (color-for all-colors color) (:default-color cfg))
1656- projected (sort-by first (map (fn [x y] (coord x y)) xs ys))]]
1657- [:polyline {:points (str/join " " (map (fn [[px py]] (str px " ," py)) projected))
1658- :stroke c :stroke-width (:line-width cfg) :fill " none" }]))))))
1659-
16601660; ; ### 🧪 Scatter + Regression
16611661; ;
16621662; ; `layers` applies two layers to the same data -- one scatter, one regression line:
0 commit comments