Source

htraf-packaging / demo / doc.html

  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
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
<!DOCTYPE html>
<html>
<head>
    <title>HTRAF Documentation</title>
    <link type="text/css" rel="stylesheet" href="css/htraf-02.css"/>
    <script language="JavaScript" src="../js/lib/jquery-1.4.3.js"></script>
    <script language="JavaScript" src="../js/lib/creole.js"></script>
    <script language="JavaScript">
        function id(s) {
            return $.trim(s).toLowerCase().replace(/[^A-Za-z_-]/g, '_');
        }
        Parse.Simple.Doc = function(options) {
            Parse.Simple.Creole.call(this, options);
                
            var g = this.grammar;
            this.grammar.def = {
                regex: /\`\`(.+?)\`\`/,
                build: function(node, r, options) {
                    var uri = '#' + id(r[1]); 
                    g.namedUri.build.call(this, node, 
                                          [null, uri, r[1]], options);
                }
            };

            this.grammar.li.children.push(this.grammar.def);
            this.grammar.paragraph.children.push(this.grammar.def);

            this.grammar.root = new this.ruleConstructor(this.grammar.root);
        }
        Parse.Simple.Doc.prototype = new Parse.Simple.Creole();
        Parse.Simple.Doc.prototype.constructor = Parse.Simple.Doc;

        $(function() {
            $('.creole').each(function() {
                var data = $(this).text();
                $(this).text('');
                var creole = new Parse.Simple.Doc({});
                creole.parse(this, data);
            });

            $('h1,h2,h3').each(function() {
                $(this).attr('id', id($(this).text()));
            });
        });
    </script>

    <style>
        html, body {
            width: 100%;
            height: 100%;
            padding: 0px;
        }
        div.menu {
            position: absolute;
            width: 200px;
            top: 0px;
            bottom: 0px;
            left: 0px;
            overflow: auto;
            padding-top: 10px;
            padding-left: 10px;
        }
        a {
            border-bottom-width: 0px;
        }
        a:hover {
            border-bottom-width: 1px;
        }
        div.menu ul {
            margin:0 0 5px 10px;
        }

        div.doc {
            position: absolute;
            left: 220px;
            right: 10px;
            bottom: 0px;
            top: 0px;
            overflow: auto;
        }
        div.doc h1 {
            margin: 1em 0 0 0;
        }
        div.doc h3 {
            font-size: 1em;
        }
        strong {
            font-weight: bold;
        }
        em {
            font-style: italic;
            color: #555555;
        }
        ol {
            list-style-type: decimal;
            list-style-position: inside;
            color: #555555;
        }
        pre {
            font-family: Monaco, monospace;
            font-size: 0.9em;
        }
    </style>
</head>
<body>
    <div class="menu creole">
* ``Widgets``
** ``table``
** ``select``
** ``list``
** ``iframe``
** ``chart``
** ``singleValue``
* ``Attributes``
** ``data-htsql``
** ``data-widget``
** ``data-onchange``
** ``data-onerror``
** ``data-onempty``
** ``data-onbeforeload``
** ``data-onafterload``
** ``data-column``
** ``data-type``
** ``data-show-title``
** ``data-title``
** ``data-legend``
** ``data-x-vertical``
** ``data-hide-column-N``
    </div>
    <div class="doc creole">
== Widgets
Every tag in the HTML document marked with the ``data-htsql`` attribute 
is considered as //widget//. Each widget is loaded
with data according to ``data-htsql`` attribute and rendered according to
data received and ``attributes`` specified. Typically, widget's children are 
removed, so make sure to not keep any data/markup inside those tags in your
HTML. 

The type of widget is determined as following:

# ``data-widget`` value if specified;
# tag name;
# if nothing of above fits, ``singleValue`` widget is used.

=== table
HTML &lt;table&gt; with &lt;thead&gt; header and &lt;tbody&gt; content. The
simplest and typical representation of the query resultset. When row is 
selected the value of column #0 becomes the value of the whole widget. 
Optional ``data-hide-column-N`` (N is integer) attributes may be used to hide
columns. Even column is hidden it is still could be accessed.

**Custom Attributes:** ``data-hide-column-N``

**Example ([[basic/index.html|functional]]): **
{{{
<pre>
    &lt;table id="department"
        data-htsql="/department{code, name, school.name}
                     ?school=$school&amp;name~$department_name"&gt;
    &lt;/table&gt;
</pre>
}}}

=== select
HTML &lt;select&gt; tag. Generates options based on resultset. Each row
becomes an option, where the first column is its value, the second one is
its text. In case if resultset has only 1 column - uses its value for both:
value and text.

**Example ([[basic/index.html|functional]]): **
{{{
<pre>
    &lt;select data-htsql="/school{id(), name}" id="school"&gt;&lt;/select&gt;
</pre>
}}}

=== list
&lt;ul&gt; and &lt;ol&gt; tags. Generates &lt;li&gt; per each row in resultset
much like ``select`` does: the first column becomes the value, the second
is used for text (falling back to the first if row length is 1). Note, that 
items are selectable. 

**Example ([[iframe_list.html|functional]]): **
{{{
<pre>
    &lt;ul data-htsql="/school{id(), name}" id="school"&gt;&lt;/ul&gt;
</pre>
}}}

=== iframe
HTML &lt;iframe&gt; with the //src// attr generated dynamically basing on
``data-htsql`` specified. 

**Example ([[iframe_list.html|functional]]): **
{{{
<pre>
    &lt;iframe data-htsql="/school{id(), name}" id="school"&gt;&lt;/iframe&gt;
</pre>
}}}

=== chart
HTML &lt;div&gt; tag used as the canvas for drawing charts using the 
[[http://www.jqplot.com|jqPlot]] library. Note, that element width and
height should be specified, i.e. there should be some space to draw the chart. 
At the moment, 4 types of chart are supported: //pie//, //line//, //bar// and 
//stack//. 

**pie** chart is the simplest one, it uses the resultset of 2 
columns. The first column is the pie segment identifier (used for legend), 
the second one is the numeric value, which defines how big the pie segment is.

**bar**, **stack** and **line** charts require the similar 2+ columns 
resultsets, where the first column represents the X axis (**line** has
the restriction here: when using it the first column should be either date,
datetime or numeric). Every following column represents the series of Y values.
Legend is contructed of column titles starting from the second column. 


**Custom Attributes:** ``data-show-title``, ``data-title``, ``data-legend``,
                       ``data-x-vertical``

**Example ([[chart.html|functional]]): **
{{{
<pre>
    &lt;div style="width: 750px; height: 400px;" 
         data-htsql="/program{degree^,count(student)}" 
         data-widget="chart"
         data-type="pie"&gt;&lt;/div&gt;
    &lt;div class="chart" 
        data-htsql="/student{dob.year()^,count(gender='f') as Females,
                            count(gender='m') as Males}" 
         data-widget="chart"
         data-type="bar"&gt;&lt;/div&gt;

</pre>
}}}

=== singleValue

Could be used with any HTML widget, also used as the fallback, when no widget
is specified. Takes the value of the first row and first column and replaces
the tag contents with it.


**Example ([[basic/index.html|functional]]): **
{{{
<pre>
    &lt;em data-htsql="/department{name}?code=$department"&gt;&lt;/em&gt;
</pre>
}}}


== Attributes
All HTRAF-specific attributes start with ``data-`` prefix. Almost all of them
are optional (except of ``data-htsql``). Use them to customize widget's 
behavior and appearance. Note, if you change them using //$(...).attr()// call
the related widget will be reloaded and/or re-rendered.
{{{
<pre>
</pre>
}}}

=== data-htsql

* //Required, HTSQL expression or link to .htsql resource//
* //Widgets: all//

The most important attribute. Actually triggers all further HTRAF processing
on the HTML tag. Any valid HTSQL expression or a link to //*.htsql// resource
is permitted there. Please note, that all HTSQL **$variables** will be bound
to a page elements with the matching identifier. For example, 
&lt;input id="variables"&gt; would match the previously mentioned variable.

**Example ([[basic/index.html|functional]]): **
{{{
<pre>
    &lt;select data-htsql="/school{id(), name}" id="school"&gt;&lt;/select&gt;
    &lt;table id="department"
        data-htsql="/department{code, name, school.name}
                     ?school=$school"&gt;
    &lt;/table&gt;
</pre>
}}}

Make sure to list all dependent variables in data-htsql when using the 
//.htsql// resources. Otherwise HTRAF never know how to bind page elements.
The example would be:
{{{
<pre>
    &lt;select data-htsql="/-/school.htsql" id="school"&gt;&lt;/select&gt;
    &lt;table id="department"
        data-htsql="/-/department.htsql?school=$school"&gt;
    &lt;/table&gt;
</pre>
}}}

=== data-widget

* //Optional, String//
* //Widgets: all(although currently makes sense for 'chart' only) //

Specifies the widget name.

=== data-onchange

* //Optional, String//
* //Widgets: all//

JavaScript code to be executed when widget's value changes. Inside the 
attribute //this// points to the DOM element attribute belongs to.
**Example:**
{{{
<pre>
    &lt;table id="department" data-onchange="alert($(this).val())"
        data-htsql="/-/department.htsql?school=$school"&gt;
    &lt;/table&gt;
</pre>
}}}

=== data-onerror

* //Optional, String//
* //Widgets: all//

JavaScript code to be executed when widget's loading produces an error on the
server (usually means that incorrect HTSQL was specified). Inside the 
attribute //this// points to the DOM element attribute belongs to, first 
argument holds the error information.
**Example:**
{{{
<pre>
    &lt;table id="department" 
        data-onerror="alert($(this).attr('id') + ' ' + arguments[0].reason)"
        data-htsql="bad-htsql"&gt;
    &lt;/table&gt;
</pre>
}}}

=== data-empty

* //Optional, String//
* //Widgets: all//

JavaScript code to be executed when widget is loaded but the resultset is 
empty. Inside the attribute //this// points to the DOM element attribute 
belongs to.
**Example:**
{{{
<pre>
    &lt;table id="department" data-onempty="$(this).hide()"
        data-htsql="/-/department.htsql?school=$school"&gt;
    &lt;/table&gt;
</pre>
}}}

=== data-onbeforeload

* //Optional, String//
* //Widgets: all//

JavaScript code to be executed before loading the widget. 
Inside the attribute //this// points to the DOM element attribute belongs to.

=== data-onafterload

* //Optional, String//
* //Widgets: all//

JavaScript code to be executed after the widget is loaded. 
Inside the attribute //this// points to the DOM element attribute belongs to.

=== data-type

* //Optional, Choice ('line', 'bar', 'stack', 'pie')//
* //Widgets: // ``chart``

Chart type, defaults to 'line'.

=== data-show-title

* //Optional, Boolean ('yes', 'true', 'no', 'false')//
* //Widgets: // ``chart``

=== data-title

* //Optional, Any//
* //Widgets: // ``chart``

Title to be shown at the top of the chart. By default shows the HTSQL query.

=== data-legend

* //Optional, Choice ('se', 'ne', 'sw', 'nw', 'no')//
* //Widgets: // ``chart``
Chart legend control: 'se' means south-east, 'nw' means north-east etc. 
'no' means hide the legend entirely. Defaults to 'ne'.

=== data-x-vertical

* //Optional, Boolean ('yes', 'true', 'no', 'false')//
* //Widgets: // ``chart``
When set to true, marks on the X axis are shown vertically.

=== data-hide-column-N

* //Optional, Boolean ('yes', 'true', 'no', 'false')//
* //Widgets: // ``table``
When set to true, column N is hidden (N starts from 0). 

    </div>
</body>
</html>