Subversion-Projekte lars-tiefland.ci

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
875 lars 1
<?php
2
    $title = "Pyramid Chart By Age";
3
?>
4
<?php include "opener.php"; ?>
5
 
6
<!-- Example scripts go here -->
7
    <link class="include" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/themes/smoothness/jquery-ui.css" rel="Stylesheet" />
8
    <link href="colorpicker/jquery.colorpicker.css" rel="stylesheet" type="text/css"/>
9
    <style type="text/css">
10
 
11
        .quintile-outer-container {
12
            width: 97%;
13
            height: 97%;
14
            margin: auto;
15
        }
16
 
17
        .jqplot-chart {
18
            height: 600px;
19
        }
20
 
21
        .quintile-toolbar .ui-icon {
22
            float: right;
23
            margin: 3px 5px;
24
        }
25
 
26
        table.stats-table td, table.highlighted-stats-table td {
27
            background-color: rgb(230, 230, 230);
28
            padding: 0.5em;
29
        }
30
 
31
        col.label {
32
            width: 14em;
33
        }
34
 
35
        col.value {
36
            width: 7em;
37
        }
38
 
39
        td.quintile-value {
40
            width: 7em;
41
            text-align: right;
42
        }
43
 
44
        table.stats-table td.tooltip-header, table.highlighted-stats-table td.tooltip-header {
45
            background-color: rgb(200, 200, 200);
46
        }
47
 
48
        table.stats-table, table.highlighted-stats-table, td.contour-cell {
49
            font-size: 0.7em;
50
        }
51
 
52
        td.contour-cell {
53
            height: 1.5em;
54
            padding-left: 20px;
55
            padding-bottom: 1.5em;
56
        }
57
 
58
        table.highlighted-stats-table {
59
            margin-top: 15px;
60
        }
61
 
62
        div.stats-cell div.input {
63
            font-size: 0.7em;
64
            margin-top: 1.5em;
65
        }
66
 
67
        div.content-container {
68
            padding-left: 230px;   /* LC width */
69
            padding-right: 300px;  /* RC width */
70
            height: 100%;
71
        }
72
 
73
        div.content-container .column {
74
            position: relative;
75
            float: left;
76
        }
77
 
78
        div.controls {
79
            width: 170px;          /* LC width */
80
            right: 230px;          /* LC width */
81
            padding-left: 30px;
82
            padding-right: 30px;
83
            margin-left: -100%;
84
            margin-top: 30px;
85
        }
86
 
87
        div.chart-cell {
88
            width: 100%;
89
            height: 100%;
90
        }
91
 
92
        div.stats-cell {
93
            width: 270px;          /* RC width */
94
            margin-right: -300px;  /* RC width */
95
            padding-right: 30px;
96
            margin-top: 30px;
97
        }
98
 
99
        div.controls, div.controls select {
100
            font-size: 0.8em;
101
        }
102
 
103
        div.controls li {
104
            list-style-type: none;
105
        }
106
 
107
        div.controls ul {
108
            margin-top: 0.5em;
109
            padding-left: 0.2em;
110
        }
111
 
112
        div.overlay-chart-container {
113
            display: none;
114
            z-index: 11;
115
            position: fixed;
116
            width: 800px;
117
            left: 50%;
118
            margin-left: -400px;
119
            background-color: white;
120
        }
121
 
122
        div.overlay-chart-container div.ui-icon {
123
            float: right;
124
            margin: 3px 5px;
125
        }
126
 
127
        div.overlay-shadow {
128
            display: none;
129
            z-index: 10;
130
            background-color: rgba(0, 0, 0, 0.8);
131
            position: fixed;
132
            top: 0px;
133
            left: 0px;
134
            width: 100%;
135
            height: 100%;
136
        }
137
 
138
        div.ui-colorpicker div.ui-dialog-titlebar {
139
            padding: 0.1em 0.3em;
140
        }
141
 
142
        input.color {
143
            display: none;
144
        }
145
 
146
        div.colorpicker-container span {
147
            padding: 3px;
148
        }
149
 
150
        div.quintile-content {
151
            width: 100%;
152
            height: 100%;
153
        }
154
 
155
 
156
        @media print {
157
            div.stats-cell {
158
                vertical-align: top;
159
                padding-top: 35px;
160
            }
161
 
162
            table.stats-table, table.stats-table td {
163
                 color: #aaaaaa;
164
                 border: 1px solid #bbbbbb;
165
                 border-collapse: collapse;
166
            }
167
 
168
            table.stats-table tr {
169
                font-family: Verdana,Arial,sans-serif;
170
                /*font-size: 0.7em;*/
171
            }
172
        }
