Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
clj-xchart/src/clj/com/hypirion/clj_xchart/specs.clj
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
40 lines (35 sloc)
1.66 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns com.hypirion.clj-xchart.specs | |
(:require [clojure.spec.alpha :as s] | |
[com.hypirion.clj-xchart :as c] | |
[com.hypirion.clj-xchart.specs.series :as series] | |
[com.hypirion.clj-xchart.specs.series.bubble :as bubble] | |
[com.hypirion.clj-xchart.specs.series.category :as category] | |
[com.hypirion.clj-xchart.specs.series.xy :as xy] | |
[com.hypirion.clj-xchart.specs.styling :as sty])) | |
(defn styling-matches-series? | |
"Styling can only talk about as many series as there are series." | |
[{:keys [series style]}] | |
(<= (count (:series style)) | |
(count (:x series)))) | |
;; without spec, this fails xchart validation on AWT thread | |
(defmulti series-compatible-with-render-style? | |
"Is series data compatible with chart render style?" | |
(fn [{:keys [series style]}] (:render-style style))) | |
(defmethod series-compatible-with-render-style? :default | |
[_] | |
true) | |
(defmethod series-compatible-with-render-style? [:area] | |
[{:keys [series]}] | |
(every? | |
(fn [{:keys [x style]}] | |
(or (:render-style style) | |
(series/ordered? (second x)))) | |
(vals series))) | |
(s/def ::xy-chart-args (s/and (s/cat :series ::xy/series :style (s/? ::sty/xy-styling)) | |
styling-matches-series? | |
series-compatible-with-render-style?)) | |
(s/fdef c/xy-chart :args ::xy-chart-args) | |
(s/def ::bubble-chart*-args (s/and (s/cat :series ::bubble/series :style ::sty/bubble-styling) | |
styling-matches-series?)) | |
(s/def ::category-chart-args (s/and (s/cat :series ::category/series :style ::sty/category-styling) | |
styling-matches-series?)) |