Name: SuikaWikiGraph FullName: "SuikaWikiGraph" format support URI: IW:SuikaWiki:SuikaWiki Description: This module provides "SuikaWikiGraph/0.9" support. Initialize: my $HAS_XML = SuikaWiki::Plugin->feature ('SuikaWiki::Markup::XML'); my $NS_XHTML1 = 'http://www.w3.org/1999/xhtml'; { Name: wikiview/graph-timeline-pseudo-html FullName: Embeding timeline graph (written in pseudo HTML) Description: WARNING: This rule outputs very ugly HTML (some people call it "DIV chuu-teki"). SVG output should be used for SVG-enabled UAs. Format: my @data = ( {year => 1992, month => 0, label => 'Very earlier HTML spec'}, {year => 1993, month => 3, label => 'HTML 1.0 I-D'}, {year => 1993, month => 11, label => 'HTML+ I-D'}, {year => 1995, month => 5, label => 'HTML 3.0 I-D'}, {year => 1997, month => 01, label => 'HTML 2.x RFC'}, {year => 1997, month => 01, label => 'HTML 3.2 REC'}, {year => 1997, month => 12, label => 'HTML 4.0 REC'}, {year => 1998, month => 02, label => 'CHTML NoteC'}, {year => 1999, month => 12, label => 'HTML 4.01 REC'}, {year => 2000, month => 01, label => 'XHTML 1.0 REC'}, {year => 2000, month => 12, label => 'XHTML Basic 1.0 REC'}, {year => 2001, month => 04, label => 'XHTML m12n REC'}, {year => 2001, month => 05, label => 'XHTML 1.1 REC'}, {year => 2002, month => 8, label => 'XHTML 1.0 SE REC'}, {year => 2002, month => 00, label => 'XHTML 2.0 WD'}, ); $r = SuikaWiki::Markup::XML->new (namespace_uri => $NS_XHTML1, local_name => 'div'); my @sorted_data = sort {$a->{value} <=> $b->{value}} @{time_db_to_graph_db(\@data)}; my $s = 700 / ($sorted_data[-1]->{value} - $sorted_data[0]->{value} || 1); my $offset = $sorted_data[0]->{value}; my $pp = 0; for my $entry (@sorted_data) { unless ($entry->{value} == $sorted_data[0]->{value}) { for ($r->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'div')) { $_->set_attribute (class => 'pi-swg-hgt-graph'); $_->set_attribute (style => qq(top: @{[($pp - $offset)*$s]}px; height: @{[($entry->{value} - $pp)*$s]}px)); } } for ($r->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'div')) { $_->set_attribute (class => 'pi-swg-hgt-label'); $_->set_attribute (style => qq(top: @{[($entry->{value} - $offset)*$s-16]}px)); $_->set_attribute (title => $entry->{label_full} || $entry->{label}); $_->append_text ($entry->{label}); } $pp = $entry->{value}; } } MODULE: sub time_db_to_graph_db (\@) { require Time::Local; my $tdb = shift; my $gdb = []; for my $t (@$tdb) { my $g = {}; ## TODO $g->{value} = Time::Local::timegm_nocheck ($t->{second}, $t->{minute}, $t->{hour}, $t->{day}, $t->{month}-1, $t->{year}); $g->{label} = $t->{label}; $g->{label_full} = sprintf '%s (%04d-%02d-%02dT%02d:%02d:%02dZ)', $t->{label}, $t->{year}, $t->{month}, $t->{day}, $t->{hour}, $t->{minute}, $t->{second}; push @$gdb, $g; } $gdb; } SuikaWiki::View->definition (pi_swg__hgt_ => { media => {type => 'text/html', charset => 1, expires => 600}, xmedia => {type => 'application/xhtml+xml', charset => 1, expires => 600}, template => <{%res(name=>{Plugin:SuikaWikiGraph:Timeline:WebPageTitle});}p,link-meta=>{%predefined-template(name=>links);}p,content=>{ %graph-timeline-pseudo-html; }p); EOH POD:TO DO: POD:LICENSE: Copyright 2003 Wakaba %%GNUGPL2%%