173
 
174
    </style>
175
 
176
    <div class="overlay-shadow"></div>
177
 
178
    <div class="overlay-chart-container ui-corner-all">
179
        <div class="overlay-chart-container-header ui-widget-header ui-corner-top">Right click the image to Copy or Save As...<div class="ui-icon ui-icon-closethick"></div></div>
180
        <div class="overlay-chart-container-content ui-corner-bottom"></div>
181
    </div>
182
 
183
    <div class="quintile-outer-container ui-widget ui-corner-all">
184
        <div class="quintile-toolbar ui-widget-header  ui-corner-top">
185
            <span class="quintile-title">Income Level:</span>
186
        </div>
187
        <div class="quintile-content ui-widget-content ui-corner-bottom">
188
 
189
            <div class="content-container">
190
 
191
 
192
            <div class="chart-cell column">
193
                <div id="agesChart" class="jqplot-chart"></div>
194
            </div>
195
 
196
            <div class="controls column">
197
                <table>
198
                    <tr>
199
                        <td>
200
                            Axes:
201
                        </td>
202
                        <td>
203
                            <select name="axisPosition">
204
                                <option value="both">Left &amp; Right</option>
205
                                <option value = "left">Left</option>
206
                                <option value = "right">Right</option>
207
                                <option value = "mid">Mid</option>
208
                            </select>
209
                        </td>
210
                    </tr>
211
                    <tr>
212
                        <td>
213
                            Colors:
214
                        </td>
215
                        <td>
216
                            <ul>
217
                                <li><input class="color" type="color" id="colorMale" value="#526D2C" /> Male</li>
218
                                <li><input class="color" type="color" id="colorFemale" value="#77933C" /> Female</li>
219
                                <li><input class="color" type="color" id="colorBackground" value="#ffffff" /> Background</li>
220
                                <li><input class="color" type="color" id="colorPlotBands" value="f5ebd7" /> Plot Bands</li>
221
                            </ul>
222
                        </td>
223
                    </tr>
224
                    <tr>
225
                        <td>
226
                            Grids:
227
                        </td>
228
                        <td>
229
                            <ul>
230
                                <li><input name="gridsVertical" value="vertical" type="checkbox" />Vertical</li>
231
                                <li><input name="gridsHorizontal" value="horizontal" type="checkbox" />Horizontal</li>
232
                                <li><input name="showMinorTicks" value="true" type="checkbox" checked />Only major</li>
233
                                <li><input name="plotBands" value="true" type="checkbox" checked />Plot Bands</li>
234
                            </ul>
235
                        </td>
236
                    </tr>
237
                    <tr>
238
                        <td colspan="2">
239
                            <ul>
240
                                <li><input name="barPadding" value="2" type="checkbox" checked />Gap between bars</li>
241
                                <!-- value for showContour is speed at which to fade lines in/out -->
242
                                <li><input name="showContour" value="500" type="checkbox" />Comparison Line</li>
243
                            </ul>
244
                        </td>
245
                    </tr>
246
                </table>
247
            </div>
248
 
249
            <div class="stats-cell column">
250
                <table class="stats-table">
251
                <colgroup>
252
                    <col class="label">
253
                    <col class="value">
254
                </colgroup>
255
                <tbody>
256
                    <tr>
257
                        <td class="ui-corner-tl">Mean Age:</td>
258
                        <td class="quintile-value summary-meanAge ui-corner-tr"></td>
259
                    </tr>
260
                    <tr>
261
                        <td>Sex Ratio:</td>
262
                        <td class="quintile-value summary-sexRatio"></td>
263
                    </tr>
264
                    <tr>
265
                        <td>Age Dependency Ratio:</td>
266
                        <td class="quintile-value summary-ageDependencyRatio"></td>
267
                    </tr>
268
                    <tr>
269
                        <td>Population, Total:</td>
270
                        <td class="quintile-value summary-populationTotal"></td>
271
                    </tr>
272
                    <tr>
273
                        <td>Population, Male:</td>
274
                        <td class="quintile-value summary-populationMale"></td>
275
                    </tr>
276
                    <tr>
277
                        <td class="ui-corner-bl">Population, Female:</td>
278
                        <td class="quintile-value summary-populationFemale ui-corner-br"></td>
279
                    </tr>
280
                </tbody>
281
                </table>
282
                <table class="highlighted-stats-table">
