Here is my code so far. I want you to extend it with more graphs that call back to the…
- User
Here is my code so far. I want you to extend it with more graphs that call back to the same profit data or create new data for them.
(ns apexchartsdemo.core (:require [reagent.core :as r] [reagent.dom :as rdom] [goog.events :as events] [goog.history.EventType :as HistoryEventType] [markdown.core :refer [md->html]] [apexchartsdemo.ajax :as ajax] [ajax.core :refer [GET POST]] [reitit.core :as reitit] [clojure.string :as string] ["react-apexcharts$default" :as Chart]) (:import goog.History))
(def chart (r/adapt-react-class Chart))
(defonce session (r/atom {:page :home}))
(defn nav-link [uri title page] [:a.navbar-item {:href uri :class (when (= page (:page @session)) "is-active")} title])
(defn navbar [] (r/with-let [expanded? (r/atom false)] [:nav.navbar.is-info>div.container [:div.navbar-brand [:a.navbar-item {:href "/" :style {:font-weight :bold}} "Apex Charts demo"] [:span.navbar-burger.burger {:data-target :nav-menu :on-click #(swap! expanded? not) :class (when @expanded? :is-active)} [:span][:span][:span]]] [:div#nav-menu.navbar-menu {:class (when @expanded? :is-active)} [:div.navbar-start [nav-link "#/" "Home" :home] [nav-link "#/about" "About" :about]]]]))
(defn about-page [] [:section.section>div.container>div.content [:img {:src "/img/warning_clojure.png"}]])
(defn random-team-profit [] (map #(+ 10000 %) (repeatedly 5 (fn [] (rand-int 70000)))))
(def profit-series (r/atom {2018 (random-team-profit) 2019 (random-team-profit) 2020 (random-team-profit) 2021 (random-team-profit) 2022 (random-team-profit) 2023 (random-team-profit)}))
(defn totals-per-year [profit-series-atom] (map #(reduce + %) (vals profit-series-atom))) (defn profit-of-year [profit-series-atom year] (reduce + (profit-series-atom year))) (defn team-contribution [profit-series-atom year] (profit-series-atom year))
;; atoms and etc (def my-reagent-atom (r/atom 123)) (def year-val (r/atom 2023))
(defn slider-on-change-handler [js-event] (reset! year-val (-> js-event .-target .-value)))
;; Pie Chart data atoms (def pie-chart-options (r/atom {:chart {:width 380 :type "pie"} :labels ["Team A", "Team B", "Team C", "Team D", "Team E"] :responsive [{:breakpoint 480 :options {:chart {:width 200} :legend {:position "bottom"}}}]})) ;; Area Chart data atoms (def area-chart-series (r/atom [{:name "Series 1" :data [31, 40, 28, 51, 42, 109, 100]}])) (def area-chart-options (r/atom {:chart {:height 350 :type "area"} :dataLabels {:enabled false} :stroke {:curve "smooth"} :xaxis {:type "datetime" :categories ["2018-09-19T00:00:00", "2018-09-19T01:30:00", "2018-09-19T02:30:00", "2018-09-19T03:30:00", "2018-09-19T04:30:00", "2018-09-19T05:30:00", "2018-09-19T06:30:00"]}}))
;; (def year-slider-low-val (r/atom 2010)) ;; (def year-slider-high-val (r/atom 2015))
;; (defn year-slider-on-change-handler-low [js-event] ;; (let [new-val (js/parseInt (-> js-event .-target .-value))] ;; (when (< new-val @year-slider-high-val) ;; (reset! year-slider-low-val new-val))))
- Assistant
- User
Can you convert this chart to ClojureScript?
codeoptions: { chart: { height: 350, type: 'rangeBar' }, plotOptions: { bar: { horizontal: true } }, dataLabels: { enabled: true, formatter: function(val) { var a = moment(val[0]) var b = moment(val[1]) var diff = b.diff(a, 'days') return diff + (diff > 1 ? ' days' : ' day') } }, fill: { type: 'gradient', gradient: { shade: 'light', type: 'vertical', shadeIntensity: 0.25, gradientToColors: undefined, inverseColors: true, opacityFrom: 1, opacityTo: 1, stops: [50, 0, 100, 100] } }, xaxis: { type: 'datetime' }, legend: { position: 'top' } }, }; } - Assistant
To convert the provided JavaScript chart configuration to ClojureScript, you'll need to translate the JavaScript object into a ClojureScript map and adapt the formatter function to use ClojureScript syntax.
- User
Here is the data to use, please format it.
series: [ { name: 'Bob', data: [ { x: 'Design', y: [ new Date('2019-03-05').getTime(), new Date('2019-03-08').getTime() ] }, { x: 'Code', y: [ new Date('2019-03-08').getTime(), new Date('2019-03-11').getTime() ] }, { x: 'Test', y: [ new Date('2019-03-11').getTime(), new Date('2019-03-16').getTime() ] } ] }, { name: 'Joe', data: [ { x: 'Design', y: [ new Date('2019-03-02').getTime(), new Date('2019-03-05').getTime() ] }, { x: 'Code', y: [ new Date('2019-03-06').getTime(), new Date('2019-03-09').getTime() ] }, { x: 'Test', y: [ new Date('2019-03-10').getTime(), new Date('2019-03-19').getTime() ] } ] } ],
- Assistant