initial commit
[home-automation.git] / RGraph / docs / external.html
1 <?php ob_start('ob_gzhandler') ?>
2 <!DOCTYPE html >
3 <html>
4 <head>
5     <meta http-equiv="X-UA-Compatible" content="chrome=1">
6     <!--
7         /**
8         * o------------------------------------------------------------------------------o
9         * | This file is part of the RGraph package - you can learn more at:             |
10         * |                                                                              |
11         * |                          http://www.rgraph.net                               |
12         * |                                                                              |
13         * | This package is licensed under the RGraph license. For all kinds of business |
14         * | purposes there is a small one-time licensing fee to pay and for non          |
15         * | commercial  purposes it is free to use. You can read the full license here:  |
16         * |                                                                              |
17         * |                      http://www.rgraph.net/LICENSE.txt                       |
18         * o------------------------------------------------------------------------------o
19         */
20     -->
21     <title>RGraph: HTML5 canvas graph library - Integrating RGraph with external libraries</title>
22     
23     <meta name="keywords" content="rgraph html5 canvas graph docs external libraries" />
24     <meta name="description" content="RGraph: HTML5 canvas graph software - Documentation about integrating RGraph with external libraries" />
25
26     <link rel="stylesheet" href="../css/website.css" type="text/css" media="screen" />
27     <link rel="stylesheet" href="../css/ModalDialog.css" type="text/css" media="screen" />
28     <link rel="icon" type="image/png" href="../images/favicon.png">
29
30     <script src="../libraries/RGraph.modaldialog.js" ></script>
31     <script src="../libraries/RGraph.common.core.js" ></script>
32     <script src="../libraries/RGraph.common.context.js" ></script>
33     <script src="../libraries/RGraph.line.js" ></script>
34     <!--[if IE 8]><script src="../excanvas/excanvas.compressed.js"></script><![endif]-->
35     
36     <script>
37         window.onload = function ()
38         {
39             /**
40             * Draw the line graph
41             */
42             var line = new RGraph.Line('myLine', [45,12,16,18,44,54,23,21,56,58,33,47]);
43             line.Set('chart.background.barcolor1', 'white');
44             line.Set('chart.background.barcolor2', 'white');
45             line.Set('chart.tickmarks', null);
46             line.Set('chart.hmargin', 10);
47             line.Set('chart.linewidth', 3);
48             line.Set('chart.shadow', true);
49             line.Set('chart.shadow.offset', 2);
50             line.Set('chart.labels', ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']);
51             line.Set('chart.title', 'A line graph with context menu');
52
53             // This defines a context menu which shows the dialog. The commented out
54             // bit defines an onclick handler on the background, so that when you
55             // click it (the background), the dialog is hidden.
56             line.Set('chart.contextmenu', [ 
57                                            ['Login to admin area...', function () {ModalDialog.Show('myDialog', 300);/*ModalDialog.background.onclick = function () {ModalDialog.Close();};*/}],
58                                            null,
59                                            ['Cancel', function () {}]
60                                           ]);
61
62             line.Draw();
63         }
64     </script>
65
66
67     <style>
68         /*
69         * These are the CSS classes that you can use to customise the appearance of the ModalDialog. If you're trying to
70         * override something which the scripts set, then because of the ordering you may need to use the "! important"
71         * modifier.
72         */
73         .ModalDialog_background {
74         }
75
76         .ModalDialog_dialog {
77             -webkit-box-shadow: gray 0 0 15px ! important;
78             -moz-box-shadow: 0 0 15px gray ! important;
79             box-shadow: 0 0 15px gray ! important;
80         }
81
82         .ModalDialog_topbar {
83         }
84     </style>
85
86 </head>
87 <body>
88
89     <!-- Social networking buttons -->
90     <script src="../libraries/RGraph.common.core.js" ></script>
91     
92     <script>
93         function HideTwitterDIV ()
94         {
95             document.getElementById("twitter_div").style.opacity = 0;
96             document.getElementById("twitter_div").style.display = 'none';
97         }
98
99
100         function ShowTwitterDIV (e)
101         {
102             var e   = RGraph.FixEventObject(document.all ? event : e);
103             var div = document.getElementById("twitter_div");
104             var img = document.getElementById("twitter_icon");
105
106             div.style.display = 'block';
107             div.style.left    = (RGraph.getCanvasXY(img)[0] + img.offsetWidth - div.offsetWidth + 110) + 'px';
108             div.style.top     = (RGraph.getCanvasXY(img)[1] - 1) + 'px';
109
110             /**
111             * Fade it in
112             */
113             setTimeout('document.getElementById("twitter_div").style.opacity = 0.2;', 25);
114             setTimeout('document.getElementById("twitter_div").style.opacity = 0.4;', 50);
115             setTimeout('document.getElementById("twitter_div").style.opacity = 0.6;', 100);
116             setTimeout('document.getElementById("twitter_div").style.opacity = 0.8;', 125);
117             setTimeout('document.getElementById("twitter_div").style.opacity = 1.0;', 150);
118
119             e.stopPropagation();
120
121             return false;
122         }
123
124         /**
125         * This code installs the event handler that hides the Twitter DIV
126         */
127         if (RGraph.isIE8()) {
128              window.attachEvent('onload', function () {document.body.attachEvent('onclick', HideTwitterDIV);});
129         } else {
130             window.addEventListener('click', HideTwitterDIV, false);
131         }
132     </script>
133
134     <!-- The twitter DIV --> 
135     <div id="twitter_div" style="position: absolute;top: 0;left: 0;background-color: #eee;border: 2px dashed black;box-shadow: 0 0 15px #aaa;-moz-box-shadow: 0 0 15px #aaa;-webkit-box-shadow: 0 0 15px #aaa;padding: 3px;display: none;opacity: 0;z-index: 99;"> 
136         <a href="http://twitter.com/home/?status=RGraph%3A+HTML5+canvas+graph+library+based+on+the+HTML5+canvas+tag+http%3A%2F%2Fwww.rgraph.net+%23rgraph+%23html5+%23canvas" target="_blank" title="Share on Twitter" rel="nofollow" style="text-decoration: none">Tweet&nbsp;about&nbsp;RGraph</a><br>
137         <a href="http://twitter.com/_rgraph" style="text-decoration: none" rel="nofollow" target="_blank">Follow for HTML5 news</a> 
138     </div>
139
140     <div id="social_icons" class="warning" style="top: 0; left: 5px; position: absolute">
141         <script>
142             // Opera fix
143             if (navigator.userAgent.indexOf('Opera') == -1) {
144               document.getElementById("social_icons").style.position = 'fixed';
145               document.getElementById("twitter_div").style.position = 'fixed';
146     
147             }
148         </script>
149     
150         <b style="display: inline-block; position: relative; top: 1px">Bookmark and share:</b>
151     
152     
153             <div id="social">
154                 <a title="Bookmark with delicious" href="http://delicious.com/save?jump=close&v=4&noui&jump=close&url=http://www.rgraph.net&notes=RGraph%20is%20a%20HTML5%20based%20graph%20library%20supporting%20a%20wide%20range%20of%20different%20graph%20types:Bar,%20Bipolar,%20Donut,%20Funnel,%20Gantt,%20Horizontal%20Bar,%20LED,%20Line,%20Meter,%20Odometer,%20Pie,%20Progress%20Bar,%20Rose,%20RScatter,%20Scatter%20and%20Traditional%20Radar&title=RGraph:%20HTML5%20canvas%20graph%20library%20based%20on%20the%20HTML5%20canvas%20tag" target="_blank">
155                     <img src="../images/delicious.png" alt="Bookmark with delicious" width="22" height="22" border="0" align="absmiddle" /> 
156                 </a> 
157      
158                 <a href="" target="_blank" onmouseover="if (document.getElementById('twitter_div').style.display == 'none') ShowTwitterDIV(event);" onclick="event.stopPropagation(); event.cancelBubble = true; return false">
159                     <img src="../images/twitter.png" id="twitter_icon" alt="tweet this site" width="22" height="22" border="0" align="absmiddle" />
160                 </a>
161     
162     
163 <!--
164                 <a title="Post to Google Buzz!" href="" onclick="window.open('http://www.google.com/buzz/post?url=http://www.rgraph.net&imageurl=http://www.rgraph.net/images/logo.png', 'google_buzz_window', 'width=800,height=400,top=100,left=100'); return false">
165                     <img src="../images/buzz.png" width="22" height="22" alt="Post to Google Buzz!" align="absmiddle" style="position: relative; top: -2px; border: 0" border="0"/>
166                 </a>
167     
168     
169                 <a title="Share RGraph on Facebook" href="" onclick="window.open('http://www.facebook.com/sharer.php?u=http://www.rgraph.net&t=RGraph:%20HTML5%20canvas%20graph%20library', 'facebook_window', 'width=500,height=300,top=100,left=100'); return false">
170                     <img src="../images/facebook.png" width="22" height="22" alt="Post to Facebook" align="absmiddle" style="position: relative; top: -2px; border: 0" border="0"/>
171                 </a>
172     
173                 <a href="mailto:share@friendfeed.com" title="Share on FriendFeed"> 
174                     <img src="../images/friendfeed.png" width="22" height="22" alt="Share on FriendFeed" border="0" align="absmiddle" /> 
175                 </a>
176     
177                 <a href="http://www.stumbleupon.com/submit?url=http://www.rgraph.net" target="_blank" title="Share on StumbleUpon" >
178                     <img src="../images/stumble.png" alt="Stumble! this site" width="22" height="22" border="0" align="absmiddle" /> 
179                 </a>
180 -->
181             </div>
182     </div>
183     <!-- /Social networking buttons -->
184
185
186     <div id="breadcrumb">
187         <a href="../index.html">RGraph: HTML5 canvas graph library</a>
188         >
189         <a href="index.html">Documentation</a>
190         >
191         Integrating RGraph with external libraries
192     </div>
193
194     <h1>RGraph: HTML5 canvas graph library - Integrating RGraph with external libraries</h1>
195
196     <script>
197         if (RGraph.isIE8()) {
198             document.write('<div style="background-color: #fee; border: 2px dashed red; padding: 5px"><b>Important</b><br /><br /> Internet Explorer 8 does not natively support the HTML5 canvas tag, so if you want to see the graphs, you can either:<ul><li>Install <a href="http://code.google.com/chrome/chromeframe/">Google Chrome Frame</a></li><li>Use ExCanvas. This is provided in the RGraph Archive.</li><li>Use another browser entirely. Your choices are Firefox 3.5+, Chrome 2+, Safari 4+ or Opera 10.5+. </li></ul> <b>Note:</b> Internet Explorer 9 fully supports the canvas tag. Click <a href="http://groups.google.com/group/rgraph/browse_thread/thread/c5651ff8c56b8f3c#" target="_blank">here</a> to see some screenshots.</div>');
199         }
200     </script>
201
202     <ul>
203         <li><a href="#msie">Note about Microsoft Internet Explorer and the ModalDialog</a></li>
204         <li><a href="#hiding">Hiding the ModalDialog</a></li>
205         <li><a href="#customising">Customising the ModalDialog</a></li>
206         <li><a href="#integration">ModalDialog integration</a></li>
207     </ul>
208
209     <canvas id="myLine" width="400" height="200" style="float: right">[No canvas support]</canvas>
210
211     <p>
212         This page shows you how you can easily integrate the graphs with other external Javascript libraries. This particular example
213         attaches a context menu to the graph, of which the only option is to show a login dialog. This could, for example, be used to
214         allow logging in to an admin area.
215     </p>
216     
217     <p>
218         The dialog doesn't need to require user input - it could just be a static "Please wait..." type dialog, which is shown while a
219         subsequent page loads that takes a few seconds.
220     </p>
221         
222     <p>
223         The ModalDialog was originally an external library, however it's now part of the RGraph package. It's also covered by the
224         RGraph license - so if you have an <a href="licensing.html">RGraph license</a>, then the ModalDialog is part of that.
225     </p>
226
227     <br /><br />
228
229     <pre class="code">
230 &lt;script src="RGraph.common.core.js"&gt;
231 &lt;script src="RGraph.common.context.js"&gt;
232 &lt;script src="RGraph.line.js"&gt;
233 &lt;script src="RGraph.modaldialog.js"&gt;
234
235 &lt;script&gt;
236     window.onload = function ()
237     {
238         /**
239         * Draw the line graph
240         */
241         var line = new RGraph.Line('myLine', [45,12,16,18,44,54,23,21,56,58,33,47]);
242         line.Set('chart.background.barcolor1', 'white');
243         line.Set('chart.background.barcolor2', 'white');
244         line.Set('chart.tickmarks', null);
245         line.Set('chart.hmargin', 10);
246         line.Set('chart.linewidth', 3);
247         line.Set('chart.shadow', true);
248         line.Set('chart.shadow.offset', 2);
249         line.Set('chart.labels', ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']);
250         line.Set('chart.title', 'A line graph with context menu');
251         <span style="color: green">
252         // This defines a context menu which calls the given function. This function in turn shows the dialog
253         line.Set('chart.contextmenu', [['Login to admin area...', function () {ModalDialog.Show('myDialog', 300);}}]]);
254         </span>
255         line.Draw();
256     }
257 &lt;/script&gt;</pre>
258
259     <p>
260         If you're interested in using this modal dialog, then you'll probably also want the CSS that styles it. This can be found in the
261         &quot;css&quot; directory.
262     </p>
263
264     <a name="msie"></a>
265     <h3>Note about Microsoft Internet Explorer 8 and the ModalDialog</h3>
266     
267     <p>
268         Microsoft Internet Explorer 8 only supports fixed positioning in strict rendering mode, therefore you must specify a DTD
269         when using this browser. Eg:
270     </p>
271     
272     <pre class="code">
273 &lt;!DOCTYPE html &gt;
274 </pre>
275
276     <a name="hiding"></a>
277     <h3>Hiding the ModalDialog</h3>
278     <p>
279         To hide the ModalDialog (from a "Cancel" button for example), you can use the Close() method:
280     </p>
281     
282     <pre class="code">
283 &lt;input type="reset" value="Cancel" onclick="ModalDialog.Close()"&gt;
284 </pre>
285
286     <a name="customising"></a>
287     <h3>Customising the ModalDialog</h3>
288     <p>
289         You can customise the appearance of the ModalDialog by using three CSS classes, which are documented <a href="css.html">here</a>.
290         This page customises the dialog slightly by changing the shadow X/Y offsets:
291     </p>
292     
293     <pre class="code">
294 &lt;style&gt;
295     /*
296     * These are the CSS classes that you can use to customise the appearance of the ModalDialog. If you're trying to
297     * override something which the scripts set, then because of the ordering you may need to use the "! important"
298     * modifier.
299     */
300     
301     /**
302     * This is the semi-opaque background
303     */
304     .ModalDialog_background {
305     }
306
307
308     /**
309     * This is the dialog itself
310     */
311     .ModalDialog_dialog {
312         -webkit-box-shadow: gray 0 0 15px ! important;
313         -moz-box-shadow: 0 0 15px gray ! important;
314         box-shadow: 0 0 15px gray ! important;
315     }
316
317
318     /**
319     * This is gray bar at the top of the dialog
320     */
321     .ModalDialog_topbar {
322     }
323 &lt;/style&gt;
324 </pre>
325
326     <a name="integration"></a>
327     <h3>ModalDialog integration</h3>
328     <p>
329         To integrate the ModalDialog look at the sample code above (the key line is where the context menu is defined). The method you should call is <b>ModalDialog.Show(id, width)</b>.
330         The <i>id</i> is the <i>id</i> of the layer to use. Only the <i>.innerHTML</i> is used, not the layer itself, so it can be hidden by
331         setting the display CSS <i>display</i> property to <i>none</i>. The <i>width</i> is a number which is used as the width of the dialog.
332     </p>
333     
334     <p>
335         The only library needed for the ModalDialog to work is <i>RGraph.modaldialog.js</i> - you do not need to use
336         <i>RGraph.common.js</i>. This makes for far smaller download requirements.
337         
338     </p>
339
340     <!-- This is the popup dialog-->
341
342         <div id="myDialog" class="modalDialog" style="display: none">
343
344             <b>Please login</b>
345             <p>
346                 <table border="0">
347                     <tr>
348                         <td align="right" style="padding-top: 4px">Email</td>
349                         <td><input type="text" size="20" name="email" style="width: 150px" /></td>
350                     </tr>
351
352                     <tr>
353                         <td align="right" style="padding-top: 4px">Password</td>
354                         <td><input type="password" size="20" name="password" style="width: 150px" /></td>
355                     </tr>
356                     
357                     <tr>
358                         <td colspan="2" align="right">
359                             <input type="reset" value="Cancel" onclick="ModalDialog.Close()">
360                             <input type="submit" name="submit" value="Login &raquo;" onclick="alert('This is just an example'); if (document.all) event.cancelBubble = true; else event.stopPropagation()">
361                         </td>
362                     </tr>
363                 </table>
364             </p>
365         </div>
366
367     <!-- End of dialog -->
368
369 </body>
370 </html>