lynaghk / c2 Goto Github PK
View Code? Open in Web Editor NEWDeclarative data visualization in Clojure(Script).
Home Page: http://keminglabs.com/c2/
License: Other
Declarative data visualization in Clojure(Script).
Home Page: http://keminglabs.com/c2/
License: Other
Hi Kevin, hi all.
SVG elements seem not to be properly rendered in c2.util/bind!, maybe a problem due to singult as in singult's issue#7. I have uploaded on https://github.com/sinapsi-srl/binding-issue a minimal project to show the problem.
Version: [com.keminglabs/c2 "0.2.2"]
When I try to bind!
anything at all to a div in my page, the page trips over an unexpectedly null element in singult.coffee.merge. The specific thing I'm trying is (bind! "#content" [:p "Meaningful content."])
. If you want, you can also look at the repo for the (currently toy) project.
This looks like a bug in singult, but I'm opening an issue c2 because that's the dependency I'm pulling in.
Samples should use more svg helpers like translate
instead of doing inline string interpolation.
The majority of C2 source is being ported to .cljx
files that can be statically transformed into the appropriate .clj
and .cljs
files.
Consumers using the library as a JAR don't need to know about any of this, but it's central for development.
See emezeske/lein-cljsbuild#49 for more background, and leave a comment here if you think this is a great/terrible idea.
Something like this
[:p "Intermediate Speed Shaft" [:br] "Generator End Bearing"]
works the first time, but not on updates.
The hiccup vector
[x.a.b {:class "c"}]
should render into
<x class="a b c"></x>
Reported via an email:
I would like to point out that I've just run the 'c2-demos/hello-bars' you published on your github page and the bar visualization (sizing) fails if you add a doctype declaration
<!DOCTYPE html>
or
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
to the html file 'hello-bars/public/index.html'.
...Otherwise the geo->svg function doesn't work, probably due to an issue with core.match
Could you state a license by which the code can be used?
Thanks,
Hen
The geo->svg
fn is a ton of string concatenation and array joins.
Likely possible to get massive perf boost from coercing to JavaScript arrays and using browser native #join method.
Example have (:use [c2.core :only [unify style]]), code do not have "style" function.
Am I'm missing something?
Server-side hiccup doesn't care about namespaces (e.g., [:svg:g]
) but in ClojureScript you need 'em for the correct DOM nodes to be generated.
This should be resolved so that pure Clojure SVG visualizations can be used in either place verbatim.
The sunburst example does not use the previously defined color-scale but just uses hardcoded "white"
Top two fns of a mapping run are both cljs.core lookups. Using records should make this much faster.
(copied from email)
Seems like C2's (-seq) hack for NodeLists no longer works with
advanced compilation, is that consistent with your observations?
Cheers,
Stephen
http://keminglabs.com/c2/docs/ redirects to http://keminglabs.com/
The hiccup style vectors only support two classes.
Doing the following in clojurescript
(bind! "#my-id"
[:div.a.b.c "hello"])
will create
<div class="a b.c">hello</div>
This is using the 0.2.0 version from clojars.
Just started working with this library and seems pretty awesome thus far!
One question right now:
I have a list of albums on a page. Each album has a button beside it to add it:
ul.albums
li
button.add
li
button.add
However. When I do a function like:
(event/on-raw ".add" :click
(fn [e]
(swap! !playlist conj {:title "aotueh"})))
It only gets called for when I click add for the first album in the list. How can I make it work for all of them?
This should do the appropriate CDATA magic too, for inline SVG stylesheets.
I have included:
[com.keminglabs/c2 "0.0.1-SNAPSHOT"]
in my project file, but I get a:
ERROR - required "c2.core" namespace never provided goog.require('c2.core');
when trying to use/require like so:
(:use [c2.core :only [unify style]])
(:require [c2.scale :as scale])
Currently this proxies to the clj->js in Singult, but that needs to be optimized for speed.
Bring back a separate clj->js fn to C2, and implement using Protocols so that users can define lossy conversions from Clojure datastructures to JavaScript objects themselves.
You shouldn't have to write
[:span (str 4)]
The first example (bar chart) on http://keminglabs.com/c2/ should be updated to remove use of c2.core/style
which has apparently been removed.
(also, a complete worked-out cljs example for the bar chart would be great).
Cheers
Right now it's possible for things like (translate [x y])
to return "translate(5/2,3)", and SVG doesn't appreciate the ratio.
Need to write our own to-string protocol for the Clojure side of things to automatically print everything as floats.
See weavejester/hiccup@06746b8.
This may require a change in the cljx plugin to parse subforms, if we want to just copy hiccup's implementation.
Scales should have an option to clamp inputs from outside of their domain.
[tw-mbp13-nmahendran Desktop]$ lein version
Leiningen 1.7.1 on Java 1.6.0_31 Java HotSpot(TM) 64-Bit Server VM
This is the latest version provided by Homebrew.
[tw-mbp13-nmahendran Desktop]$ git clone [email protected]:nybbles/c2.git
Cloning into c2...
remote: Counting objects: 951, done.
remote: Compressing objects: 100% (500/500), done.
remote: Total 951 (delta 429), reused 835 (delta 314)
Receiving objects: 100% (951/951), 130.36 KiB, done.
Resolving deltas: 100% (429/429), done.
[tw-mbp13-nmahendran Desktop]$ cd c2/
[tw-mbp13-nmahendran c2 (master)]$ lein deps
Copying 8 files to /Users/nimalan/Desktop/c2/.lein-plugins
Copying 4 files to /Users/nimalan/Desktop/c2/lib
lein midje --autotest
lein midje --autotest
[tw-mbp13-nmahendran c2 (master)]$ lein midje --autotest
That's not a task. Use "lein help" to list all tasks.
lein cljsbuild test
[tw-mbp13-nmahendran c2 (master)]$ lein cljsbuild test
Compiling ClojureScript.
(Compiling out/test/integration.js from test/integration/cljs...)
( Failed!)
java.io.FileNotFoundException: Could not locate c2/util__init.class or c2/util.clj on classpath:
RT.java:430 clojure.lang.RT.load
RT.java:398 clojure.lang.RT.load
core.clj:5386 clojure.core/load[fn]
core.clj:5385 clojure.core/load
RestFn.java:408 clojure.lang.RestFn.invoke
core.clj:5200 clojure.core/load-one
core.clj:5237 clojure.core/load-lib
RestFn.java:142 clojure.lang.RestFn.applyTo
core.clj:602 clojure.core/apply
core.clj:5271 clojure.core/load-libs
RestFn.java:137 clojure.lang.RestFn.applyTo
core.clj:602 clojure.core/apply
core.clj:5352 clojure.core/require
RestFn.java:408 clojure.lang.RestFn.invoke
compiler.clj:874 cljs.compiler/eval1145[fn]
MultiFn.java:177 clojure.lang.MultiFn.invoke
compiler.clj:1076 cljs.compiler/analyze-seq
compiler.clj:1129 cljs.compiler/analyze
compiler.clj:1122 cljs.compiler/analyze
compiler.clj:1189 cljs.compiler/compile-file*
compiler.clj:1227 cljs.compiler/compile-file
compiler.clj:1288 cljs.compiler/compile-root
closure.clj:367 cljs.closure/compile-dir
closure.clj:399 cljs.closure/eval1742[fn]
closure.clj:266 cljs.closure/eval1670[fn]
closure.clj:413 cljs.closure/eval1729[fn]
closure.clj:266 cljs.closure/eval1670[fn]
closure.clj:872 cljs.closure/build
compiler.clj:52 cljsbuild.compiler/compile-cljs[fn]
compiler.clj:51 cljsbuild.compiler/compile-cljs
compiler.clj:70 cljsbuild.compiler/run-compiler
NO_SOURCE_FILE:1 user/eval2146[fn]
util.clj:31 cljsbuild.util/in-threads[fn]
core.clj:1817 clojure.core/binding-conveyor-fn[fn]
AFn.java:18 clojure.lang.AFn.call
FutureTask.java:303 java.util.concurrent.FutureTask$Sync.innerRun
FutureTask.java:138 java.util.concurrent.FutureTask.run
ThreadPoolExecutor.java:886 java.util.concurrent.ThreadPoolExecutor$Worker.runTask
ThreadPoolExecutor.java:908 java.util.concurrent.ThreadPoolExecutor$Worker.run
Thread.java:680 java.lang.Thread.run
Running all ClojureScript tests.
Exception in thread "main" java.lang.RuntimeException: java.io.IOException: Cannot run program "phantomjs": error=2, No such file or directory
at clojure.lang.Util.runtimeException(Util.java:165)
at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:35)
at cljsbuild.util$process_start.invoke(util.clj:70)
at cljsbuild.util$sh.invoke(util.clj:80)
at cljsbuild.test$run_tests$iter__180__184$fn__185.invoke(test.clj:11)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:60)
at clojure.lang.RT.seq(RT.java:466)
at clojure.core$seq.invoke(core.clj:133)
at clojure.core$dorun.invoke(core.clj:2723)
at clojure.core$doall.invoke(core.clj:2739)
at cljsbuild.test$run_tests.invoke(test.clj:10)
at user$eval221.invoke(NO_SOURCE_FILE:1)
at clojure.lang.Compiler.eval(Compiler.java:6465)
at clojure.lang.Compiler.eval(Compiler.java:6455)
at clojure.lang.Compiler.eval(Compiler.java:6431)
at clojure.core$eval.invoke(core.clj:2795)
at clojure.main$eval_opt.invoke(main.clj:296)
at clojure.main$initialize.invoke(main.clj:315)
at clojure.main$null_opt.invoke(main.clj:348)
at clojure.main$main.doInvoke(main.clj:426)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:405)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.Var.applyTo(Var.java:518)
at clojure.main.main(main.java:37)
Caused by: java.io.IOException: Cannot run program "phantomjs": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at java.lang.Runtime.exec(Runtime.java:593)
at java.lang.Runtime.exec(Runtime.java:466)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:92)
at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:30)
... 24 more
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:53)
at java.lang.ProcessImpl.start(ProcessImpl.java:91)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
... 32 more
[tw-mbp13-nmahendran c2 (master)]$
lein cljsbuild once
[tw-mbp13-nmahendran c2 (master)]$ lein cljsbuild once
Compiling ClojureScript.
(Compiling out/test/integration.js from test/integration/cljs...)
( Failed!)
java.io.FileNotFoundException: Could not locate c2/util__init.class or c2/util.clj on classpath:
RT.java:430 clojure.lang.RT.load
RT.java:398 clojure.lang.RT.load
core.clj:5386 clojure.core/load[fn]
core.clj:5385 clojure.core/load
RestFn.java:408 clojure.lang.RestFn.invoke
core.clj:5200 clojure.core/load-one
core.clj:5237 clojure.core/load-lib
RestFn.java:142 clojure.lang.RestFn.applyTo
core.clj:602 clojure.core/apply
core.clj:5271 clojure.core/load-libs
RestFn.java:137 clojure.lang.RestFn.applyTo
core.clj:602 clojure.core/apply
core.clj:5352 clojure.core/require
RestFn.java:408 clojure.lang.RestFn.invoke
compiler.clj:874 cljs.compiler/eval1145[fn]
MultiFn.java:177 clojure.lang.MultiFn.invoke
compiler.clj:1076 cljs.compiler/analyze-seq
compiler.clj:1129 cljs.compiler/analyze
compiler.clj:1122 cljs.compiler/analyze
compiler.clj:1189 cljs.compiler/compile-file*
compiler.clj:1227 cljs.compiler/compile-file
compiler.clj:1288 cljs.compiler/compile-root
closure.clj:367 cljs.closure/compile-dir
closure.clj:399 cljs.closure/eval1742[fn]
closure.clj:266 cljs.closure/eval1670[fn]
closure.clj:413 cljs.closure/eval1729[fn]
closure.clj:266 cljs.closure/eval1670[fn]
closure.clj:872 cljs.closure/build
compiler.clj:52 cljsbuild.compiler/compile-cljs[fn]
compiler.clj:51 cljsbuild.compiler/compile-cljs
compiler.clj:70 cljsbuild.compiler/run-compiler
NO_SOURCE_FILE:1 user/eval2146[fn]
util.clj:31 cljsbuild.util/in-threads[fn]
core.clj:1817 clojure.core/binding-conveyor-fn[fn]
AFn.java:18 clojure.lang.AFn.call
FutureTask.java:303 java.util.concurrent.FutureTask$Sync.innerRun
FutureTask.java:138 java.util.concurrent.FutureTask.run
ThreadPoolExecutor.java:886 java.util.concurrent.ThreadPoolExecutor$Worker.runTask
ThreadPoolExecutor.java:908 java.util.concurrent.ThreadPoolExecutor$Worker.run
Thread.java:680 java.lang.Thread.run
[tw-mbp13-nmahendran c2 (master)]$
Functions in c2.dom should be consistent about what subset of {live elements, css selectors, hiccup vectors, hiccup maps} they accept as arguments.
Hi Kevin,
this link http://keminglabs.com/c2/docs/ goes to http://keminglabs.com/
is this behavior normal or definitive?
Is there other way to generate or access the documented source?
thanks in advance
have a good day!
Hi Kevin,
I tried run lein cljsbuild
with c2 version "0.2.3-SNAPSHOT". It gives the following error:
WARNING: Use of undeclared Var c2.dom/e__3480__auto__ at line 112 file:/***/.m2/repository/com/keminglabs/c2/0.2.3-SNAPSHOT/c2-0.2.3-SNAPSHOT.jar!/c2/dom.cljs
Compiling "resources/public/js/binding_issue.js" failed.
clojure.lang.ExceptionInfo: Assert failed: Can't qualify symbol in catch
(not (namespace name)) at line 112 file:/***/.m2/repository/com/keminglabs/c2/0.2.3-SNAPSHOT/c2-0.2.3-SNAPSHOT.jar!/c2/dom.cljs
It seems that the error is caused by the dependency
[org.clojure/core.match "0.2.0-alpha12" :exclusions [org.clojure/core.logic]]
in project.clj
. Reverting to
[org.clojure/core.match "0.2.0-alpha11" :exclusions [org.clojure/clojure org.clojure/core.logic]]
seems to fix the error.
Bye,
Federico
The following project is providing an API for multi-dimensional data / arrays / matrices in Clojure in a way that will hopefully be able to unify different matrix implementations in Clojure with a common abstraction:
It would be great if c2 could at some point gain the ability to visualise core.matrix data. In particular, this would make it easy for c2 to visualise data regardless of the underlying matrix / data format.
Note that there are also plans to port Incanter to use core.matrix, so there may also be some synergies there.
Hey Kevin.
I was integrating C2 into a work project and discovered that things don't seem to work with more recent versions of ClojureScript.
For example, if you upgrade the hello-bars demo then clean target/
and public/out/
you will find the project can no longer cljsbuild.
diff --git a/hello-bars/project.clj b/hello-bars/project.clj
index 90c8b76..a982bc5 100644
--- a/hello-bars/project.clj
+++ b/hello-bars/project.clj
@@ -1,9 +1,8 @@
(defproject hello-bars "0.0.1-SNAPSHOT"
:description "hello-bars: c2 at its simplest"
- :dependencies [[org.clojure/clojure "1.4.0"]
+ :dependencies [[org.clojure/clojure "1.5.1"]
+ [org.clojure/clojurescript "0.0-2138"]
Result:
Compiling "public/out/hello-bars.js" from "src/cljs"...
Compiling "public/out/hello-bars.js" failed:
clojure.lang.ExceptionInfo: failed compiling file:src/cljs/hello_bars/core.cljs
core.clj:4327 clojure.core/ex-info
compiler.clj:1005 cljs.compiler/compile-file
compiler.clj:1057 cljs.compiler/compile-root
# ...
Caused by: clojure.lang.ExceptionInfo: clojure.lang.Cons cannot be cast to clojure.lang.Named at line 109 file:/Users/ryan/.m2/repository/com/keminglabs/c2/0.2.1/c2-0.2.1.jar!/c2/dom.cljs
core.clj:4327 clojure.core/ex-info
analyzer.clj:265 cljs.analyzer/error
analyzer.clj:1414 cljs.analyzer/analyze-seq
analyzer.clj:1505 cljs.analyzer/analyze[fn]
...
(Since there doesn't seem to be a 0.2.1 tag, I bumped to 0.2.2 and the line in question is dom.cljs#112)
It seems to be something to do with core.match. Can you make anything of this?
The following call results in an endless loop (clojurescript):
(c2.ticks/search [same-number same-number]) e.g. (c2.ticks/search [0 0])
So testing for (= d-min d-max) and returning an empty default seems to be a reasonable thing to do.
Version: [com.keminglabs/c2 "0.2.2"]
In CLJ hiccup seqs are "exploded" into the containing body:
(html [:ul (map (fn [d] [:li d])] (range 3))])
is treated the same as
(html [:ul
[:li 1]
[:li 2]
[:li 3]])
C2 clientside should do likewise, so people don't have to expand manually using (into)
.
The watcher key is hardcoded, so the last visualization with an atom data source will overwrite the previous watcher.
This is used by the c2 event handlers:
https://github.com/lynaghk/c2/blob/master/src/cljs/c2/dom.cljs#L52
Check if this functionality is provided in Google's Closure or can otherwise be abstracted out so other browsers don't get angry.
Hi,
I ran into errors using c2 with recent clojurescript versions. For example if I make the following patch to the c2-demos/hello-bars
project.clj
:
(defproject hello-bars "0.0.1-SNAPSHOT"
:description "hello-bars: c2 at its simplest"
- :dependencies [[org.clojure/clojure "1.4.0"]
- [com.keminglabs/c2 "0.2.1"]]
+ :dependencies [[org.clojure/clojure "1.5.1"]
+ [org.clojure/clojurescript "0.0-2227"]
+ [com.keminglabs/c2 "0.2.3"]]
:min-lein-version "2.0.0"
:source-paths ["src/clj"]
- :plugins [[lein-cljsbuild "0.2.7"]]
+ :plugins [[lein-cljsbuild "1.0.3"]]
Then I get the following from lein cljsbuild
:
Compiling "public/out/hello-bars.js" from ["src/cljs"]...
WARNING: Referred macro reflex.macros/capture-derefed does not exist at line 1 file:/home/felix/.m2/repository/com/keminglabs/reflex/0.1.1/reflex-0.1.1.jar!/reflex/core.cljs
WARNING: No such namespace: singult.coffee at line 1 file:/home/felix/.m2/repository/com/keminglabs/singult/0.1.6/singult-0.1.6.jar!/singult/core.cljs
WARNING: No such namespace: singult.coffee at line 1 /home/felix/devel/c2-demos/hello-bars/target/cljsbuild-compiler-0/singult/core.cljs
WARNING: Referred macro reflex.macros/capture-derefed does not exist at line 1 /home/felix/devel/c2-demos/hello-bars/target/cljsbuild-compiler-0/reflex/core.cljs
And fatal runtime errors:
Uncaught Error: goog.require could not find: singult.coffee
I'm not sure how to go about investigating this.
Best
Felix
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.