283
                <colgroup>
284
                    <col class="label">
285
                    <col class="value">
286
                </colgroup>
287
                <tbody>
288
                    <tr class="tooltip-header">
289
                        <td class="tooltip-header ui-corner-top" colspan="2">Highlighted Age: <span class="tooltip-item tooltipAge">&nbsp;</span></td>
290
                    </tr>
291
                    <tr>
292
                        <td>Population, Male: </td>
293
                        <td class="quintile-value"><span class="tooltip-item tooltipMale">&nbsp;</span></td>
294
                    </tr>
295
                    <tr>
296
                        <td>Population, Female: </td>
297
                        <td class="quintile-value"><span class="tooltip-item tooltipFemale">&nbsp;</span></td>
298
                    </tr>
299
                    <tr>
300
                        <td class="ui-corner-bl">Sex Ratio: </td>
301
                        <td class="quintile-value ui-corner-br"><span class="tooltip-item tooltipRatio">&nbsp;</span></td>
302
                    </tr>
303
                <tbody>
304
                </table>
305
            </div>
306
 
307
            </div>
308
 
309
        </div>
310
    </div>
311
 
312
 
313
 
314
    <script class="code" type="text/javascript">
315
    $(document).ready(function(){
316
 
317
        // if browser supports canvas, show additional toolbar icons
318
        if (!$.jqplot.use_excanvas) {
319
            $('div.quintile-toolbar').append('<div class="ui-icon ui-icon-image"></div><div class="ui-icon ui-icon-print"></div>');
320
        }
321
 
322
        // for this demo, all data is same for each quintile.
323
        // could do something like this to get the index of the quintile.
324
        // <!-- var quintileIndex = parseInt(< ? php echo $_GET["qidx"]; ? >); -->
325
 
326
        var male;
327
        var female;
328
        var summaryTable;
329
        var sexRatios;
330
        var jsondata = [[1043353182,539695335,503657847,28.24,27.51,29.01,51.78],
331
          [0.0085318435343400800,0.0088774027062416400,0.0094714560875224100,0.0101640893891056000,0.0108249758696292000,0.0113773174183149000,0.0117954271696904000,0.0120868766491156000,0.0122726357410028000,0.0123620512208843000,0.0124092312631522000,0.0123929933989534000,0.0123170841477326000,0.0121788940682660000,0.0119848553256476000,0.0117367932349178000,0.0114334768233470000,0.0110840887113746000,0.0107005336950161000,0.0102889073661635000,0.0098746874267631800,0.0094727992165526500,0.0091066817836288100,0.0087853078056091400,0.0085176451289595700,0.0082955898249666400,0.0081021034227657000,0.0079410857437656400,0.0078129432771183200,0.0077041517746791700,0.0076076629996558600,0.0075063773837400400,0.0074212932416191700,0.0073577960797626100,0.0073199937766648000,0.0072872222696609900,0.0072249036551971000,0.0071436496521446000,0.0070535868312601700,0.0069442503777637000,0.0068032069975035000,0.0066093294501292200,0.0063936409488174700,0.0061768176372133200,0.0059737878831400300,0.0057724507581444500,0.0055456647375558400,0.0053139201135624000,0.0050952395722700100,0.0048873227886988200,0.0046839194356973000,0.0044709211871979300,0.0042683374557587400,0.0040886232834079100,0.0039394433696905200,0.0038097165950705600,0.0036797119436340500,0.0035595490798891500,0.0034559622921317600,0.0033586853733251200,0.0032515219944251700,0.0031141174480235800,0.0029601056879342400,0.0027997057390388600,0.0026388958299152400,0.0024706340765107900,0.0022829305753990900,0.0020900571013307600,0.0019037152224417700,0.0017251049256371200,0.0015499961243315000,0.0013709889555399900,0.0011982773790103000,0.0010401790931594200,0.0009015220565900700,0.0007812832602556460,0.0006749752626942340,0.0005833580512023270,0.0005061657847658260,0.0004399544894590220,0.0003808034210932470,0.0003273788998735520,0.0002794993115460400,0.0002369793671257210,0.0001995479850687680,0.0001668101805315270,0.0001383186716039340,0.0001138075253115040,0.0000929924552954457,0.0000755223736670678,0.0000610047525059652,0.0000490638302928227,0.0000396489252832302,0.0000330891826825378,0.0000281195284929135,0.0001070412478036410],
332
          [0.0071192629623232800,0.0072839317935624000,0.0075693293189514500,0.0079091875498352200,0.0082360857829773300,0.0084979038169712600,0.0086893986451354100,0.0088353986277422900,0.0089633895658643000,0.0090878796761182500,0.0092337667384807200,0.0093792123312149900,0.0095192745279032600,0.0096463104169553400,0.0097588790000607600,0.0098544841215461300,0.0099282199747865200,0.0099763812248601700,0.0099957597226035700,0.0099801585489242500,0.0099375446097938400,0.0098709094654945100,0.0097926096630396900,0.0097014318757340600,0.0095968423362564000,0.0094699215837397400,0.0093120985109391200,0.0091337644254482100,0.0089445678055607600,0.0087423328014590000,0.0085321350430430500,0.0083104164267343500,0.0081040369311665900,0.0079207770770160300,0.0077675098774536000,0.0076284130950824500,0.0074765938644635800,0.0073237591351693500,0.0071772210497332700,0.0070244435483804400,0.0068550745015274400,0.0066526057090785200,0.0064404461001358000,0.0062305720357510500,0.0060342707683446500,0.0058408705961082800,0.0056264339860478000,0.0054065565344313600,0.0051920462742280000,0.0049765895152515200,0.0047558832991186200,0.0045207003388048400,0.0042899070487080500,0.0040745089551306800,0.0038817655555785800,0.0037053224400247200,0.0035332134254902200,0.0033727187145046400,0.0032284905944481100,0.0030937679725170100,0.0029582187048090100,0.0028081834596732200,0.0026513461722362800,0.0024926069125082600,0.0023353006048059200,0.0021744630786167700,0.0020021420693961100,0.0018298895084829500,0.0016671380010344600,0.0015153637133401800,0.0013712248188900700,0.0012284616818527500,0.0010934572254154500,0.0009707133813897040,0.0008622603131043950,0.0007661899219731710,0.0006786114871838230,0.0006005435486257860,0.0005322956370150040,0.0004715229254612440,0.0004158721219136000,0.0003645948643149670,0.0003176904909297340,0.0002751152300590630,0.0002367021156783720,0.0002021700726755280,0.0001712214234345020,0.0001437557719387760,0.0001197138111336940,0.0000989925882290494,0.0000814263200020563,0.0000667991474109870,0.0000549164545704749,0.0000455518367647343,0.0000384480445034309,0.0001437755914949950],
333
          [1.284165231,1.3059697282,1.3408259576,1.3770498469,1.4083776842,1.4346340126,1.4545779876,1.4658887137,1.4671638972,1.457608962,1.4400548643,1.4158684686,1.3864911961,1.3528812542,1.3159697978,1.27622903,1.2340137083,1.1905291022,1.1471037258,1.1047013276,1.0647737249,1.0283340659,0.9964942039,0.9703629438,0.9510519527,0.9386721807,0.932316307,0.9316292996,0.9359838821,0.9443012277,0.9554470086,0.9678781103,0.9812761433,0.9953894103,1.0098153246,1.0236249732,1.035479081,1.0451994053,1.0530930686,1.0593183708,1.0634438538,1.0645809137,1.0637641578,1.0623066923,1.0608111193,1.0589993944,1.0561690641,1.0531914677,1.0515722425,1.052330754,1.0553372965,1.0597522653,1.0661637808,1.0752634417,1.0874733411,1.1017415355,1.1159815378,1.1309096828,1.1470504754,1.1633078085,1.1777943775,1.1882903501,1.1963378464,1.2035708256,1.2108560457,1.2175013424,1.2218302494,1.2239011525,1.223611334,1.2198647763,1.2112533925,1.1958739376,1.1742717733,1.1482333683,1.1203430352,1.0926602484,1.0658097999,1.040887396,1.0189501507,0.9998112064,0.9811922123,0.9621730704,0.9427349027,0.9230154312,0.903354613,0.8841353287,0.8656369091,0.8483181293,0.8323701879,0.8174967062,0.8028084248,0.7870522949,0.7736454722,0.7783827557,0.7836945697,0.7977724963],
334
          [0,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+", ""]];
335
 
336
 
337
        // the "x" values from the data will go into the ticks array.
338
        // ticks should be strings for this case where we have values like "75+"
339
        var ticks = jsondata[4];
340
 
341
        $('td.summary-meanAge').each(function(index) {
342
            $(this).html($.jqplot.sprintf('%5.2f', jsondata[0][3]));
343
        });
344
 
345
        $('td.summary-sexRatio').each(function(index) {
346
            $(this).html($.jqplot.sprintf('%5.2f', jsondata[3][0]));
347
        });
348
 
349
        $('td.summary-ageDependencyRatio').each(function(index) {
350
            $(this).html($.jqplot.sprintf('%5.2f', jsondata[0][6]));
351
        });
352
 
353
        $('td.summary-populationTotal').each(function(index) {
354
            $(this).html($.jqplot.sprintf("%'d", jsondata[0][0]));
355
        });
356
 
357
        $('td.summary-populationMale').each(function(index) {
358
            $(this).html($.jqplot.sprintf("%'d", jsondata[0][1]));
359
        });
360
 
361
        $('td.summary-populationFemale').each(function(index) {
362
            $(this).html($.jqplot.sprintf("%'d", jsondata[0][2]));
363
        });
364
 
365
        // These two variables should be removed outside of the jqplot.com example environment.
366
        $.jqplot._noToImageButton = true;
367
        $.jqplot._noCodeBlock = true;
368
 
369
        // Custom color arrays are set up for each series to get the look that is desired.
370
        // Two color arrays are created for the default and optional color which the user can pick.
371
        var greenColors = ["#526D2C", "#77933C", "#C57225", "#C57225"];
372
        var blueColors = ["#3F7492", "#4F9AB8", "#C57225", "#C57225"];
373
 
374
        // To accomodate changing y axis, need to keep track of plot options.
375
        // changing axes will require recreating the plot, so need to keep
376
        // track of state changes.
377
        var plotOptions = {
378
            // We set up a customized title which acts as labels for the left and right sides of the pyramid.
379
            title: {
380
                text: '<span style="margin-left:25%;">Male</span><span style="margin-left:33%;">Female</span>',
381
                textAlign: 'left'
382
            },
383
            // by default, the series will use the green color scheme.
384
            seriesColors: greenColors,
385
 
386
            grid: {
387
                drawBorder: false,
388
                shadow: false,
389
                background: "#ffffff",
390
                rendererOptions: {
391
                    // plotBands is an option of the pyramidGridRenderer.
392
                    // it will put banding at starting at a specified value
393
                    // along the y axis with an adjustable interval.
394
                    plotBands: {
395
                        show: true,
396
                        interval: 10,
397
                        color: 'rgb(245, 235, 215)'
398
                    }
399
                }
400
            },
401
 
402
            // This makes the effective starting value of the axes 0 instead of 1.
403
            // For display, the y axis will use the ticks we supplied.
404
            defaultAxisStart: 0,
405
            seriesDefaults: {
406
                renderer: $.jqplot.PyramidRenderer,
407
                rendererOptions: {
408
                    barPadding: 1.5,
409
                    offsetBars: true
410
                },
411
                yaxis: "yaxis",
412
                shadow: false
413
            },
414
 
415
            // We have 4 series, the left and right pyramid bars and
416
            // the left and rigt overlay lines.
417
            series: [
418
                // For pyramid plots, the default side is right.
419
                // We want to override here to put first set of bars
420
                // on left.
421
                {
422
                    rendererOptions:{
423
                        side: "left",
424
                        synchronizeHighlight: 1
425
                    }
426
                },
427
                {
428
                    yaxis: "y2axis",
429
                    rendererOptions: {
430
                        synchronizeHighlight: 0
431
                    }
432
                },
433
                {
434
                    rendererOptions: {
435
                        fill: false,
436
                        side: 'left'
437
                    }
438
                },
439
                {
440
                    yaxis: 'y2axis',
441
                    rendererOptions: {
442
                        fill: false
443
                    }
444
                }
445
            ],
446
            axesDefaults: {
447
                tickOptions: {
448
                    showGridline: false
449
                },
450
                pad: 0,
451
                rendererOptions: {
452
                    baselineWidth: 2
453
                }
454
            },
455
 
456
            // Set up all the y axes, since users are allowed to switch between them.
457
            // The only axis that will show is the one that the series are "attached" to.
458
            // We need the appropriate options for the others for when the user switches.
459
            axes: {
460
                xaxis: {
461
                    tickOptions: {
462
                        formatter: $.jqplot.PercentTickFormatter,
463
                        formatString: '%.1f%%'
464
                    }
465
                },
466
                yaxis: {
467
                    label: "Age",
468
                    // Use canvas label renderer to get rotated labels.
469
                    labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
470
                    // include empty tick options, they will be used
471
                    // as users set options with plot controls.
472
                    tickOptions: {},
473
                    showMinorTicks: false,
474
                    tickInterval: 5,
475
                    ticks: ticks,
476
                    rendererOptions: {
477
                        tickSpacingFactor: 15,
478
                        category: false
479
                    }
480
                },
481
                yMidAxis: {
482
                    label: "Age",
483
                    // include empty tick options, they will be used
484
                    // as users set options with plot controls.
485
                    tickOptions: {},
486
                    showMinorTicks: false,
487
                    tickInterval: 5,
488
                    ticks: ticks,
489
                    rendererOptions: {
490
                        tickSpacingFactor: 15,
491
                        category: false
492
                    }
493
                },
494
                y2axis: {
495
                    label: "Age",
496
                    // Use canvas label renderer to get rotated labels.
497
                    labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
498
                    // include empty tick options, they will be used
499
                    // as users set options with plot controls.
500
                    tickOptions: {},
501
                    showMinorTicks: false,
502
                    tickInterval: 5,
503
                    ticks: ticks,
504
                    rendererOptions: {
505
                        tickSpacingFactor: 15,
506
                        category: false
507
                    }
508
                }
509
            }
510
        };
511
 
512
        // resize the chart container to fill the space
513
        $('#agesChart').height($('div.chart-cell').height()*0.96);
514
        $('#agesChart').width($('div.chart-cell').width()*0.97);
515
 
516
        // $('#agesChart').jqplot([jsondata[1], jsondata[2]], plotOptions);
517
        $.jqplot.config.addDomReference = true;
518
        var plot1 = $.jqplot('agesChart', [jsondata[1], jsondata[2]], plotOptions);
519
 
520
        $(window).resize (function(event, ui) {
521
            // pass in resetAxes: true option to get rid of old ticks and axis properties
522
            // which should be recomputed based on new plot size.
523
            $('#agesChart').height($('div.chart-cell').height()*0.96);
524
            $('#agesChart').width($('div.chart-cell').width()*0.97);
525
            plot1.replot( { resetAxes: true } );
526
        });
527
 
528
        // initialize form elements
529
        // set these before attaching event handlers.
530
 
531
        $("input[type=checkbox][name=gridsVertical]").attr("checked", false);
532
        $("input[type=checkbox][name=gridsHorizontal]").attr("checked", false);
533
        $("input[type=checkbox][name=showMinorTicks]").attr("checked", true);
534
        $("input[type=checkbox][name=plotBands]").attr("checked", true);
535
        $("input[type=checkbox][name=showContour]").attr("checked", true);
536
        $("input[type=checkbox][name=barPadding]").attr("checked", true);
537
        $("select[name=axisPosition]").val("both");
538
 
539
        //////
540
        // The followng functions use verbose css selectors to make
541
        // it clear exactly which elements they are binging to/operating on
542
        //////
543
 
544
        $("select[name=axisPosition]").change(function(){
545
            // this refers to the html element we are binding to.
546
            // $(this) is jQuery object on that element.
547
 
548
            var opts = {series:[{}, {}, {}, {}]};
549
 
550
            switch ($(this).val()) {
551
                case "both":
552
                    opts.series[0].yaxis = "yaxis";
553
                    opts.series[1].yaxis = "y2axis";
554
                    opts.series[2].yaxis = "yaxis";
555
                    opts.series[3].yaxis = "y2axis";
556
                    break;
557
                case "left":
558
                    opts.series[0].yaxis = "yaxis";
559
                    opts.series[1].yaxis = "yaxis";
560
                    opts.series[2].yaxis = "yaxis";
561
                    opts.series[3].yaxis = "yaxis";
562
                    break;
563
                case "right":
564
                    opts.series[0].yaxis = "y2axis";
565
                    opts.series[1].yaxis = "y2axis";
566
                    opts.series[2].yaxis = "y2axis";
567
                    opts.series[3].yaxis = "y2axis";
568
                    break;
569
                case "mid":
570
                    opts.series[0].yaxis = "yMidAxis";
571
                    opts.series[1].yaxis = "yMidAxis";
572
                    opts.series[2].yaxis = "yMidAxis";
573
                    opts.series[3].yaxis = "yMidAxis";
574
                    break;
575
                default:
576
                    break;
577
 
578
            }
579
 
580
            plot1.replot(opts);
581
        });
582
 
583
        // bind to the data highlighting event to make custom tooltip:
584
        $(".jqplot-target").each(function(index){
585
            $(this).bind("jqplotDataHighlight", function(evt, seriesIndex, pointIndex, data) {
586
                // Here, assume first series is male poulation and second series is female population.
587
                // Adjust series indices as appropriate.
588
                var plot = $(this).data('jqplot');
589
                var malePopulation = Math.abs(plot.series[0].data[pointIndex][1]) * jsondata[0][1];
590
                var femalePopulation = Math.abs(plot.series[1].data[pointIndex][1]) * jsondata[0][2];
591
                var malePopulation = jsondata[1][pointIndex] * jsondata[0][1];
592
                var femalePopulation = jsondata[2][pointIndex] * jsondata[0][2];
593
                // var ratio = femalePopulation / malePopulation * 100;
594
                var ratio = jsondata[3][pointIndex];
595
 
596
                $('.tooltipMale').stop(true, true).fadeIn(350).html($.jqplot.sprintf("%'d", malePopulation));
597
                $('.tooltipFemale').stop(true, true).fadeIn(350).html($.jqplot.sprintf("%'d", femalePopulation));
598
                $('.tooltipRatio').stop(true, true).fadeIn(350).html($.jqplot.sprintf('%5.2f', ratio));
599
 
600
                // Since we don't know which axis is rendererd and acive with out a little extra work,
601
                // just use the supplied ticks array to get the age label.
602
                $('.tooltipAge').stop(true, true).fadeIn(350).html(ticks[pointIndex]);
603
            });
604
        });
605
 
606
        // bind to the data highlighting event to make custom tooltip:
607
        $(".jqplot-target").each(function() {
608
            $(this).bind("jqplotDataUnhighlight", function(evt, seriesIndex, pointIndex, data) {
609
                // clear out all the tooltips.
610
                $(".tooltip-item").fadeOut(250);
611
            });
612
        });
613
 
614
        $('.ui-icon-print').click(function(){
615
            $(this).parent().next().print();
616
        });
617
 
618
 
619
        $("input[type=checkbox][name=gridsVertical]").change(function(){
620
            // this refers to the html element we are binding to.
621
            // $(this) is jQuery object on that element.
622
            var opts = {axes: {xaxis: {tickOptions: {showGridline: this.checked}}}};
623
            plot1.replot(opts);
624
        });
625
 
626
 
627
        $("input[type=checkbox][name=gridsHorizontal]").change(function(){
628
            // this refers to the html element we are binding to.
629
            // $(this) is jQuery object on that element.
630
            var opts = {
631
                axes: {
632
                    yaxis: {
633
                        tickOptions: {showGridline: this.checked}
634
                    },
635
                    y2axis: {
636
                        tickOptions: {showGridline: this.checked}
637
                    },
638
                    yMidAxis: {
639
                        tickOptions: {showGridline: this.checked}
640
                    }
641
                }
642
            };
643
            plot1.replot(opts);
644
        });
645
 
646
        $("input[type=checkbox][name=plotBands]").change(function(){
647
            // this refers to the html element we are binding to.
648
            // $(this) is jQuery object on that element.
649
            var opts = {grid:{ rendererOptions: {plotBands: { show: this.checked}}}};
650
            plot1.replot(opts);
651
        });
652
 
653
        ////
654
        // To-Do
655
        //
656
        // initialize form elements on reload.
657
        // figure out what overlay line would be.
658
        // have to adjust ticks to do show minor.
659
        // make like kcp_pyramid.php
660
        ////
661
        $("input[type=checkbox][name=showMinorTicks]").change(function(){
662
            // this refers to the html element we are binding to.
663
            // $(this) is jQuery object on that element.
664
            var opts = {
665
                axes: {
666
                    yaxis: {
667
                        showMinorTicks: !this.checked
668
                    },
669
                    y2axis: {
670
                        showMinorTicks: !this.checked
671
                    },
672
                    yMidAxis: {
673
                        showMinorTicks: !this.checked
674
                    }
675
                }
676
            };
677
            plot1.replot(opts);
678
        });
679
 
680
        $("input[type=checkbox][name=barPadding]").change(function(){
681
            // this refers to the html element we are binding to.
682
            // $(this) is jQuery object on that element.
683
            if (this.checked) {
684
                var val = parseFloat($(this).val());
685
                var opts = {
686
                    seriesDefaults: {
687
                        rendererOptions: {
688
                            barPadding: val
689
                        }
690
                    }
691
                };
692
            }
693
            else {
694
                var opts = {
695
                    seriesDefaults: {
696
                        rendererOptions: {
697
                            barPadding: 0
698
                        }
699
                    }
700
                };
701
            }
702
            plot1.replot(opts);
703
        });
704
 
705
 
706
        $('.ui-icon-image').each(function() {
707
            $(this).bind('click', function(evt) {
708
                var chart = $(this).closest('div.quintile-outer-container').find('div.jqplot-target');
709
                var imgelem = chart.jqplotToImageElem();
710
                var div = $('div.overlay-chart-container-content');
711
                div.empty();
712
                div.append(imgelem);
713
                $('div.overlay-shadow').fadeIn(600);
714
                div.parent().fadeIn(1000);
715
                div = null;
716
            });
717
        });
718
 
719
        $('div.overlay-chart-container-header div.ui-icon-closethick').click(function(){
720
            var div = $('div.overlay-chart-container-content');
721
            div.parent().fadeOut(600);
722
            $('div.overlay-shadow').fadeOut(1000);
723
        });
724
 
725
        function applyColors(maleColor, femaleColor, backgroundColor, bandColor) {
726
            var opts = {series:[{}, {}], grid:{rendererOptions:{plotBands:{}}}};
727
            opts.series[0].color = maleColor;
728
            opts.series[1].color = femaleColor;
729
            opts.grid.background = backgroundColor;
730
            opts.grid.rendererOptions.plotBands.color = bandColor;
731
            plot1.replot(opts);
732
        };
733
 
734
        $('#colorMale').colorpicker({
735
            colorFormat: '#HEX',
736
            showOn: 'button',
737
            buttonColorize: true,
738
            buttonImageOnly: true,
739
            parts: 'full',
740
            close: function(ui, color) {
741
                applyColors(color.formatted, plot1.series[1].color, plot1.grid.background, plot1.grid.plotBands.color);
742
            }
743
        });
744
 
745
        $('#colorFemale').colorpicker({
746
            colorFormat: '#HEX',
747
            showOn: 'button',
748
            buttonColorize: true,
749
            buttonImageOnly: true,
750
            parts: 'full',
751
            close: function(ui, color) {
752
                applyColors(plot1.series[0].color, color.formatted, plot1.grid.background, plot1.grid.plotBands.color);
753
            }
754
        });
755
 
756
        $('#colorBackground').colorpicker({
757
            colorFormat: '#HEX',
758
            showOn: 'button',
759
            buttonColorize: true,
760
            buttonImageOnly: true,
761
            parts: 'full',
762
            close: function(ui, color) {
763
                applyColors(plot1.series[0].color, plot1.series[1].color, color.formatted, plot1.grid.plotBands.color);
764
            }
765
        });
766
 
767
        $('#colorPlotBands').colorpicker({
768
            colorFormat: '#HEX',
769
            showOn: 'button',
770
            buttonColorize: true,
771
            buttonImageOnly: true,
772
            parts: 'full',
773
            close: function(ui, color) {
774
                applyColors(plot1.series[0].color, plot1.series[1].color, plot1.grid.background, color.formatted);
775
            }
776
        });
777
 
778
    });
779
    </script>
780
 
781
<!-- End example scripts -->
782
 
783
<!-- Don't touch this! -->
784
 
785
<?php include "commonScripts.html" ?>
786
 
787
<!-- End Don't touch this! -->
788
 
789
<!-- Additional plugins go here -->
790
 
791
    <script class="include" type="text/javascript" src="../plugins/jqplot.categoryAxisRenderer.js"></script>
792
 
793
    <!-- load the pyramidAxis and Grid renderers in production.  pyramidRenderer will try to load via ajax if not present, but that is not optimal and depends on paths being set. -->
794
    <script class="include" type="text/javascript" src="../plugins/jqplot.pyramidAxisRenderer.js"></script>
795
    <script class="include" type="text/javascript" src="../plugins/jqplot.pyramidGridRenderer.js"></script>
796
 
797
    <script class="include" type="text/javascript" src="../plugins/jqplot.pyramidRenderer.js"></script>
798
    <script class="include" type="text/javascript" src="../plugins/jqplot.canvasTextRenderer.js"></script>
799
    <script class="include" type="text/javascript" src="../plugins/jqplot.canvasAxisLabelRenderer.js"></script>
800
    <script class="include" type="text/javascript" src="../plugins/jqplot.json2.js"></script>
801
    <script class="include" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js"></script>
802
    <script class="include" type="text/javascript" src="kcp.print.js"></script>
803
 
804
    <script src="colorpicker/jquery.colorpicker.js"></script>
805
 
806
<!-- End additional plugins -->
807
 
808
<?php include "closer.php"; ?>