Manipulating dates in Exhibit

19 views
Skip to first unread message

C Anthony Lewis

unread,
Apr 8, 2009, 8:39:08 AM4/8/09
to simile-...@googlegroups.com

Hello,

 

As ever, thanks for a great set of tools and helpful list.

 

I’m (again) having difficulty manipulating dates in Exhibit. I followed the code at http://groups.google.com/group/simile-widgets/browse_thread/thread/78063be86c4d2ca4 and got a facet (I hope that’s the correct term) working that displays months of the year, so I thought I’d be clever and do the same for years… of course I don’t really know what I’m doing so it didn’t work!

 

To extract the year from a date I used:

        var yearNames = [ "2007", "2008", "2009", "2010", "2011" ];
        Exhibit
.Functions["year"] = {
            f
: function(args) {
               
var set = new Exhibit.Set();
              
                args
[0].forEachValue(function(v) {
                   
var d = SimileAjax.DateTime.parseIso8601DateTime(v);
                   
var y = d.getFullYear();
                    set
.add(yearNames[y]);
                }
);
              
               
return new Exhibit.Expression._Collection(set, "number");
            }
        }
;

and then had the following:

       <div ex:role="facet" ex:expression="year(.startdate)" ex:fixedOrder="2007;2008;2009;2010;2011" ex:facetLabel="Year"></div>

But to no avail… all I’m getting is “undefined” for all the items in my Exhibit.

 

I’m wondering if this is totally the wrong way to go about it as maybe I would need to have an infinite list of years for this to work?

 

Thanks for any assistance,

 

Anthony

 

 

C. Anthony Lewis

Petroleum & Environmental Geochemistry Group,

School of Earth, Ocean and Environmental Sciences,

University of Plymouth,

Plymouth, Devon PL4 8AA, U.K.

 

tel: +44 (0)1752 584554

email: cal...@plymouth.ac.uk

web: http://www.pegg.org.uk

http://www.plymouth.ac.uk/chemistry

 

David Karger

unread,
Apr 8, 2009, 8:43:53 AM4/8/09
to simile-...@googlegroups.com
an alternative approach would be to use exhibit's callback-on-data-load to explicitly add a "year" property to every item.  Then you could use a plain year facet. 

Sent from my iPhone
ecause you are subscribed to the Google Groups "SIMILE Widgets" group.
To post to this group, send email to simile-...@googlegroups.com
To unsubscribe from this group, send email to simile-widget...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/simile-widgets?hl=en
-~----------~----~----~----~------~----~------~--~---

ml>

C Anthony Lewis

unread,
Apr 9, 2009, 9:28:39 AM4/9/09
to simile-...@googlegroups.com

David,

 

Many thanks for the speedy response.

 

If I understand correctly, you’re suggesting that a “year” property can be added on the fly from the original property as the data loads. I fear this is a little beyond my current skills so I’m wondering if you can suggest an existing Exhibit that I can look at.

 

Does this mean that it’s not possible to do it the way I was attempting?

 

All the best and thanks for any further assistance,

 

Anthony

Durendal

unread,
Apr 9, 2009, 2:28:14 PM4/9/09
to SIMILE Widgets
Hi,

Have you tried by replacing line:
set.add(yearNames[y]);
by
set.add(y);

This might solve your trouble.
Michiel

