Unify! and variable number of points

35 views
Skip to first unread message

Daniel Woelfel

unread,
Jul 27, 2012, 9:01:21 PM7/27/12
to c2-...@googlegroups.com
I'm using unify! to create a scatterplot with c2 0.2.0. The data is stored in an atom, which is reset! with new data. Points from the old data set will stick around if my new data set has fewer points than the previous data set. 

How can I prevent this from happening? Is there some way to make c2 view a container as a cohesive whole?

Kevin Lynagh

unread,
Jul 27, 2012, 9:10:45 PM7/27/12
to c2-...@googlegroups.com
Hi Daniel,

Unify takes an optional :key-fn that it uses to track identity when data changes.
It defaults to just using index, which can be a problem if (as you've discovered) the newer dataset has fewer elements than the old.
If your data has something like a database primary key id, you can use that:

(unify my-data mapping :key-fn #(:id %))

you can also force unify to update everything every time its run by saying ":force-update? true", but you should only really use that if the mapping-fn references some changeable state outside of the dataset.

best,

Kevin

On Fri, Jul 27, 2012 at 6:01 PM, Daniel Woelfel <dwwo...@gmail.com> wrote:
I'm using unify! to create a scatterplot with c2 0.2.0. The data is stored in an atom, which is reset! with new data. Points from the old data set will stick around if my new data set has fewer points than the previous data set. 

How can I prevent this from happening? Is there some way to make c2 view a container as a cohesive whole?

--
You received this message because you are subscribed to the Google Groups "C2-cljs" group.
To unsubscribe from this group, send email to c2-cljs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Kevin Lynagh
Keming Labs
http://keminglabs.com
888.502.1042

Kevin Lynagh

unread,
Jul 27, 2012, 9:12:51 PM7/27/12
to c2-...@googlegroups.com
p.s. This is where all of the unify magic happens:

    https://github.com/lynaghk/singult/blob/master/src/coffee/Singult.coffee#L179

Daniel Woelfel

unread,
Jul 27, 2012, 9:29:33 PM7/27/12
to c2-...@googlegroups.com
Thanks.
Reply all
Reply to author
Forward
0 new messages