451 lines
42 KiB
HTML
451 lines
42 KiB
HTML
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Creating and formatting basic Windrose graphs</title><link rel="stylesheet" type="text/css" href="manual.css"><meta name="generator" content="DocBook XSL Stylesheets V1.76.0"><link rel="home" href="index.html" title="JpGraph Manual"><link rel="up" href="ch21.html" title="Chapter 21. Windrose"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Creating and formatting basic Windrose graphs</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center">Chapter 21. Windrose</th><td width="20%" align="right"> </td></tr></table><hr></div><div class="sect1" title="Creating and formatting basic Windrose graphs"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2587220"></a>Creating and formatting basic Windrose graphs</h2></div></div></div>
|
||
|
||
<p>Creation of windrose graphs first requires the inclusion of the library extension
|
||
module "<code class="filename">jpgraph_windrose.php</code>"</p>
|
||
<p>The creation of Windrose graphs otherwise follows the traditional steps in the library
|
||
of creating a graph and then adding one or several windrose plots to the canvas.</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
|
||
<p>Create a basic canvas graph as an instance of <code class="code">class
|
||
WindroseGraph</code></p>
|
||
</li><li class="listitem">
|
||
<p>Create an instance of one or several windrose plots as instances of
|
||
<code class="code">class WindrosePlot</code>, set up the scale and appearance and
|
||
then add them to the graph canvas.</p>
|
||
</li><li class="listitem">
|
||
<p>Send back the graph to the client with a call to
|
||
<code class="code">WindroseGraph::Stroke()</code>. As usual this can be used to
|
||
either send back the graph to the client (e.g.browser) or write the graph to
|
||
a file by specifying a filename as the first argument to
|
||
<code class="code">WindroseGraph::Stroke()</code>.</p>
|
||
</li></ol></div>
|
||
<p>The example in <a class="xref" href="ch21s02.html#fig.windrose_ex0" title="Figure 21.6. A basic 16 direction windrose graph (windrose_ex0.php)">Figure 21.6. A basic 16 direction windrose graph <code class="uri"><a class="uri" href="example_src/windrose_ex0.html" target="_top">(<code class="filename">windrose_ex0.php</code>)</a></code> </a> show a windrose graphs using
|
||
just the default values for all parameters. </p>
|
||
<p>
|
||
</p><div class="example"><a name="example.windrose_ex0"></a><p class="title"><b>Example 21.3. A basic 16 direction windrose graph (<code class="filename">windrose_ex0.php</code>) </b></p><div class="example-contents"> <div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
6
|
||
7
|
||
8
|
||
9
|
||
10
|
||
11
|
||
12
|
||
13
|
||
14
|
||
15
|
||
16
|
||
17
|
||
18
|
||
19
|
||
20
|
||
21
|
||
22
|
||
23
|
||
24
|
||
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags"><?php</span><span class="hl-code">
|
||
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/jpgraph.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/jpgraph_windrose.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Data can be specified using both ordinal index of the axis</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> as well as the direction label</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$data</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-code">
|
||
</span><span class="hl-number">0</span><span class="hl-code"> => </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-number">5</span><span class="hl-code">,</span><span class="hl-number">5</span><span class="hl-code">,</span><span class="hl-number">5</span><span class="hl-code">,</span><span class="hl-number">8</span><span class="hl-brackets">)</span><span class="hl-code">,
|
||
</span><span class="hl-number">1</span><span class="hl-code"> => </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-number">3</span><span class="hl-code">,</span><span class="hl-number">4</span><span class="hl-code">,</span><span class="hl-number">1</span><span class="hl-code">,</span><span class="hl-number">4</span><span class="hl-brackets">)</span><span class="hl-code">,
|
||
</span><span class="hl-quotes">'</span><span class="hl-string">WSW</span><span class="hl-quotes">'</span><span class="hl-code"> => </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-number">1</span><span class="hl-code">,</span><span class="hl-number">5</span><span class="hl-code">,</span><span class="hl-number">5</span><span class="hl-code">,</span><span class="hl-number">3</span><span class="hl-brackets">)</span><span class="hl-code">,
|
||
</span><span class="hl-quotes">'</span><span class="hl-string">N</span><span class="hl-quotes">'</span><span class="hl-code"> => </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-number">2</span><span class="hl-code">,</span><span class="hl-number">3</span><span class="hl-code">,</span><span class="hl-number">8</span><span class="hl-code">,</span><span class="hl-number">1</span><span class="hl-code">,</span><span class="hl-number">1</span><span class="hl-brackets">)</span><span class="hl-code">,
|
||
</span><span class="hl-number">15</span><span class="hl-code"> => </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-number">2</span><span class="hl-code">,</span><span class="hl-number">3</span><span class="hl-code">,</span><span class="hl-number">5</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> First create a new windrose graph with a title</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$graph</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">WindroseGraph</span><span class="hl-brackets">(</span><span class="hl-number">400</span><span class="hl-code">,</span><span class="hl-number">400</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-var">$graph</span><span class="hl-code">-></span><span class="hl-identifier">title</span><span class="hl-code">-></span><span class="hl-identifier">Set</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">A basic Windrose graph</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Create the windrose plot.</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$wp</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">WindrosePlot</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Add and send back to browser</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$graph</span><span class="hl-code">-></span><span class="hl-identifier">Add</span><span class="hl-brackets">(</span><span class="hl-var">$wp</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-var">$graph</span><span class="hl-code">-></span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-inlinetags">?></span></pre></td></tr></table></div></div></div><p><br class="example-break"> </p><div class="figure"><a name="fig.windrose_ex0"></a><p class="title"><b>Figure 21.6. A basic 16 direction windrose graph <code class="uri"><a class="uri" href="example_src/windrose_ex0.html" target="_top">(<code class="filename">windrose_ex0.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/windrose_ex0.png" alt="A basic 16 direction windrose graph (windrose_ex0.php)"></span> </div></div><p><br class="figure-break">
|
||
</p>
|
||
<p>In the same way as for other graph types one or several Windrose plots can be added
|
||
and positioned freely in the Windrose graph by specifying the position as either
|
||
absolute coordinates or as fractions of the width/height of the overall graph.</p>
|
||
<p>
|
||
</p><div class="tip" title="Tip" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Tip</h3>
|
||
<p>An easier way to position Windrose plots is to use layout classes as described
|
||
in <a class="xref" href="ch21s06.html" title="Using layout classes to position Windrose plots">Using layout classes to position Windrose plots</a></p>
|
||
</div><p>
|
||
</p>
|
||
<p>Each instance of the <code class="code">WindrosePlot</code> is added to the overall graph with a
|
||
call to the standard method </p>
|
||
<p>
|
||
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
|
||
<p><code class="code">WindroseGraph::Add($aObject)</code></p>
|
||
</li></ul></div><p>
|
||
</p>
|
||
<p>To avoid that all the plots collide in the middle the positioning and sizing methods
|
||
as shown in the previous sections should be used. </p>
|
||
<p>The following script shows how two plots are displayed in the same graph.</p>
|
||
<p>
|
||
</p><div class="example"><a name="example.windrose_2plots_ex1"></a><p class="title"><b>Example 21.4. Adding two windrose plots to the same graph (<code class="filename">windrose_2plots_ex1.php</code>) </b></p><div class="example-contents"> <div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
6
|
||
7
|
||
8
|
||
9
|
||
10
|
||
11
|
||
12
|
||
13
|
||
14
|
||
15
|
||
16
|
||
17
|
||
18
|
||
19
|
||
20
|
||
21
|
||
22
|
||
23
|
||
24
|
||
25
|
||
26
|
||
27
|
||
28
|
||
29
|
||
30
|
||
31
|
||
32
|
||
33
|
||
34
|
||
35
|
||
36
|
||
37
|
||
38
|
||
39
|
||
40
|
||
41
|
||
42
|
||
43
|
||
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags"><?php</span><span class="hl-code">
|
||
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/jpgraph.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/jpgraph_windrose.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Data can be specified using both ordinal idex of axis as well</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> as the direction label</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$data</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-code">
|
||
</span><span class="hl-number">1</span><span class="hl-code"> => </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-number">10</span><span class="hl-code">,</span><span class="hl-number">10</span><span class="hl-code">,</span><span class="hl-number">13</span><span class="hl-code">,</span><span class="hl-number">7</span><span class="hl-brackets">)</span><span class="hl-code">,
|
||
</span><span class="hl-number">2</span><span class="hl-code"> => </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-number">2</span><span class="hl-code">,</span><span class="hl-number">8</span><span class="hl-code">,</span><span class="hl-number">10</span><span class="hl-brackets">)</span><span class="hl-code">,
|
||
</span><span class="hl-number">4</span><span class="hl-code"> => </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-number">1</span><span class="hl-code">,</span><span class="hl-number">12</span><span class="hl-code">,</span><span class="hl-number">22</span><span class="hl-brackets">)</span><span class="hl-code">,
|
||
</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-var">$data2</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-code">
|
||
</span><span class="hl-number">4</span><span class="hl-code"> => </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-number">12</span><span class="hl-code">,</span><span class="hl-number">8</span><span class="hl-code">,</span><span class="hl-number">2</span><span class="hl-code">,</span><span class="hl-number">3</span><span class="hl-brackets">)</span><span class="hl-code">,
|
||
</span><span class="hl-number">2</span><span class="hl-code"> => </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-number">5</span><span class="hl-code">,</span><span class="hl-number">4</span><span class="hl-code">,</span><span class="hl-number">4</span><span class="hl-code">,</span><span class="hl-number">5</span><span class="hl-code">,</span><span class="hl-number">2</span><span class="hl-brackets">)</span><span class="hl-code">,
|
||
</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Create a new small windrose graph</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$graph</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">WindroseGraph</span><span class="hl-brackets">(</span><span class="hl-number">660</span><span class="hl-code">,</span><span class="hl-number">400</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-var">$graph</span><span class="hl-code">-></span><span class="hl-identifier">SetShadow</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-var">$graph</span><span class="hl-code">-></span><span class="hl-identifier">title</span><span class="hl-code">-></span><span class="hl-identifier">Set</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">Two windrose plots in one graph</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-var">$graph</span><span class="hl-code">-></span><span class="hl-identifier">title</span><span class="hl-code">-></span><span class="hl-identifier">SetFont</span><span class="hl-brackets">(</span><span class="hl-identifier">FF_ARIAL</span><span class="hl-code">,</span><span class="hl-identifier">FS_BOLD</span><span class="hl-code">,</span><span class="hl-number">14</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-var">$graph</span><span class="hl-code">-></span><span class="hl-identifier">subtitle</span><span class="hl-code">-></span><span class="hl-identifier">Set</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">(Using Box() for each plot)</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-var">$wp</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">WindrosePlot</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-var">$wp</span><span class="hl-code">-></span><span class="hl-identifier">SetType</span><span class="hl-brackets">(</span><span class="hl-identifier">WINDROSE_TYPE8</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-var">$wp</span><span class="hl-code">-></span><span class="hl-identifier">SetSize</span><span class="hl-brackets">(</span><span class="hl-number">0</span><span class="hl-number">.42</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-var">$wp</span><span class="hl-code">-></span><span class="hl-identifier">SetPos</span><span class="hl-brackets">(</span><span class="hl-number">0</span><span class="hl-number">.25</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-number">.55</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-var">$wp</span><span class="hl-code">-></span><span class="hl-identifier">SetBox</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-var">$wp2</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">WindrosePlot</span><span class="hl-brackets">(</span><span class="hl-var">$data2</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-var">$wp2</span><span class="hl-code">-></span><span class="hl-identifier">SetType</span><span class="hl-brackets">(</span><span class="hl-identifier">WINDROSE_TYPE16</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-var">$wp2</span><span class="hl-code">-></span><span class="hl-identifier">SetSize</span><span class="hl-brackets">(</span><span class="hl-number">0</span><span class="hl-number">.42</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-var">$wp2</span><span class="hl-code">-></span><span class="hl-identifier">SetPos</span><span class="hl-brackets">(</span><span class="hl-number">0</span><span class="hl-number">.74</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-number">.55</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-var">$wp2</span><span class="hl-code">-></span><span class="hl-identifier">SetBox</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-var">$wp2</span><span class="hl-code">-></span><span class="hl-identifier">SetRangeColors</span><span class="hl-brackets">(</span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">green</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">yellow</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">red</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">brown</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-var">$graph</span><span class="hl-code">-></span><span class="hl-identifier">Add</span><span class="hl-brackets">(</span><span class="hl-var">$wp</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-var">$graph</span><span class="hl-code">-></span><span class="hl-identifier">Add</span><span class="hl-brackets">(</span><span class="hl-var">$wp2</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-var">$graph</span><span class="hl-code">-></span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-inlinetags">?></span></pre></td></tr></table></div></div></div><p><br class="example-break"> </p><div class="figure"><a name="fig.windrose_2plots_ex1"></a><p class="title"><b>Figure 21.7. Adding two windrose plots to the same graph <code class="uri"><a class="uri" href="example_src/windrose_2plots_ex1.html" target="_top">(<code class="filename">windrose_2plots_ex1.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/windrose_2plots_ex1.png" alt="Adding two windrose plots to the same graph (windrose_2plots_ex1.php)"></span> </div></div><p><br class="figure-break">
|
||
</p>
|
||
<div class="sect2" title="Specifying the windrose scale"><div class="titlepage"><div><div><h3 class="title"><a name="id2587433"></a>Specifying the windrose scale</h3></div></div></div>
|
||
|
||
<p>The scale is a property of each plot and is access though the instance variable
|
||
<code class="code">WindrosePlot::scale</code>. The scale consists of the epi-centric circles
|
||
that radiates from the center of the Windrose plot. The step between each circle can
|
||
be set manually or it can be done automatically by the library depending on the data
|
||
values. </p>
|
||
<p>(In order to keep the flow of the text this section leaves the full examples to
|
||
the example section.)</p>
|
||
<p>To manual set the scale of the circles the following method is used:</p>
|
||
<p>
|
||
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
|
||
<p><code class="code">WindrosePlotScale::SetStepSize($aMax,$aStepSize=null)</code></p>
|
||
<p><code class="code">$aMax</code>, The maximum scale value</p>
|
||
<p><code class="code">$aStepSize</code>, The step between each scale circle</p>
|
||
</li></ul></div><p>
|
||
</p>
|
||
<p>By default the library tries multiple of 5:s and 2:s for a visually esthetic grid
|
||
spacing. </p>
|
||
<p>Other example of methods available to adjust the scale are</p>
|
||
<p>
|
||
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
|
||
<p><code class="code">WindrosePlotScale::SetFont($aFontFamily,$aFontStyle=FS_NORMAL,$aFontSize=10)</code></p>
|
||
<p>Specify font for all scale labels apart from the 0-label (in the
|
||
center)</p>
|
||
</li><li class="listitem">
|
||
<p><code class="code">WindrosePlotScale::SetZFont($aFontFamily,$aFontStyle=FS_NORMAL,$aFontSize=10)</code></p>
|
||
<p>Specify the font for the 0-label (in the center)</p>
|
||
</li><li class="listitem">
|
||
<p><code class="code">WindrosePlotScale::SetFontColor($aColor)</code></p>
|
||
<p>Specify font color for all scale labels apart from the 0-label (in the
|
||
center)</p>
|
||
</li><li class="listitem">
|
||
<p><code class="code">WindrosePlotScale::SetZFontColor($aColor)</code></p>
|
||
<p>Specify the font for the 0-label (in the center)</p>
|
||
</li><li class="listitem">
|
||
<p><code class="code">WindrosePlotScale::SetLabelFillColor($aBkgColor,$aBorderColor=false)</code></p>
|
||
<p>Set the background color for the labels</p>
|
||
</li><li class="listitem">
|
||
<p><code class="code">WindrosePlotScale::SetLabelAlign($aAlign)</code></p>
|
||
<p>Set the label text alignment</p>
|
||
</li><li class="listitem">
|
||
<p><code class="code">WindrosePlotScale::SetLabelFormat($aFmt)</code></p>
|
||
<p>Set the label format. This is specified as a "<code class="code">printf()</code>"
|
||
format string.</p>
|
||
</li><li class="listitem">
|
||
<p><code class="code">WindrosePlotScale::Hide($aFlg)</code></p>
|
||
<p>Hide the scale labels</p>
|
||
</li></ul></div><p>
|
||
</p>
|
||
<p>Examples of how to use these methods are shown in the following sections.</p>
|
||
<div class="sect3" title="Specifying fonts and font colors"><div class="titlepage"><div><div><h4 class="title"><a name="id2587654"></a>Specifying fonts and font colors</h4></div></div></div>
|
||
|
||
<p>Fonts can be specified for both the labels on the scale as well as separately
|
||
for the label in the center of the plot. The following code snippet shows how to
|
||
do this (we assume we have already created a windrose plot called
|
||
"<code class="code">windplot</code>") </p>
|
||
<p>
|
||
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
6
|
||
7
|
||
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">// Font and color for scale labels
|
||
$windplot->scale->SetFont(FF_VERDANA,FS_NORMAL,10);
|
||
$windplot->scale->SetFontColor('navy');
|
||
|
||
// Font and color for the center (Zero circle) label
|
||
$windplot->scale->SetZFont(FF_VERDANA,FS_NORMAL,10);
|
||
$windplot->scale->SetZFontColor('navy');</span></pre></td></tr></table></div><p>
|
||
</p>
|
||
</div>
|
||
<div class="sect3" title="Manually specifying the scale"><div class="titlepage"><div><div><h4 class="title"><a name="id2587682"></a>Manually specifying the scale</h4></div></div></div>
|
||
|
||
<p>By default the library automatically determines a scale range and step size
|
||
taking into account the maximum value of data, size of the plot and the font
|
||
size specified for the scale labels. </p>
|
||
<p>However it is possible to force a manual scale and step size with a call to
|
||
<code class="code">Set($aMaxValue,$aStepSize)</code>. This call sets the maximum scale
|
||
value as well as the step size. The step size is optional. If the step size is
|
||
not specified it will be automatically determined. </p>
|
||
<p>
|
||
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">// Specify both maximum value and a step size
|
||
$windplot->scale->Set(40,8);
|
||
...
|
||
// Specify just the maximum value
|
||
$windplot->scale->Set(40);</span></pre></td></tr></table></div><p>
|
||
</p>
|
||
<p>This feature is also illustrated in <a class="xref" href="ch21s07.html#fig.windrose_ex7" title="Figure 21.25. (windrose_ex7.php)">Figure 21.25. <code class="uri"><a class="uri" href="example_src/windrose_ex7.html" target="_top">(<code class="filename">windrose_ex7.php</code>)</a></code> </a> in
|
||
the example part of this chapter.</p>
|
||
<p>
|
||
</p><div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
|
||
<p>The automatic scaling tries to first use step sizes as multiples of 5
|
||
and then multiples of 2 to achieve a suitable spacing of the scale
|
||
lines.</p>
|
||
</div><p>
|
||
</p>
|
||
<p>
|
||
</p><div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
|
||
<p>It might be surprising to see that the scale steps may change when the
|
||
label font is changed. However, this is by design. The reason for this
|
||
is that there is only a certain amount of space available for the labels
|
||
between each step. In order for large fonts to fit the space between the
|
||
grids the step between each circle must be large enough.</p>
|
||
</div><p>
|
||
</p>
|
||
</div>
|
||
<div class="sect3" title="Specifying the label angle"><div class="titlepage"><div><div><h4 class="title"><a name="id2587738"></a>Specifying the label angle</h4></div></div></div>
|
||
|
||
<p>The labels for the scale is placed along a line radiating from the center of
|
||
the windrose plots. The angle for the labels can be either manually or
|
||
automatically determined. </p>
|
||
<p>The labels for the scale is placed along one of the sixteen compass directions
|
||
if you choose automatic positioning of the labels. By default the library tries
|
||
to choose a direction with as little data around it as possible.</p>
|
||
<p>To manually specify the angle a call to <code class="code">SetAngle($aAngle)</code> with
|
||
the angle (in degrees) as argument. </p>
|
||
<p>The code snippet below shows how to do this </p>
|
||
<p>
|
||
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
|
||
2
|
||
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">// Show the labels at 45 degrees angle
|
||
$windplot->scale->SetAngle(45);</span></pre></td></tr></table></div><p>
|
||
</p>
|
||
<p>To specify that the library should do this automatically (which is the
|
||
default) the angle is specified as the string 'auto' as</p>
|
||
<p>
|
||
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
|
||
2
|
||
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">// Let the library determine a good angle
|
||
$windplot->scale->SetAngle('auto');</span></pre></td></tr></table></div><p>
|
||
</p>
|
||
</div>
|
||
<div class="sect3" title="Specifying number formats for scale labels"><div class="titlepage"><div><div><h4 class="title"><a name="id2587797"></a>Specifying number formats for scale labels</h4></div></div></div>
|
||
|
||
<p>In the same way as for other scales in the library it is possible to specify a
|
||
"printf()" format string to adjust the appearance of the labels. By default the
|
||
label format is the same as</p>
|
||
<p>
|
||
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
|
||
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$windplot->scale->SetLabelFormat('%d%%');</span></pre></td></tr></table></div><p>
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div class="sect2" title="Specifying direction labels"><div class="titlepage"><div><div><h3 class="title"><a name="id2587804"></a>Specifying direction labels</h3></div></div></div>
|
||
|
||
<p>With direction labels we mean the names of the compass directions surrounding the
|
||
windrose plot. By default they are given the English short form for the 16 discrete
|
||
compass named directions. This can also be localized (described in ??).</p>
|
||
<div class="sect3" title="Specifying fonts and font colors for the axis titles (direction labels)"><div class="titlepage"><div><div><h4 class="title"><a name="id2587835"></a>Specifying fonts and font colors for the axis titles (direction
|
||
labels)</h4></div></div></div>
|
||
|
||
<p>Fonts for the axis titles are specified with (with the usual arguments)</p>
|
||
<div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
|
||
<p><code class="code">WindrosePlot::SetFont()</code></p>
|
||
</li><li class="listitem">
|
||
<p><code class="code">WindrosePlot::SetFontColor()</code></p>
|
||
</li></ul></div><p>as the following example shows </p>
|
||
<p>
|
||
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
|
||
2
|
||
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$windplot->SetFont(FF_TIMES,FS_BOLD,12);
|
||
$windplot->SetFontColor('darkgreen');</span></pre></td></tr></table></div><p>
|
||
</p>
|
||
<p>Which for example could give a Windrose plot as shown in <a class="xref" href="ch21s07.html#fig.windrose_ex4" title="Figure 21.22. (windrose_ex4.php)">Figure 21.22. <code class="uri"><a class="uri" href="example_src/windrose_ex4.html" target="_top">(<code class="filename">windrose_ex4.php</code>)</a></code> </a></p>
|
||
</div>
|
||
<div class="sect3" title="Setting arbitrary text for data directions"><div class="titlepage"><div><div><h4 class="title"><a name="id2587887"></a>Setting arbitrary text for data directions</h4></div></div></div>
|
||
|
||
<p>Wen using the free direction windrose plots the default label is the direction
|
||
for the data in degrees. This is fully customizable by using the following
|
||
method. </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
|
||
<p><code class="code">WindrosePlot::SetLabels($aLabels)</code></p>
|
||
<p>The input data to this method is an associative array where the
|
||
keys are the direction and the content is the text to be
|
||
displayed.</p>
|
||
</li></ul></div>
|
||
<p>Please note that for regular Windrose plots, i.e. with only compass direction
|
||
the label can not be changed. This is only available if the type of the windrose
|
||
plot is <code class="code">WINDROSE_TYPEFREE</code>.</p>
|
||
<p>The following example specifies a data point at 50 degrees and a text
|
||
"Point\n#7315" as the label.</p>
|
||
<p>
|
||
</p><div class="tip" title="Tip" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Tip</h3>
|
||
<p>Labels can contain "\n" which will be interpreted as a line break.
|
||
</p>
|
||
</div><p>
|
||
</p>
|
||
<p>
|
||
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$data = array( 50 => array(12,12,2) );
|
||
$labels = array( 50 => 'Point #7315' );
|
||
...
|
||
$windplot = new WindrosePlot();
|
||
$windplot->SetLabels($labels);</span></pre></td></tr></table></div><p>
|
||
</p>
|
||
<p>An example of this can be seen in <a class="xref" href="ch21s07.html#fig.windrose_ex6" title="Figure 21.24. (windrose_ex6.php)">Figure 21.24. <code class="uri"><a class="uri" href="example_src/windrose_ex6.html" target="_top">(<code class="filename">windrose_ex6.php</code>)</a></code> </a></p>
|
||
</div>
|
||
<div class="sect3" title="Adjusting the alignment and margin"><div class="titlepage"><div><div><h4 class="title"><a name="id2587959"></a>Adjusting the alignment and margin</h4></div></div></div>
|
||
|
||
<p>There are two basic ways of adjusting the position of the compass labels
|
||
around the plot: </p>
|
||
<p>
|
||
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
|
||
<p>Adjusting the margin between the label and the outer plot
|
||
circle</p>
|
||
</li><li class="listitem">
|
||
<p>Adjusting the anchor point of the labels.</p>
|
||
</li></ul></div><p>
|
||
</p>
|
||
<p>The easiest way to explain this is to first imagine an invisible circle around
|
||
the plot. The margins specifies how far from the outer scale circle this
|
||
imaginative circle is placed. </p>
|
||
<p>In order to position the labels on that circle around the plot there are
|
||
several possible ways to select what point of the text should be positioned on
|
||
the circle. The easiest way is to select the center (both in X and Y directions)
|
||
of the text. This works well if all labels are roughly the same size. If there
|
||
are big difference between the smallest and largest label it might be necessary
|
||
to have a very large margin to avoid the text to "collide" with the plot.</p>
|
||
<p>A better way is to determine the closest point of the text to the plot and
|
||
then make that point lay on the circle. The closets point depends on what
|
||
compass direction the label is on, for example for the "East" label the closes
|
||
point is the middle of the left side of the text and for the "West" the closes
|
||
point is the middle of the right side.</p>
|
||
<p>The library supports both way of positioning through the method </p>
|
||
<div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
|
||
<p><code class="code">WindrosePlot::SetLabelPosition($aPosition)</code></p>
|
||
<p>Valid values for $aPosition are <code class="code">LBLPOSIITON_CENTER</code>
|
||
and <code class="code">LBLPOSITION_EDGE</code> .</p>
|
||
</li></ul></div><p>The following code snippet shows how to specify both margin and
|
||
position do this: </p>
|
||
<p>
|
||
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
|
||
2
|
||
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-code">$windplot->SetLabelMargin(30);
|
||
$windplot->SetLabelPosition(LBLPOSITION_EDGE);</span></pre></td></tr></table></div><p>
|
||
</p>
|
||
<p>The red circle in ?? and ?? illustrates the "imaginative" circle on which the
|
||
labels are placed. The distance from the out most plot circle to the label
|
||
anchor point is the margin.</p>
|
||
<table xmlns="" frame="void" id="id2588065">
|
||
<tbody xmlns="">
|
||
<tr>
|
||
<td>
|
||
<div class="figure"><a name="id2588081"></a><p class="title"><b>Figure 21.8. Positioning with LBLPOSITION_CENTER</b></p><div class="figure-contents">
|
||
|
||
<div class="mediaobject"><img src="images/windrose_label-align1.png" alt="Positioning with LBLPOSITION_CENTER"></div>
|
||
</div></div><br class="figure-break">
|
||
</td>
|
||
<td>
|
||
<div class="figure"><a name="id2588101"></a><p class="title"><b>Figure 21.9. Positioning with LBLPOSITION_EDGE</b></p><div class="figure-contents">
|
||
|
||
<div class="mediaobject"><img src="images/windrose_label-align2.png" alt="Positioning with LBLPOSITION_EDGE"></div>
|
||
</div></div><br class="figure-break">
|
||
</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<p>An example of this can be seen in <a class="xref" href="ch21s07.html#fig.windrose_ex6" title="Figure 21.24. (windrose_ex6.php)">Figure 21.24. <code class="uri"><a class="uri" href="example_src/windrose_ex6.html" target="_top">(<code class="filename">windrose_ex6.php</code>)</a></code> </a></p>
|
||
</div>
|
||
</div>
|
||
</div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"> </td><td width="20%" align="center"><a accesskey="u" href="ch21.html">Up</a></td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>
|