On 9 apr, 15:28, C Anthony Lewis <cale...@plymouth.ac.uk> wrote:
> David,
>
> Many thanks for the speedy response.
>
> If I understand correctly, you’re suggesting that a “year” property can be added on the fly from the original property as the data loads. I fear this is a little beyond my current skills so I’m wondering if you can suggest an existing Exhibit that I can look at.
>
> Does this mean that it’s not possible to do it the way I was attempting?
>
> All the best and thanks for any further assistance,
>
> Anthony
>
> From: simile-...@googlegroups.com [mailto:simile-...@googlegroups.com] On Behalf Of David Karger
> Sent: 08 April 2009 13:44
> To: simile-...@googlegroups.com
> Subject: Re: Manipulating dates in Exhibit
>
> an alternative approach would be to use exhibit's callback-on-data-load to explicitly add a "year" property to every item.  Then you could use a plain year facet.
>
> Sent from my iPhone
>
> On Apr 8, 2009, at 8:39 AM, C Anthony Lewis <cale...@plymouth.ac.uk<mailto:cale...@plymouth.ac.uk>> wrote:
> Hello,
>
> As ever, thanks for a great set of tools and helpful list.
>
> I’m (again) having difficulty manipulating dates in Exhibit. I followed the code athttp://groups.google.com/group/simile-widgets/browse_thread/thread/78...and got a facet (I hope that’s the correct term) working that displays months of the year, so I thought I’d be clever and do the same for years… of course I don’t really know what I’m doing so it didn’t work!
>
> To extract the year from a date I used:
>         var yearNames = [ "2007", "2008", "2009", "2010", "2011" ];
>         Exhibit.Functions["year"] = {
>             f: function(args) {
>                 var set = new Exhibit.Set();
>
>                 args[0].forEachValue(function(v) {
>                     var d = SimileAjax.DateTime.parseIso8601DateTime(v);
>                     var y = d.getFullYear();
>                     set.add(yearNames[y]);
>                 });
>
>                 return new Exhibit.Expression._Collection(set, "number");
>             }
>         };
>
> and then had the following:
>        <div ex:role="facet" ex:expression="year(.startdate)" ex:fixedOrder="2007;2008;2009;2010;2011" ex:facetLabel="Year"></div>
>
> But to no avail… all I’m getting is “undefined” for all the items in my Exhibit.
>
> I’m wondering if this is totally the wrong way to go about it as maybe I would need to have an infinite list of years for this to work?
>
> Thanks for any assistance,
>
> Anthony
>
> C. Anthony Lewis
> Petroleum & Environmental Geochemistry Group,
> School of Earth, Ocean and Environmental Sciences,
> University of Plymouth,
> Plymouth, Devon PL4 8AA, U.K.
>
> tel: +44 (0)1752 584554
> email: cale...@plymouth.ac.uk<mailto:cale...@plymouth.ac.uk>
> web:http://www.pegg.org.uk<http://www.pegg.org.uk/>http://www.plymouth.ac.uk/chemistry
>
> ecause you are subscribed to the Google Groups "SIMILE Widgets" group.
> To post to this group, send email to simile-...@googlegroups.com<mailto:simile-...@googlegroups.com>
> To unsubscribe from this group, send email to simile-widget...@googlegroups.com<mailto:simile-widget...@googlegroups.com>

David Karger

unread,
Apr 12, 2009, 1:59:48 AM4/12/09
to simile-...@googlegroups.com
Anthony; your way might work. It looks like you are getting "undefined"
because getFullYear is returning values like 2001 while your array only
has 5 entries. You might try replacing set.add(yearNames[y]) with
set.add(y).

If you want to try what I suggested, which is along the lines of this
thread:
http://simile.mit.edu/wiki/Exhibit/How_to_make_an_exhibit_from_any_JSONP_data_source

you would specify

<link rel="exhibit/data" href="your data url" ex:converter="myConverter">

and then place a script in the body that adds a "year" to every item
based on its "data" field:

<script>
function myConverter( json ) {
var items = json.items;
for (var i = 0; item = items[i]; i++) {
items[i].year = *SimileAjax*.*DateTime*.*parseIso8601DateTime(item.date).getFullYear();*
}
return json;
}
</script>

and would then be able to access a "year" property in your data.



