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:* [email protected]
> [mailto:[email protected]] *On Behalf Of *David Karger
> *Sent:* 08 April 2009 13:44
> *To:* [email protected]
> *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 <[email protected]
> <mailto:[email protected]>> 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: [email protected] <mailto:[email protected]>
>
>     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
>     [email protected]
>     <mailto:[email protected]>
>     To unsubscribe from this group, send email to
>     [email protected]
>     <mailto:[email protected]>
>     For more options, visit this group at
>     http://groups.google.com/group/simile-widgets?hl=en
>     -~----------~----~----~----~------~----~------~--~---
>
>     ml>
>
>
>  
>
>
> >

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SIMILE Widgets" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/simile-widgets?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to