view release on metacpan or search on metacpan
~~~~{.buffer to='chart_data'}
apples,bananas,cake,cabbage,edam,fromage,tomatoes,chips
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
~~~~
The content comprises a number of lines of comma separated data items.
The first line of the content is the legends, the subsequent lines are numbers relating
to each of these legends.
### Pie chart
**Example**
~~~~{.chart format='pie' title='chart1' from_buffer='chart_data'
size='400x400' xaxis='things xways' yaxis='Vertical things'
legends='a,b,c,d,e,f,g,h' }
~~~~
**Output**
~~~~{.chart format='pie' title='chart1' from_buffer='chart_data'
size='400x400' xaxis='things xways' yaxis='Vertical things'
legends='a,b,c,d,e,f,g,h' }
~~~~
### Bar chart
**Example**
~~~~{.chart format='bars' title='chart1' from_buffer='chart_data'
size='600x400' xaxis='things ways' yaxis='Vertical things'
legends='a,b,c,d,e,f,g,h' }
~~~~
**Output**
~~~~{.chart format='bars' title='chart1' from_buffer='chart_data'
size='600x400' xaxis='things ways' yaxis='Vertical things'
legends='a,b,c,d,e,f,g,h' }
~~~~
### Mixed chart
**Example**
~~~~{.chart format='mixed' title='chart1' from_buffer='chart_data'
size='600x400' xaxis='things xways' axis='Vertical things'
legends='a,b,c,d,e,f,g,h' types='lines linepoints lines bars' }
~~~~
**Output**
~~~~{.chart format='mixed' title='chart1' from_buffer='chart_data'
size='600x400' xaxis='things xways' axis='Vertical things'
legends='a,b,c,d,e,f,g,h' types='lines linepoints lines bars' }
~~~~
## Message Sequence Charts - mscgen
Software (or process) engineers often want to be able to show the sequence in which a number of events take place. We use the [msc] program for this. This program needs to be installed onto your system to allow this to work
The content for this code-block is EXACTLY the same that you would use as input to [msc]
There are only optional 2 arguments
}
~~~~
## Venn diagram
Creating venn diagrams may sometimes be useful, though to be honest this implementation is not great, if I could find a better way to do this then I would!
**Example**
~~~~{.venn title="sample venn diagram"
legends="team1 team2 team3" scheme="rgb" explain='1'}
abel edward momo albert jack julien chris
edward isabel antonio delta albert kevin jake
gerald jake kevin lucia john edward
~~~~
**Output**
~~~~{.venn title="sample venn diagram" legends="team1 team2 team3" scheme="rgb" explain='1'}
abel edward momo albert jack julien chris
edward isabel antonio delta albert kevin jake
gerald jake kevin lucia john edward
~~~~
## Barcodes
Sometimes having barcodes in your document may be useful, certainly qrcodes are popular.
The code-block only allows a single line of content. Some of the barcode types need
Create a simple table using CSV style data
* class
* HTML/CSS class name
* id
* HTML/CSS class
* width
* width of the table
* style
* style the table if not doing anything else
* legends
* csv of headings for table, these correspond to the data sets
* separator
* what should be used to separate cells, defaults to ','
**Example**
~~~~{.table separator=',' width='100%' legends=1
from_buffer='chart_data'}
~~~~
**Output**
~~~~{.table separator=',' width='100%' legends=1
from_buffer='chart_data'}
~~~~
## Links
With one code-block we can create a list of links
The code-block contents comprises a number of lines with a reference and a URL.
The reference comes first, then a '|' to separate it from the URL.
docs/README.html view on Meta::CPAN
<p>The various arguments to the code-block are shown in the examples below, hopefully they are self explanatory.</p>
<p>We will buffer some data to start</p>
<p><strong>Example</strong></p>
<pre><code>~~~~{.buffer to='chart_data'}
apples,bananas,cake,cabbage,edam,fromage,tomatoes,chips
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
~~~~</code></pre>
<p>The content comprises a number of lines of comma separated data items. The first line of the content is the legends, the subsequent lines are numbers relating to each of these legends.</p>
<h3 id="pie-chart"><a name='6.1_pie_chart'>6.1 Pie chart</a></h3>
<p><strong>Example</strong></p>
<pre><code>~~~~{.chart format='pie' title='chart1' from_buffer='chart_data'
size='400x400' xaxis='things xways' yaxis='Vertical things'
legends='a,b,c,d,e,f,g,h' }
~~~~</code></pre>
<p><strong>Output</strong></p>
<p><img src='/tmp/kmulholland/cache/ct2/b82cab1f86108fdab6afbe84d1869d6a.png' alt='chart1' height='400' width='400' /></p>
<h3 id="bar-chart"><a name='6.2_bar_chart'>6.2 Bar chart</a></h3>
<p><strong>Example</strong></p>
<pre><code>~~~~{.chart format='bars' title='chart1' from_buffer='chart_data'
size='600x400' xaxis='things ways' yaxis='Vertical things'
legends='a,b,c,d,e,f,g,h' }
~~~~</code></pre>
<p><strong>Output</strong></p>
<p><img src='/tmp/kmulholland/cache/ct2/511c5b56e040bea36912d2b0987f5d1d.png' alt='chart1' height='400' width='600' /></p>
<h3 id="mixed-chart"><a name='6.3_mixed_chart'>6.3 Mixed chart</a></h3>
<p><strong>Example</strong></p>
<pre><code>~~~~{.chart format='mixed' title='chart1' from_buffer='chart_data'
size='600x400' xaxis='things xways' axis='Vertical things'
legends='a,b,c,d,e,f,g,h' types='lines linepoints lines bars' }
~~~~</code></pre>
<p><strong>Output</strong></p>
<p><img src='/tmp/kmulholland/cache/ct2/a1903dfe13a20e39b9e880ff1ee06b0c.png' alt='chart1' height='400' width='600' /></p>
<h2 id="message-sequence-charts---mscgen"><a name='7_message_sequence_charts_-_mscgen'>7 Message Sequence Charts - mscgen</a></h2>
<p>Software (or process) engineers often want to be able to show the sequence in which a number of events take place. We use the <a href="http://www.mcternan.me.uk/mscgen/">msc</a> program for this. This program needs to be installed onto your system...
<p>The content for this code-block is EXACTLY the same that you would use as input to <a href="http://www.mcternan.me.uk/mscgen/">msc</a></p>
<p>There are only optional 2 arguments</p>
<ul>
<li>title
<ul>
docs/README.html view on Meta::CPAN
start [shape=Mdiamond];
end [shape=Msquare];
}
~~~~</code></pre>
<p><strong>Output</strong></p>
<p><img src='/tmp/kmulholland/cache/ct2/d25c89fc3008d30afc6dc3fd38178ab2.png' alt='graphviz1' height='600' width='306' /></p>
<h2 id="venn-diagram"><a name='11_venn_diagram'>11 Venn diagram</a></h2>
<p>Creating venn diagrams may sometimes be useful, though to be honest this implementation is not great, if I could find a better way to do this then I would!</p>
<p><strong>Example</strong></p>
<pre><code>~~~~{.venn title="sample venn diagram"
legends="team1 team2 team3" scheme="rgb" explain='1'}
abel edward momo albert jack julien chris
edward isabel antonio delta albert kevin jake
gerald jake kevin lucia john edward
~~~~</code></pre>
<p><strong>Output</strong></p>
<p><img src='/tmp/kmulholland/cache/ct2/9e0b98ce7e0ea5829245653fa0eade79.png' alt='sample venn diagram' height='400' width='400' /></p>
<ul>
<li>only in team1 : julien momo abel chris jack
<ul>
<li>only in team2 : delta isabel antonio</li>
docs/README.html view on Meta::CPAN
<li>HTML/CSS class</li>
</ul></li>
<li>width
<ul>
<li>width of the table</li>
</ul></li>
<li>style
<ul>
<li>style the table if not doing anything else</li>
</ul></li>
<li>legends
<ul>
<li>csv of headings for table, these correspond to the data sets</li>
</ul></li>
<li>separator
<ul>
<li>what should be used to separate cells, defaults to â,â</li>
</ul></li>
</ul>
<p><strong>Example</strong></p>
<pre><code>~~~~{.table separator=',' width='100%' legends=1
from_buffer='chart_data'}
~~~~</code></pre>
<p><strong>Output</strong></p>
<table width='100%' >
<tr><th>
apples
</th><th>
bananas
</th><th>
cake
lib/App/Basis/ConvertText2/Plugin/Chart.pm view on Meta::CPAN
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
" ;
my $params = {
size => "600x480",
title => "chart1",
xaxis => 'things xways',
yaxis => 'Vertical things',
format => 'pie',
legends => 'a,b,c,d,e,f,g,h'
} ;
my $obj = App::Basis::ConvertText2::Plugin::Chart->new() ;
my $out = $obj->process( 'chart', $content, $params) ;
=head1 DESCRIPTION
Convert comma separated text strings into charts image PNG
=cut
lib/App/Basis/ConvertText2/Plugin/Chart.pm view on Meta::CPAN
filename - filename to save the created chart image as
hashref params of
size - size of image, default 400x300, widthxheight - optional
title - title for the chart
xaxis - label for x axis
yaxis - label for y axis
format - chart format mixed, area, lines, points, linespoints, bars, lines3d, pie
types - space separated list of types, in the same order as the data sets. Possible values are: lines bars points area linespoints
overwrite - If set to 0, bars of different data sets will be drawn next to each other. If set to 1, they will be drawn in front of each other. Default: 0.
legends - csv of legends for graph, these correspond to the data sets
=cut
sub process {
my $self = shift;
my ( $tag, $content, $params, $cachedir ) = @_;
my ( @data, $chart, $format );
my @types = ();
$params->{size} ||= "400x300";
my ( $x, $y ) = ( $params->{size} =~ /^\s*(\d+)\s*x\s*(\d+)\s*$/ );
lib/App/Basis/ConvertText2/Plugin/Chart.pm view on Meta::CPAN
default_type => $types[0] || "points",
bgclr => 'white',
fgclr => 'black',
boxclr => 'ivory',
accentclr => 'black',
valuesclr => 'black',
labelclr => 'black',
axislabelclr => 'black',
legendclr => 'black',
valuesclr => 'black',
textclr => 'black',
# shadow_depth => 2,
x_label => $params->{xaxis} || "",
y_label => $params->{yaxis} || "",
title => $params->{title} || "",
overwrite => $params->{overwrite} || 0,
bar_spacing => 6,
long_ticks => 1,
x_ticks => 1,
x_labels_vertical => 1,
legend_marker_width => 24,
line_width => 3,
marker_size => 5,
legend_placement => 'RC',
);
# set the colours for the charts
# white, lgray, gray, dgray, black, lblue, blue, dblue, gold, lyellow, yellow, dyellow,
# lgreen, green, dgreen, lred, red, dred, lpurple, purple, dpurple, lorange, orange,
# pink, dpink, marine, cyan, lbrown, dbrown.
$chart->set( dclrs => [qw(marine blue lred dgreen orange salmon lbrown gold lgreen yellow gray dred lpurple)] );
# set the font things
$chart->set_title_font(gdGiantFont);
# pie legends are written on the slices, so we don't have this method
if ( $format eq 'pie' ) {
$chart->set_value_font(gdMediumBoldFont);
}
else {
# legends comma seperated to allow spaces in descriptions
$chart->set_legend( split( /,/, $params->{legends} || "" ) );
$chart->set_legend_font(gdMediumBoldFont);
$chart->set_x_label_font(gdMediumBoldFont);
$chart->set_y_label_font(gdMediumBoldFont);
$chart->set_x_axis_font(gdMediumBoldFont);
$chart->set_y_axis_font(gdMediumBoldFont);
$chart->set_values_font(gdMediumBoldFont);
}
my ( $stdout, $stderr, $exit ) = capture {
my $gd = $chart->plot( \@data );
path($filename)->spew_raw( $gd->png ) if ($$gd);
lib/App/Basis/ConvertText2/Plugin/Text.pm view on Meta::CPAN
create a basic html table
parameters
data - comma separated lines of table data
hashref params of
class - HTML/CSS class name
id - HTML/CSS class
width - width of the table
style - style the table if not doing anything else
legends - flag to indicate that the top row is the legends
separator - characters to be used to separate the fields
=cut
sub table {
my $self = shift;
my ( $tag, $content, $params, $cachedir ) = @_;
$params->{title} ||= "";
lib/App/Basis/ConvertText2/Plugin/Text.pm view on Meta::CPAN
my $out = "<table ";
$out .= "class='$params->{class}' " if ( $params->{class} );
$out .= "id='$params->{id}' " if ( $params->{id} );
$out .= "width='$params->{width}' " if ( $params->{width} );
$out .= "class='$params->{style}' " if ( $params->{style} );
$out .= ">\n";
for ( my $i = 0; $i < scalar(@data); $i++ ) {
$out .= "<tr>";
# decide if the top row has the legends
my $tag = ( !$i && $params->{legends} ) ? 'th' : 'td';
map { $out .= "<$tag>$_</$tag>"; } @{ $data[$i] };
$out .= "</tr>\n";
}
$out .= "</table>\n";
return $out;
}
# ----------------------------------------------------------------------------
lib/App/Basis/ConvertText2/Plugin/Venn.pm view on Meta::CPAN
App::Basis::ConvertText2::Plugin::Venn
=head1 SYNOPSIS
my $content = "abel edward momo albert jack julien chris
edward isabel antonio delta albert kevin jake
gerald jake kevin lucia john edward" ;
my $params = {
title => "sample venn diagram",
legends => "team1 team2 team3",
scheme => "rgb",
explain => '1'
} ;
my $obj = App::Basis::ConvertText2::Plugin::Venn->new() ;
my $out = $obj->process( 'venn', $content, $params) ;
=head1 DESCRIPTION
Convert a text string of comma separated numbers into a Venn diagran image PNG
lib/App/Basis/ConvertText2/Plugin/Venn.pm view on Meta::CPAN
create a simple venn diagram image, with some nice defaults, returns some
markdown explaining the diagram, undex/empty if errors
parameters
text - 2 or 3 space separated lines of items for the venn
filename - filename to save the created image as
hashref params of
title - title for the image
legends - legends to match the lines
size - size of image, default 400x400, widthxheight - optional
scheme - color scheme
=cut
sub process {
my $self = shift;
my ( $tag, $content, $params, $cachedir ) = @_;
$params->{size} ||= "";
$params->{title} ||= "";
$params->{legends} ||= "";
$params->{size} ||= "400x400";
$params->{scheme} ||= 'default';
$params->{scheme} = lc( $params->{scheme} );
my ( $w, $h ) = ( $params->{size} =~ /^\s*(\d+)\s*x\s*(\d+)\s*$/ );
if ( !$h ) {
$w = 400;
$h = 400;
}
return "" if ( !$content );
lib/App/Basis/ConvertText2/Plugin/Venn.pm view on Meta::CPAN
my $filename = cachefile( $cachedir, "$sig.png" );
# we will not check for the cachefile as we need to create the venn object
# each time to get the explaination text, besides not many people will
# use this plugin, so lets not go to the extra effort
my $venn_chart = Venn::Chart->new( $w, $h ) or die("error : $!");
# lose any leading spaces
$content =~ s/^\s+//s;
# Set a title, colors and a legend for our chart
my $colors = $_colour_schemes{ $params->{scheme} } ? $_colour_schemes{ $params->{scheme} } : $_colour_schemes{default};
$venn_chart->set_options( -title => $params->{title}, -colors => $colors );
my @legends;
# decide how to split the legends
if ( $params->{legends} =~ /,/ ) {
@legends = map { my $n = $_; $n =~ s/^\s+//; $n } split( /,/, $params->{legends} );
}
else {
@legends = split( /\s/, $params->{legends} );
}
# get the venn data, max 3 lines of it
my $lines = 0;
my @data;
my @newlegends;
foreach my $line ( split( /\n/, $content ) ) {
$line =~ s/^s+//; # remove leading spaces
next if ( !$line );
# update legends with members
my $l = $legends[$lines];
if ( !$l ) {
$l = 'missing';
push @legends, $l;
}
push @newlegends, "$l : $line";
last if ( ++$lines > 3 );
my @a = split( /[,\s+]/, $line );
push @data, \@a;
}
$venn_chart->set_legends(@newlegends);
# Create a diagram with gd object
my $gd_venn = $venn_chart->plot(@data);
# Create a Venn diagram image in png format
path($filename)->spew_raw( $gd_venn->png() );
my $out;
if ( -f $filename ) {
# now explain what is in each region
my @ref_lists = $venn_chart->get_list_regions();
# create something suitable for the HTML
$out = create_img_src( $filename, $params->{title} );
$out .= "\n\n" . "* only in $legends[0] : " . join( ' ', @{ $ref_lists[0] } ) . "
* only in $legends[1] : " . join( ' ', @{ $ref_lists[1] } ) . "
* $legends[0] and $legends[1] share : " . join( ' ', @{ $ref_lists[2] } ) . "\n";
if ( scalar(@newlegends) > 2 ) {
$out .= "* only in $legends[2] : " . join( ' ', @{ $ref_lists[3] } ) . "
* $legends[0] and $legends[2] share : " . join( ' ', @{ $ref_lists[4] } ) . "
* $legends[1] and $legends[2] share : " . join( ' ', @{ $ref_lists[5] } ) . "
* $legends[0], $legends[1] and $legends[2] share : " . join( ' ', @{ $ref_lists[6] } ) . "\n";
}
$out .= "\n";
}
return $out;
}
# ----------------------------------------------------------------------------
1;
t/02_plugins.t view on Meta::CPAN
$out = $obj->process( 'qrcode', $content, $params, $TEST_DIR );
ok( has_file($out), 'qrcode created a file' );
# chart
$obj = App::Basis::ConvertText2::Plugin::Chart->new();
$content = "apples,bananas,cake,cabbage,edam,fromage,tomatoes,chips
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55";
$params = extract_args('title="chart1" size="400x400" xaxis="things xways" yaxis="Vertical things" format="pie" legends="a,b,c,d,e,f,g,h"');
$out = $obj->process( 'chart', $content, $params, $TEST_DIR );
ok( has_file($out), 'chart created a file' );
# sparkline
$content = '1,4,5,20,4,5,3,1';
$obj = App::Basis::ConvertText2::Plugin::Sparkline->new();
$params = extract_args("title='sparkline' scheme='blue'");
$out = $obj->process( 'sparkline', $content, $params, $TEST_DIR );
ok( has_file($out), 'sparkline created a file' );
# venn
$content = 'abel edward momo albert jack julien chris
edward isabel antonio delta albert kevin jake
gerald jake kevin lucia john edward';
$obj = App::Basis::ConvertText2::Plugin::Venn->new();
$params = extract_args("title='sample venn diagram' legends='team1 team2 team3' scheme='rgb' explain='1'");
$out = $obj->process( 'sparkline', $content, $params, $TEST_DIR );
ok( has_file($out), 'venn created a file' );
# links
$obj = App::Basis::ConvertText2::Plugin::Text->new();
$content = "pandoc | http://johnmacfarlane.net/pandoc
PrinceXML | http://www.princexml.com
markdown | http://daringfireball.net/projects/markdown
msc | http://www.mcternan.me.uk/mscgen/
ditaa | http://ditaa.sourceforge.net