C Anthony Lewis wrote:
>
> David,
>
>
>
> Many thanks for the speedy response.
>
>
>
> If I understand correctly, you’re suggesting that a “year” property
> can be added on the fly from the original property as the data loads.
> I fear this is a little beyond my current skills so I’m wondering if
> you can suggest an existing Exhibit that I can look at.
>
>
>
> Does this mean that it’s not possible to do it the way I was attempting?
>
>
>
> All the best and thanks for any further assistance,
>
>
>
> Anthony
>
>
>
> *From:* simile-...@googlegroups.com
> [mailto:simile-...@googlegroups.com] *On Behalf Of *David Karger
> *Sent:* 08 April 2009 13:44
> *To:* simile-...@googlegroups.com
> *Subject:* Re: Manipulating dates in Exhibit
>
>
>
> an alternative approach would be to use exhibit's
> callback-on-data-load to explicitly add a "year" property to every
> item. Then you could use a plain year facet.
>
> Sent from my iPhone
>
>
> On Apr 8, 2009, at 8:39 AM, C Anthony Lewis <cal...@plymouth.ac.uk
> <mailto:cal...@plymouth.ac.uk>> wrote:
>
> Hello,
>
>
>
> As ever, thanks for a great set of tools and helpful list.
>
>
>
> I’m (again) having difficulty manipulating dates in Exhibit. I
> followed the code at
> http://groups.google.com/group/simile-widgets/browse_thread/thread/78063be86c4d2ca4
> and got a facet (I hope that’s the correct term) working that
> displays months of the year, so I thought I’d be clever and do the
> same for years… of course I don’t really know what I’m doing so it
> didn’t work!
>
>
>
> To extract the year from a date I used:
>
> *var* *yearNames* = [ /"2007"/, /"2008"/, /"2009"/,
> /"2010"/, /"2011"/ ];
> *Exhibit*.*Functions*[/"year"/] = {
> *f*: *function*(*args*) {
> *var* *set* = *new* *Exhibit*.*Set*();
>
> *args*[0].*forEachValue*(*function*(*v*) {
> *var* *d* =
> *SimileAjax*.*DateTime*.*parseIso8601DateTime*(*v*);
> *var* *y* = *d*.*getFullYear*();
> *set*.*add*(*yearNames*[*y*]);
> });
>
> *return* *new*
> *Exhibit*.*Expression*.*_Collection*(*set*, /"number"/);
> }
> };
>
>
> and then had the following:
>
> *<div* ex:role=*"facet"* ex:expression=*"year(.startdate)"*
> ex:fixedOrder=*"2007;2008;2009;2010;2011"*
> ex:facetLabel=*"Year"></div>*
>
>
> But to no avail… all I’m getting is “undefined” for all the items
> in my Exhibit.
>
>
>
> I’m wondering if this is totally the wrong way to go about it as
> maybe I would need to have an infinite list of years for this to work?
>
>
>
> Thanks for any assistance,
>
>
>
> Anthony
>
>
>
>
>
> C. Anthony Lewis
>
> Petroleum & Environmental Geochemistry Group,
>
> School of Earth, Ocean and Environmental Sciences,
>
> University of Plymouth,
>
> Plymouth, Devon PL4 8AA, U.K.
>
>
>
> tel: +44 (0)1752 584554
>
> email: cal...@plymouth.ac.uk <mailto:cal...@plymouth.ac.uk>
>
> web: http://www.pegg.org.uk <http://www.pegg.org.uk/>
>
> http://www.plymouth.ac.uk/chemistry
>
>
>
>
>
> ecause you are subscribed to the Google Groups "SIMILE Widgets"
> group.
> To post to this group, send email to
> simile-...@googlegroups.com
> <mailto:simile-...@googlegroups.com>
> To unsubscribe from this group, send email to
> simile-widget...@googlegroups.com
> <mailto:simile-widget...@googlegroups.com>

C Anthony Lewis

unread,
Apr 15, 2009, 5:51:40 AM4/15/09
to simile-...@googlegroups.com
David,

Again, thanks for the suggestions and help... as suggested by Durendal using set.year(y) works fine and I understand why, which is a bonus!

I'm about to investigate your initial suggestion so thanks for the extra pointers with that as well.

All the best,

Anthony

-----Original Message-----
From: simile-...@googlegroups.com [mailto:simile-...@googlegroups.com] On Behalf Of David Karger
Reply all
Reply to author
Forward
0 new messages