<commit_before>#+SETUPFILE: ../../src/setup.org

* Contents                                                         :toc_4_gh:
 - [[#namespace-thinggeomvizcore][Namespace: thi.ng.geom.viz.core]]
     - [[#example-usage][Example usage]]
         - [[#running-all-examples-from-repl][Running all examples from REPL]]
         - [[#namespaces-required-by-all-examples][Namespaces required by all examples]]
         - [[#scatter-plot][Scatter plot]]
         - [[#line--area-plot][Line & area plot]]
         - [[#radar-plot][Radar plot]]
         - [[#stacked-intervals][Stacked intervals]]
             - [[#plain-intervals][Plain intervals]]
             - [[#categorized-timeline][Categorized timeline]]
         - [[#contour-plot][Contour plot]]
     - [[#visualization-spec-format][Visualization spec format]]
         - [[#axis-definitions-x-axis--y-axis][Axis definitions (:x-axis / :y-axis)]]
             - [[#notes-for-polar-projection][Notes for polar projection]]
             - [[#default-axis-label-styling][Default axis label styling]]
         - [[#axis-grid-definition-grid][Axis grid definition (:grid)]]
         - [[#dataset-specs-data][Dataset specs (:data)]]
     - [[#scales][Scales]]
         - [[#linear-scale][Linear scale]]
         - [[#logarithmic-scale][Logarithmic scale]]
         - [[#lens-scale-dilating--bundling][Lens scale (dilating / bundling)]]
     - [[#axis--tick-generators][Axis & tick generators]]
         - [[#common-axis-factory][Common axis factory]]
         - [[#linear][Linear]]
         - [[#logarithmic][Logarithmic]]
         - [[#lens-axis][Lens axis]]
     - [[#visualization-methods][Visualization methods]]
         - [[#line-plot][Line plot]]
         - [[#area-graph][Area graph]]
         - [[#radar-plot][Radar plot]]
         - [[#scatter-plot][Scatter plot]]
         - [[#contour-lines][Contour lines]]
         - [[#stacked-intervals][Stacked intervals]]
     - [[#2d-cartesian-plotting-svg][2D Cartesian Plotting (SVG)]]
         - [[#svg-axis-generators][SVG axis generators]]
         - [[#generic-plotting-helpers][Generic plotting helpers]]
     - [[#2d-polar-plotting-svg][2D Polar Plotting (SVG)]]
         - [[#svg-axis-generators][SVG axis generators]]
     - [[#projections][Projections]]
     - [[#value-transformations][Value transformations]]
     - [[#value-formatting][Value formatting]]
     - [[#custom-shapes][Custom shapes]]
     - [[#todo-3d-plotting][TODO 3D Plotting]]
     - [[#complete-namespace-definitions][Complete namespace definitions]]

* Namespace: thi.ng.geom.viz.core

** Example usage

This section shows some basic example outputs and general usage
patterns. See spec description in next section for further
information.

*** Running all examples from REPL

#+BEGIN_SRC clojure
  (->> ["scatter" "lineplot" "radar" "intervals" "timeline" "contours"]
       (map #(load-file (str "examples/" % ".clj")))
       dorun)
#+END_SRC

*** Namespaces required by all examples

#+BEGIN_SRC clojure :noweb-ref example-imports
  (require '[thi.ng.geom.viz.core :as viz] :reload)
  (require '[thi.ng.geom.svg.core :as svg])
  (require '[thi.ng.geom.core.vector :as v])
  (require '[thi.ng.math.core :as m :refer [PI]])
#+END_SRC

*** Scatter plot

| [[http://media.thi.ng/geom/viz/scatter-linear-3.svg]] | [[http://media.thi.ng/geom/viz/scatter-log-3.svg]] |

#+BEGIN_SRC clojure :tangle ../babel/examples/scatter.clj :noweb yes :mkdirp yes :padline no
  <<example-imports>>

  (defn export-viz
    [spec path]
    (->> spec
         (viz/svg-plot2d-cartesian)
         (svg/svg {:width 600 :height 600})
         (svg/serialize)
         (spit path)))

  (def spec
    {:x-axis (viz/log-axis
              {:domain [1 201] :range [50 590] :pos 550})
     :y-axis (viz/linear-axis
              {:domain [0.1 100] :range [550 20] :major 10 :minor 5 :pos 50
               :label-dist 15 :label {:text-anchor "end"}})
     :grid   {:attribs {:stroke "#caa"}
              :minor-x true
              :minor-y true}
     :data   [{:values  (map (juxt identity #(Math/sqrt %)) (range 0 200 2))
               :attribs {:fill "#0af" :stroke "none"}
               :layout  viz/svg-scatter-plot}
              {:values  (map (juxt identity #(m/random %)) (range 0 200 2))
               :attribs {:fill "none" :stroke "#f60"}
               :shape   (viz/svg-triangle-down 6)
               :layout  viz/svg-scatter-plot}]})

  (export-viz spec "scatter.svg")

  (-> spec
      (assoc :y-axis (viz/log-axis
                      {:domain [0.1 101] :range [550 20] :pos 50
                       :label-dist 15 :label {:text-anchor "end"}}))
      (export-viz "scatter-log.svg"))
#+END_SRC

*** Line & area plot

| [[http://media.thi.ng/geom/viz/lineplot-3.svg]] | [[http://media.thi.ng/geom/viz/areaplot-3.svg]] |
| Line plot (cartesian)                       | Line plot (polar)                           |

#+BEGIN_SRC clojure :tangle ../babel/examples/lineplot.clj :noweb yes :mkdirp yes :padline no
  <<example-imports>>

  (defn test-equation
    [t] (let [x (m/mix (- PI) PI t)] [x (* (Math/cos (* 0.5 x)) (Math/sin (* x x x)))]))

  (defn export-viz
    [viz path] (->> viz (svg/svg {:width 600 :height 320}) (svg/serialize) (spit path)))

  (def viz-spec
    {:x-axis (viz/linear-axis
              {:domain [(- PI) PI] :range [50 580] :major (/ PI 2) :minor (/ PI 4) :pos 250})
     :y-axis (viz/linear-axis
              {:domain [-1 1] :range [250 20] :major 0.2 :minor 0.1 :pos 50
               :label-dist 15 :label {:text-anchor "end"}})
     :grid   {:attribs {:stroke "#caa"}
              :minor-y true}
     :data   [{:values  (map test-equation (m/norm-range 200))
               :attribs {:fill "none" :stroke "#0af"}
               :layout  viz/svg-line-plot}]})

  (-> viz-spec
      (viz/svg-plot2d-cartesian)
      (export-viz "lineplot.svg"))

  ;; same spec, just update style attribs & layout method
  (-> viz-spec
      (update-in [:data 0] merge {:attribs {:fill "#0af"} :layout viz/svg-area-plot})
      (viz/svg-plot2d-cartesian)
      (export-viz "areaplot.svg"))
#+END_SRC

Same overall visualization setup, only using polar coordinate transform and redefined axis ranges (in radians)...

| [[http://media.thi.ng/geom/viz/lineplot-polar-3.svg]] | [[http://media.thi.ng/geom/viz/areaplot-polar-3.svg]] |
| Area plot (cartesian)                             | Area plot (polar)                                 |

#+BEGIN_SRC clojure :tangle ../babel/examples/lineplot.clj :padline yes
  (def viz-spec-polar
    {:x-axis (viz/linear-axis
              {:domain [(- PI) PI] :range [(* 1.1 PI) (* 1.9 PI)]
               :major (/ PI 2) :minor (/ PI 16) :pos 280})
     :y-axis (viz/linear-axis
              {:domain [-1 1] :range [60 280]
               :major 0.5 :minor 0.25 :pos (* 1.1 PI)})
     :origin (v/vec2 300 310)
     :grid   {:attribs {:stroke "#caa" :fill "none"}
              :minor-x true
              :minor-y true}
     :data   [{:values  (map test-equation (m/norm-range 200))
               :attribs {:fill "none" :stroke "#0af"}
               :layout  viz/svg-line-plot}]})

  (-> viz-spec-polar (viz/svg-plot2d-polar) (export-viz "lineplot-polar.svg"))

  ;; same spec, just update style attribs & layout method
  (-> viz-spec-polar
      (update-in [:data 0] merge {:attribs {:fill "#0af"} :res 20 :layout viz/svg-area-plot})
      (viz/svg-plot2d-polar)
      (export-viz "areaplot-polar.svg"))
#+END_SRC

*** Radar plot

http://media.thi.ng/geom/viz/radarplot-3.svg

#+BEGIN_SRC clojure :tangle ../babel/examples/radar.clj :noweb yes :mkdirp yes :padline no
  <<example-imports>>
  (require '[clojure.set :as set])
  (require '[clojure.string :as str])

  (def category->domain (zipmap [:c1 :c2 :c3 :c4 :c5 :c6] (range)))<commit_msg>[viz] update image links<commit_after>#+SETUPFILE: ../../src/setup.org

* Contents                                                         :toc_4_gh:
 - [[#namespace-thinggeomvizcore][Namespace: thi.ng.geom.viz.core]]
     - [[#example-usage][Example usage]]
         - [[#running-all-examples-from-repl][Running all examples from REPL]]
         - [[#namespaces-required-by-all-examples][Namespaces required by all examples]]
         - [[#scatter-plot][Scatter plot]]
         - [[#line--area-plot][Line & area plot]]
         - [[#radar-plot][Radar plot]]
         - [[#stacked-intervals][Stacked intervals]]
             - [[#plain-intervals][Plain intervals]]
             - [[#categorized-timeline][Categorized timeline]]
         - [[#contour-plot][Contour plot]]
     - [[#visualization-spec-format][Visualization spec format]]
         - [[#axis-definitions-x-axis--y-axis][Axis definitions (:x-axis / :y-axis)]]
             - [[#notes-for-polar-projection][Notes for polar projection]]
             - [[#default-axis-label-styling][Default axis label styling]]
         - [[#axis-grid-definition-grid][Axis grid definition (:grid)]]
         - [[#dataset-specs-data][Dataset specs (:data)]]
     - [[#scales][Scales]]
         - [[#linear-scale][Linear scale]]
         - [[#logarithmic-scale][Logarithmic scale]]
         - [[#lens-scale-dilating--bundling][Lens scale (dilating / bundling)]]
     - [[#axis--tick-generators][Axis & tick generators]]
         - [[#common-axis-factory][Common axis factory]]
         - [[#linear][Linear]]
         - [[#logarithmic][Logarithmic]]
         - [[#lens-axis][Lens axis]]
     - [[#visualization-methods][Visualization methods]]
         - [[#line-plot][Line plot]]
         - [[#area-graph][Area graph]]
         - [[#radar-plot][Radar plot]]
         - [[#scatter-plot][Scatter plot]]
         - [[#contour-lines][Contour lines]]
         - [[#stacked-intervals][Stacked intervals]]
     - [[#2d-cartesian-plotting-svg][2D Cartesian Plotting (SVG)]]
         - [[#svg-axis-generators][SVG axis generators]]
         - [[#generic-plotting-helpers][Generic plotting helpers]]
     - [[#2d-polar-plotting-svg][2D Polar Plotting (SVG)]]
         - [[#svg-axis-generators][SVG axis generators]]
     - [[#projections][Projections]]
     - [[#value-transformations][Value transformations]]
     - [[#value-formatting][Value formatting]]
     - [[#custom-shapes][Custom shapes]]
     - [[#todo-3d-plotting][TODO 3D Plotting]]
     - [[#complete-namespace-definitions][Complete namespace definitions]]

* Namespace: thi.ng.geom.viz.core

** Example usage

This section shows some basic example outputs and general usage
patterns. See spec description in next section for further
information.

*** Running all examples from REPL

#+BEGIN_SRC clojure
  (->> ["scatter" "lineplot" "radar" "intervals" "timeline" "contours"]
       (map #(load-file (str "examples/" % ".clj")))
       dorun)
#+END_SRC

*** Namespaces required by all examples

#+BEGIN_SRC clojure :noweb-ref example-imports
  (require '[thi.ng.geom.viz.core :as viz] :reload)
  (require '[thi.ng.geom.svg.core :as svg])
  (require '[thi.ng.geom.core.vector :as v])
  (require '[thi.ng.math.core :as m :refer [PI]])
#+END_SRC

*** Scatter plot

| [[http://media.thi.ng/geom/viz/scatter-linear-3.svg]] | [[http://media.thi.ng/geom/viz/scatter-log-3.svg]] |

#+BEGIN_SRC clojure :tangle ../babel/examples/scatter.clj :noweb yes :mkdirp yes :padline no
  <<example-imports>>

  (defn export-viz
    [spec path]
    (->> spec
         (viz/svg-plot2d-cartesian)
         (svg/svg {:width 600 :height 600})
         (svg/serialize)
         (spit path)))

  (def spec
    {:x-axis (viz/log-axis
              {:domain [1 201] :range [50 590] :pos 550})
     :y-axis (viz/linear-axis
              {:domain [0.1 100] :range [550 20] :major 10 :minor 5 :pos 50
               :label-dist 15 :label {:text-anchor "end"}})
     :grid   {:attribs {:stroke "#caa"}
              :minor-x true
              :minor-y true}
     :data   [{:values  (map (juxt identity #(Math/sqrt %)) (range 0 200 2))
               :attribs {:fill "#0af" :stroke "none"}
               :layout  viz/svg-scatter-plot}
              {:values  (map (juxt identity #(m/random %)) (range 0 200 2))
               :attribs {:fill "none" :stroke "#f60"}
               :shape   (viz/svg-triangle-down 6)
               :layout  viz/svg-scatter-plot}]})

  (export-viz spec "scatter-linear.svg")

  (-> spec
      (assoc :y-axis (viz/log-axis
                      {:domain [0.1 101] :range [550 20] :pos 50
                       :label-dist 15 :label {:text-anchor "end"}}))
      (export-viz "scatter-log.svg"))
#+END_SRC

*** Line & area plot

| [[http://media.thi.ng/geom/viz/lineplot-3.svg]] | [[http://media.thi.ng/geom/viz/areaplot-3.svg]] |
| Line plot (cartesian)                       | Line plot (polar)                           |

#+BEGIN_SRC clojure :tangle ../babel/examples/lineplot.clj :noweb yes :mkdirp yes :padline no
  <<example-imports>>

  (defn test-equation
    [t] (let [x (m/mix (- PI) PI t)] [x (* (Math/cos (* 0.5 x)) (Math/sin (* x x x)))]))

  (defn export-viz
    [viz path] (->> viz (svg/svg {:width 600 :height 320}) (svg/serialize) (spit path)))

  (def viz-spec
    {:x-axis (viz/linear-axis
              {:domain [(- PI) PI] :range [50 580] :major (/ PI 2) :minor (/ PI 4) :pos 250})
     :y-axis (viz/linear-axis
              {:domain [-1 1] :range [250 20] :major 0.2 :minor 0.1 :pos 50
               :label-dist 15 :label {:text-anchor "end"}})
     :grid   {:attribs {:stroke "#caa"}
              :minor-y true}
     :data   [{:values  (map test-equation (m/norm-range 200))
               :attribs {:fill "none" :stroke "#0af"}
               :layout  viz/svg-line-plot}]})

  (-> viz-spec
      (viz/svg-plot2d-cartesian)
      (export-viz "lineplot.svg"))

  ;; same spec, just update style attribs & layout method
  (-> viz-spec
      (update-in [:data 0] merge {:attribs {:fill "#0af"} :layout viz/svg-area-plot})
      (viz/svg-plot2d-cartesian)
      (export-viz "areaplot.svg"))
#+END_SRC

Same overall visualization setup, only using polar coordinate transform and redefined axis ranges (in radians)...

| [[http://media.thi.ng/geom/viz/lineplot-polar-3.svg]] | [[http://media.thi.ng/geom/viz/areaplot-polar-3.svg]] |
| Area plot (cartesian)                             | Area plot (polar)                                 |

#+BEGIN_SRC clojure :tangle ../babel/examples/lineplot.clj :padline yes
  (def viz-spec-polar
    {:x-axis (viz/linear-axis
              {:domain [(- PI) PI] :range [(* 1.1 PI) (* 1.9 PI)]
               :major (/ PI 2) :minor (/ PI 16) :pos 280})
     :y-axis (viz/linear-axis
              {:domain [-1 1] :range [60 280]
               :major 0.5 :minor 0.25 :pos (* 1.1 PI)})
     :origin (v/vec2 300 310)
     :grid   {:attribs {:stroke "#caa" :fill "none"}
              :minor-x true
              :minor-y true}
     :data   [{:values  (map test-equation (m/norm-range 200))
               :attribs {:fill "none" :stroke "#0af"}
               :layout  viz/svg-line-plot}]})

  (-> viz-spec-polar (viz/svg-plot2d-polar) (export-viz "lineplot-polar.svg"))

  ;; same spec, just update style attribs & layout method
  (-> viz-spec-polar
      (update-in [:data 0] merge {:attribs {:fill "#0af"} :res 20 :layout viz/svg-area-plot})
      (viz/svg-plot2d-polar)
      (export-viz "areaplot-polar.svg"))
#+END_SRC

*** Radar plot

[[http://media.thi.ng/geom/viz/radarplot-3.svg]]

#+BEGIN_SRC clojure :tangle ../babel/examples/radar.clj :noweb yes :mkdirp yes :padline no
  <<example-imports>>
  (require '[clojure.set :as set])
  (require '[clojure.string :as str])

  (def category->domain (zipmap [:c1 :c2 :c3 :c4 :c5 :c6] (range)))
{'fraction_non_alphanumeric': 0.17863566289825283, 'fraction_numerical': 0.02132579650565262, 'mean_word_length': 2.3517761033369213, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1419414', 'n_tokens_mistral': 5805, 'n_tokens_neox': 5309, 'n_words': 1208}