Below are some extensions to
http://simile.mit.edu/wiki/Exhibit/2.0/Functions

As I was unable to get ex:formats to apply to timeline-view's lenses
(ex:formats="date
{ time-zone: 0; template: 'HH:mm:ss.S'} number { decimal-digits: 0 } item {
title: expression(value) }"
works with ex:viewClass="Tabular" but also doesn't apply to popup bubbles
from that view)... I ended up extending exhibit's functions to add some
formatting functionality within lenses using exhibit expressions:

Usage example:
><div class="episode-event-times"
ex:content="concat(ISO8601-to-HMS(.start), '&nbsp;-&nbsp;',
ISO8601-to-HMS(.end))" ></div ><div class="episode-event-duration"
ex:content="concat(to-fixed(multiply(0.001, date-range(.start, .end,
'millisecond')), 2), ' S.')" ></div

Code: http://nielsmayer.com/npm-exhibit-function-extensions.js

/* * NPM ENHANCEMENT for Exhibit.Functions[] ( *
exhibit-trunk:trunk/src/webapp/api/scripts/data/functions.js ). * Added
functions: * -- zeroTime() * :: used in conjunction with date-range() to
convert a time value into a number. * -- ISO8601-to-HMS(iso8601_string) * ::
trims '<date>T' and 'Z' from iso8601 string * :: e.g. <date>THH:mm:ss.SSSZ
--> "HH:mm:ss.SSS" * -- to-fixed(float_number, precision) * :: wrapper for
.toFixed() method on javascript numbers. */ Exhibit.Functions["to-fixed"] =
{ f: function(args) { if ((args == null) || (args.size() != 2)) return (new
Exhibit.Expression._Collection([ ], "number")); else { var arg = args[0];
switch (arg.valueType) { case 'number': var argVal =
Exhibit.FunctionUtilities.exhibitFunargValue(arg); if (argVal != null) { var
fixArg = args[1]; switch (fixArg.valueType) { case 'number': var fixVal =
Exhibit.FunctionUtilities.exhibitFunargValue(fixArg); if (fixVal != null)
return (new Exhibit.Expression._Collection([ argVal.toFixed(fixVal) ],
"number")); else return (new Exhibit.Expression._Collection([ ], "number"));
break; default: return (new Exhibit.Expression._Collection([ ], "number"));
break; } } else return (new Exhibit.Expression._Collection([ ], "number"));
break; default: return (new Exhibit.Expression._Collection([ ], "number"));
break; } } } }; Exhibit.Functions["ISO8601-to-HMS"] = { f: function(args) {
var arg = args[0]; switch (arg.valueType) { case 'date': var t =
Exhibit.FunctionUtilities.exhibitFunargValue(arg); if (t != null) return
(new Exhibit.Expression._Collection([ t.substring(t.indexOf('T') + 1,
t.lastIndexOf('Z')) ], "text")); else return (new
Exhibit.Expression._Collection([ ], "text")); break; default: return (new
Exhibit.Expression._Collection([ ], "text")); break; } } };
Exhibit.Functions["zeroTime"] = { f: function(args) { return new
Exhibit.Expression._Collection([ new Date(0) ], "date"); } }; /* * NPM
ENHANCEMENT: utility needed for functions ISO8601-to-HMS() and to-fixed() *
Extends Exhibit.FunctionUtilities from
trunk/src/webapp/api/scripts/data/functions.js */
Exhibit.FunctionUtilities.exhibitFunargValue = function (arg) { var argVal =
null; arg.forEachValue(function(v) { argVal = v; }) return (argVal); };

Niels
http://nielsmayer.com

PS: Am I doing the right thing for handling argument type or number errors
by returning "return (new Exhibit.Expression._Collection([ ],
"text"));" ?? PPS:
it's too bad exhibit expressions aren't done in scheme... it would be much
more elegant... of course, i'd be happier if JavaScript stayed as
Scheme<http://weblogs.mozillazine.org/roadmap/archives/2008/04/popularity.html>
in
the first place... it's right up there with other blunders, like adding
<blink> and <font> to HTML. :-)

--~--~---------~--~----~------------~-------~--~----~
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