kcp_pyramid_by_age.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. <?php
  2. $title = "Pyramid Chart By Age";
  3. ?>
  4. <?php include "opener.php"; ?>
  5. <!-- Example scripts go here -->
  6. <link class="include" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/themes/smoothness/jquery-ui.css" rel="Stylesheet" />
  7. <link href="colorpicker/jquery.colorpicker.css" rel="stylesheet" type="text/css"/>
  8. <style type="text/css">
  9. .quintile-outer-container {
  10. width: 97%;
  11. height: 97%;
  12. margin: auto;
  13. }
  14. .jqplot-chart {
  15. height: 600px;
  16. }
  17. .quintile-toolbar .ui-icon {
  18. float: right;
  19. margin: 3px 5px;
  20. }
  21. table.stats-table td, table.highlighted-stats-table td {
  22. background-color: rgb(230, 230, 230);
  23. padding: 0.5em;
  24. }
  25. col.label {
  26. width: 14em;
  27. }
  28. col.value {
  29. width: 7em;
  30. }
  31. td.quintile-value {
  32. width: 7em;
  33. text-align: right;
  34. }
  35. table.stats-table td.tooltip-header, table.highlighted-stats-table td.tooltip-header {
  36. background-color: rgb(200, 200, 200);
  37. }
  38. table.stats-table, table.highlighted-stats-table, td.contour-cell {
  39. font-size: 0.7em;
  40. }
  41. td.contour-cell {
  42. height: 1.5em;
  43. padding-left: 20px;
  44. padding-bottom: 1.5em;
  45. }
  46. table.highlighted-stats-table {
  47. margin-top: 15px;
  48. }
  49. div.stats-cell div.input {
  50. font-size: 0.7em;
  51. margin-top: 1.5em;
  52. }
  53. div.content-container {
  54. padding-left: 230px; /* LC width */
  55. padding-right: 300px; /* RC width */
  56. height: 100%;
  57. }
  58. div.content-container .column {
  59. position: relative;
  60. float: left;
  61. }
  62. div.controls {
  63. width: 170px; /* LC width */
  64. right: 230px; /* LC width */
  65. padding-left: 30px;
  66. padding-right: 30px;
  67. margin-left: -100%;
  68. margin-top: 30px;
  69. }
  70. div.chart-cell {
  71. width: 100%;
  72. height: 100%;
  73. }
  74. div.stats-cell {
  75. width: 270px; /* RC width */
  76. margin-right: -300px; /* RC width */
  77. padding-right: 30px;
  78. margin-top: 30px;
  79. }
  80. div.controls, div.controls select {
  81. font-size: 0.8em;
  82. }
  83. div.controls li {
  84. list-style-type: none;
  85. }
  86. div.controls ul {
  87. margin-top: 0.5em;
  88. padding-left: 0.2em;
  89. }
  90. div.overlay-chart-container {
  91. display: none;
  92. z-index: 11;
  93. position: fixed;
  94. width: 800px;
  95. left: 50%;
  96. margin-left: -400px;
  97. background-color: white;
  98. }
  99. div.overlay-chart-container div.ui-icon {
  100. float: right;
  101. margin: 3px 5px;
  102. }
  103. div.overlay-shadow {
  104. display: none;
  105. z-index: 10;
  106. background-color: rgba(0, 0, 0, 0.8);
  107. position: fixed;
  108. top: 0px;
  109. left: 0px;
  110. width: 100%;
  111. height: 100%;
  112. }
  113. div.ui-colorpicker div.ui-dialog-titlebar {
  114. padding: 0.1em 0.3em;
  115. }
  116. input.color {
  117. display: none;
  118. }
  119. div.colorpicker-container span {
  120. padding: 3px;
  121. }
  122. div.quintile-content {
  123. width: 100%;
  124. height: 100%;
  125. }
  126. @media print {
  127. div.stats-cell {
  128. vertical-align: top;
  129. padding-top: 35px;
  130. }
  131. table.stats-table, table.stats-table td {
  132. color: #aaaaaa;
  133. border: 1px solid #bbbbbb;
  134. border-collapse: collapse;
  135. }
  136. table.stats-table tr {
  137. font-family: Verdana,Arial,sans-serif;
  138. /*font-size: 0.7em;*/
  139. }
  140. }
  141. </style>
  142. <div class="overlay-shadow"></div>
  143. <div class="overlay-chart-container ui-corner-all">
  144. <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>
  145. <div class="overlay-chart-container-content ui-corner-bottom"></div>
  146. </div>
  147. <div class="quintile-outer-container ui-widget ui-corner-all">
  148. <div class="quintile-toolbar ui-widget-header ui-corner-top">
  149. <span class="quintile-title">Income Level:</span>
  150. </div>
  151. <div class="quintile-content ui-widget-content ui-corner-bottom">
  152. <div class="content-container">
  153. <div class="chart-cell column">
  154. <div id="agesChart" class="jqplot-chart"></div>
  155. </div>
  156. <div class="controls column">
  157. <table>
  158. <tr>
  159. <td>
  160. Axes:
  161. </td>
  162. <td>
  163. <select name="axisPosition">
  164. <option value="both">Left &amp; Right</option>
  165. <option value = "left">Left</option>
  166. <option value = "right">Right</option>
  167. <option value = "mid">Mid</option>
  168. </select>
  169. </td>
  170. </tr>
  171. <tr>
  172. <td>
  173. Colors:
  174. </td>
  175. <td>
  176. <ul>
  177. <li><input class="color" type="color" id="colorMale" value="#526D2C" /> Male</li>
  178. <li><input class="color" type="color" id="colorFemale" value="#77933C" /> Female</li>
  179. <li><input class="color" type="color" id="colorBackground" value="#ffffff" /> Background</li>
  180. <li><input class="color" type="color" id="colorPlotBands" value="f5ebd7" /> Plot Bands</li>
  181. </ul>
  182. </td>
  183. </tr>
  184. <tr>
  185. <td>
  186. Grids:
  187. </td>
  188. <td>
  189. <ul>
  190. <li><input name="gridsVertical" value="vertical" type="checkbox" />Vertical</li>
  191. <li><input name="gridsHorizontal" value="horizontal" type="checkbox" />Horizontal</li>
  192. <li><input name="showMinorTicks" value="true" type="checkbox" checked />Only major</li>
  193. <li><input name="plotBands" value="true" type="checkbox" checked />Plot Bands</li>
  194. </ul>
  195. </td>
  196. </tr>
  197. <tr>
  198. <td colspan="2">
  199. <ul>
  200. <li><input name="barPadding" value="2" type="checkbox" checked />Gap between bars</li>
  201. <!-- value for showContour is speed at which to fade lines in/out -->
  202. <li><input name="showContour" value="500" type="checkbox" />Comparison Line</li>
  203. </ul>
  204. </td>
  205. </tr>
  206. </table>
  207. </div>
  208. <div class="stats-cell column">
  209. <table class="stats-table">
  210. <colgroup>
  211. <col class="label">
  212. <col class="value">
  213. </colgroup>
  214. <tbody>
  215. <tr>
  216. <td class="ui-corner-tl">Mean Age:</td>
  217. <td class="quintile-value summary-meanAge ui-corner-tr"></td>
  218. </tr>
  219. <tr>
  220. <td>Sex Ratio:</td>
  221. <td class="quintile-value summary-sexRatio"></td>
  222. </tr>
  223. <tr>
  224. <td>Age Dependency Ratio:</td>
  225. <td class="quintile-value summary-ageDependencyRatio"></td>
  226. </tr>
  227. <tr>
  228. <td>Population, Total:</td>
  229. <td class="quintile-value summary-populationTotal"></td>
  230. </tr>
  231. <tr>
  232. <td>Population, Male:</td>
  233. <td class="quintile-value summary-populationMale"></td>
  234. </tr>
  235. <tr>
  236. <td class="ui-corner-bl">Population, Female:</td>
  237. <td class="quintile-value summary-populationFemale ui-corner-br"></td>
  238. </tr>
  239. </tbody>
  240. </table>
  241. <table class="highlighted-stats-table">
  242. <colgroup>
  243. <col class="label">
  244. <col class="value">
  245. </colgroup>
  246. <tbody>
  247. <tr class="tooltip-header">
  248. <td class="tooltip-header ui-corner-top" colspan="2">Highlighted Age: <span class="tooltip-item tooltipAge">&nbsp;</span></td>
  249. </tr>
  250. <tr>
  251. <td>Population, Male: </td>
  252. <td class="quintile-value"><span class="tooltip-item tooltipMale">&nbsp;</span></td>
  253. </tr>
  254. <tr>
  255. <td>Population, Female: </td>
  256. <td class="quintile-value"><span class="tooltip-item tooltipFemale">&nbsp;</span></td>
  257. </tr>
  258. <tr>
  259. <td class="ui-corner-bl">Sex Ratio: </td>
  260. <td class="quintile-value ui-corner-br"><span class="tooltip-item tooltipRatio">&nbsp;</span></td>
  261. </tr>
  262. <tbody>
  263. </table>
  264. </div>
  265. </div>
  266. </div>
  267. </div>
  268. <script class="code" type="text/javascript">
  269. $(document).ready(function(){
  270. // if browser supports canvas, show additional toolbar icons
  271. if (!$.jqplot.use_excanvas) {
  272. $('div.quintile-toolbar').append('<div class="ui-icon ui-icon-image"></div><div class="ui-icon ui-icon-print"></div>');
  273. }
  274. // for this demo, all data is same for each quintile.
  275. // could do something like this to get the index of the quintile.
  276. // <!-- var quintileIndex = parseInt(< ? php echo $_GET["qidx"]; ? >); -->
  277. var male;
  278. var female;
  279. var summaryTable;
  280. var sexRatios;
  281. var jsondata = [[1043353182,539695335,503657847,28.24,27.51,29.01,51.78],
  282. [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],
  283. [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],
  284. [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],
  285. [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+", ""]];
  286. // the "x" values from the data will go into the ticks array.
  287. // ticks should be strings for this case where we have values like "75+"
  288. var ticks = jsondata[4];
  289. $('td.summary-meanAge').each(function(index) {
  290. $(this).html($.jqplot.sprintf('%5.2f', jsondata[0][3]));
  291. });
  292. $('td.summary-sexRatio').each(function(index) {
  293. $(this).html($.jqplot.sprintf('%5.2f', jsondata[3][0]));
  294. });
  295. $('td.summary-ageDependencyRatio').each(function(index) {
  296. $(this).html($.jqplot.sprintf('%5.2f', jsondata[0][6]));
  297. });
  298. $('td.summary-populationTotal').each(function(index) {
  299. $(this).html($.jqplot.sprintf("%'d", jsondata[0][0]));
  300. });
  301. $('td.summary-populationMale').each(function(index) {
  302. $(this).html($.jqplot.sprintf("%'d", jsondata[0][1]));
  303. });
  304. $('td.summary-populationFemale').each(function(index) {
  305. $(this).html($.jqplot.sprintf("%'d", jsondata[0][2]));
  306. });
  307. // These two variables should be removed outside of the jqplot.com example environment.
  308. $.jqplot._noToImageButton = true;
  309. $.jqplot._noCodeBlock = true;
  310. // Custom color arrays are set up for each series to get the look that is desired.
  311. // Two color arrays are created for the default and optional color which the user can pick.
  312. var greenColors = ["#526D2C", "#77933C", "#C57225", "#C57225"];
  313. var blueColors = ["#3F7492", "#4F9AB8", "#C57225", "#C57225"];
  314. // To accomodate changing y axis, need to keep track of plot options.
  315. // changing axes will require recreating the plot, so need to keep
  316. // track of state changes.
  317. var plotOptions = {
  318. // We set up a customized title which acts as labels for the left and right sides of the pyramid.
  319. title: {
  320. text: '<span style="margin-left:25%;">Male</span><span style="margin-left:33%;">Female</span>',
  321. textAlign: 'left'
  322. },
  323. // by default, the series will use the green color scheme.
  324. seriesColors: greenColors,
  325. grid: {
  326. drawBorder: false,
  327. shadow: false,
  328. background: "#ffffff",
  329. rendererOptions: {
  330. // plotBands is an option of the pyramidGridRenderer.
  331. // it will put banding at starting at a specified value
  332. // along the y axis with an adjustable interval.
  333. plotBands: {
  334. show: true,
  335. interval: 10,
  336. color: 'rgb(245, 235, 215)'
  337. }
  338. }
  339. },
  340. // This makes the effective starting value of the axes 0 instead of 1.
  341. // For display, the y axis will use the ticks we supplied.
  342. defaultAxisStart: 0,
  343. seriesDefaults: {
  344. renderer: $.jqplot.PyramidRenderer,
  345. rendererOptions: {
  346. barPadding: 1.5,
  347. offsetBars: true
  348. },
  349. yaxis: "yaxis",
  350. shadow: false
  351. },
  352. // We have 4 series, the left and right pyramid bars and
  353. // the left and rigt overlay lines.
  354. series: [
  355. // For pyramid plots, the default side is right.
  356. // We want to override here to put first set of bars
  357. // on left.
  358. {
  359. rendererOptions:{
  360. side: "left",
  361. synchronizeHighlight: 1
  362. }
  363. },
  364. {
  365. yaxis: "y2axis",
  366. rendererOptions: {
  367. synchronizeHighlight: 0
  368. }
  369. },
  370. {
  371. rendererOptions: {
  372. fill: false,
  373. side: 'left'
  374. }
  375. },
  376. {
  377. yaxis: 'y2axis',
  378. rendererOptions: {
  379. fill: false
  380. }
  381. }
  382. ],
  383. axesDefaults: {
  384. tickOptions: {
  385. showGridline: false
  386. },
  387. pad: 0,
  388. rendererOptions: {
  389. baselineWidth: 2
  390. }
  391. },
  392. // Set up all the y axes, since users are allowed to switch between them.
  393. // The only axis that will show is the one that the series are "attached" to.
  394. // We need the appropriate options for the others for when the user switches.
  395. axes: {
  396. xaxis: {
  397. tickOptions: {
  398. formatter: $.jqplot.PercentTickFormatter,
  399. formatString: '%.1f%%'
  400. }
  401. },
  402. yaxis: {
  403. label: "Age",
  404. // Use canvas label renderer to get rotated labels.
  405. labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
  406. // include empty tick options, they will be used
  407. // as users set options with plot controls.
  408. tickOptions: {},
  409. showMinorTicks: false,
  410. tickInterval: 5,
  411. ticks: ticks,
  412. rendererOptions: {
  413. tickSpacingFactor: 15,
  414. category: false
  415. }
  416. },
  417. yMidAxis: {
  418. label: "Age",
  419. // include empty tick options, they will be used
  420. // as users set options with plot controls.
  421. tickOptions: {},
  422. showMinorTicks: false,
  423. tickInterval: 5,
  424. ticks: ticks,
  425. rendererOptions: {
  426. tickSpacingFactor: 15,
  427. category: false
  428. }
  429. },
  430. y2axis: {
  431. label: "Age",
  432. // Use canvas label renderer to get rotated labels.
  433. labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
  434. // include empty tick options, they will be used
  435. // as users set options with plot controls.
  436. tickOptions: {},
  437. showMinorTicks: false,
  438. tickInterval: 5,
  439. ticks: ticks,
  440. rendererOptions: {
  441. tickSpacingFactor: 15,
  442. category: false
  443. }
  444. }
  445. }
  446. };
  447. // resize the chart container to fill the space
  448. $('#agesChart').height($('div.chart-cell').height()*0.96);
  449. $('#agesChart').width($('div.chart-cell').width()*0.97);
  450. // $('#agesChart').jqplot([jsondata[1], jsondata[2]], plotOptions);
  451. $.jqplot.config.addDomReference = true;
  452. var plot1 = $.jqplot('agesChart', [jsondata[1], jsondata[2]], plotOptions);
  453. $(window).resize (function(event, ui) {
  454. // pass in resetAxes: true option to get rid of old ticks and axis properties
  455. // which should be recomputed based on new plot size.
  456. $('#agesChart').height($('div.chart-cell').height()*0.96);
  457. $('#agesChart').width($('div.chart-cell').width()*0.97);
  458. plot1.replot( { resetAxes: true } );
  459. });
  460. // initialize form elements
  461. // set these before attaching event handlers.
  462. $("input[type=checkbox][name=gridsVertical]").attr("checked", false);
  463. $("input[type=checkbox][name=gridsHorizontal]").attr("checked", false);
  464. $("input[type=checkbox][name=showMinorTicks]").attr("checked", true);
  465. $("input[type=checkbox][name=plotBands]").attr("checked", true);
  466. $("input[type=checkbox][name=showContour]").attr("checked", true);
  467. $("input[type=checkbox][name=barPadding]").attr("checked", true);
  468. $("select[name=axisPosition]").val("both");
  469. //////
  470. // The followng functions use verbose css selectors to make
  471. // it clear exactly which elements they are binging to/operating on
  472. //////
  473. $("select[name=axisPosition]").change(function(){
  474. // this refers to the html element we are binding to.
  475. // $(this) is jQuery object on that element.
  476. var opts = {series:[{}, {}, {}, {}]};
  477. switch ($(this).val()) {
  478. case "both":
  479. opts.series[0].yaxis = "yaxis";
  480. opts.series[1].yaxis = "y2axis";
  481. opts.series[2].yaxis = "yaxis";
  482. opts.series[3].yaxis = "y2axis";
  483. break;
  484. case "left":
  485. opts.series[0].yaxis = "yaxis";
  486. opts.series[1].yaxis = "yaxis";
  487. opts.series[2].yaxis = "yaxis";
  488. opts.series[3].yaxis = "yaxis";
  489. break;
  490. case "right":
  491. opts.series[0].yaxis = "y2axis";
  492. opts.series[1].yaxis = "y2axis";
  493. opts.series[2].yaxis = "y2axis";
  494. opts.series[3].yaxis = "y2axis";
  495. break;
  496. case "mid":
  497. opts.series[0].yaxis = "yMidAxis";
  498. opts.series[1].yaxis = "yMidAxis";
  499. opts.series[2].yaxis = "yMidAxis";
  500. opts.series[3].yaxis = "yMidAxis";
  501. break;
  502. default:
  503. break;
  504. }
  505. plot1.replot(opts);
  506. });
  507. // bind to the data highlighting event to make custom tooltip:
  508. $(".jqplot-target").each(function(index){
  509. $(this).bind("jqplotDataHighlight", function(evt, seriesIndex, pointIndex, data) {
  510. // Here, assume first series is male poulation and second series is female population.
  511. // Adjust series indices as appropriate.
  512. var plot = $(this).data('jqplot');
  513. var malePopulation = Math.abs(plot.series[0].data[pointIndex][1]) * jsondata[0][1];
  514. var femalePopulation = Math.abs(plot.series[1].data[pointIndex][1]) * jsondata[0][2];
  515. var malePopulation = jsondata[1][pointIndex] * jsondata[0][1];
  516. var femalePopulation = jsondata[2][pointIndex] * jsondata[0][2];
  517. // var ratio = femalePopulation / malePopulation * 100;
  518. var ratio = jsondata[3][pointIndex];
  519. $('.tooltipMale').stop(true, true).fadeIn(350).html($.jqplot.sprintf("%'d", malePopulation));
  520. $('.tooltipFemale').stop(true, true).fadeIn(350).html($.jqplot.sprintf("%'d", femalePopulation));
  521. $('.tooltipRatio').stop(true, true).fadeIn(350).html($.jqplot.sprintf('%5.2f', ratio));
  522. // Since we don't know which axis is rendererd and acive with out a little extra work,
  523. // just use the supplied ticks array to get the age label.
  524. $('.tooltipAge').stop(true, true).fadeIn(350).html(ticks[pointIndex]);
  525. });
  526. });
  527. // bind to the data highlighting event to make custom tooltip:
  528. $(".jqplot-target").each(function() {
  529. $(this).bind("jqplotDataUnhighlight", function(evt, seriesIndex, pointIndex, data) {
  530. // clear out all the tooltips.
  531. $(".tooltip-item").fadeOut(250);
  532. });
  533. });
  534. $('.ui-icon-print').click(function(){
  535. $(this).parent().next().print();
  536. });
  537. $("input[type=checkbox][name=gridsVertical]").change(function(){
  538. // this refers to the html element we are binding to.
  539. // $(this) is jQuery object on that element.
  540. var opts = {axes: {xaxis: {tickOptions: {showGridline: this.checked}}}};
  541. plot1.replot(opts);
  542. });
  543. $("input[type=checkbox][name=gridsHorizontal]").change(function(){
  544. // this refers to the html element we are binding to.
  545. // $(this) is jQuery object on that element.
  546. var opts = {
  547. axes: {
  548. yaxis: {
  549. tickOptions: {showGridline: this.checked}
  550. },
  551. y2axis: {
  552. tickOptions: {showGridline: this.checked}
  553. },
  554. yMidAxis: {
  555. tickOptions: {showGridline: this.checked}
  556. }
  557. }
  558. };
  559. plot1.replot(opts);
  560. });
  561. $("input[type=checkbox][name=plotBands]").change(function(){
  562. // this refers to the html element we are binding to.
  563. // $(this) is jQuery object on that element.
  564. var opts = {grid:{ rendererOptions: {plotBands: { show: this.checked}}}};
  565. plot1.replot(opts);
  566. });
  567. ////
  568. // To-Do
  569. //
  570. // initialize form elements on reload.
  571. // figure out what overlay line would be.
  572. // have to adjust ticks to do show minor.
  573. // make like kcp_pyramid.php
  574. ////
  575. $("input[type=checkbox][name=showMinorTicks]").change(function(){
  576. // this refers to the html element we are binding to.
  577. // $(this) is jQuery object on that element.
  578. var opts = {
  579. axes: {
  580. yaxis: {
  581. showMinorTicks: !this.checked
  582. },
  583. y2axis: {
  584. showMinorTicks: !this.checked
  585. },
  586. yMidAxis: {
  587. showMinorTicks: !this.checked
  588. }
  589. }
  590. };
  591. plot1.replot(opts);
  592. });
  593. $("input[type=checkbox][name=barPadding]").change(function(){
  594. // this refers to the html element we are binding to.
  595. // $(this) is jQuery object on that element.
  596. if (this.checked) {
  597. var val = parseFloat($(this).val());
  598. var opts = {
  599. seriesDefaults: {
  600. rendererOptions: {
  601. barPadding: val
  602. }
  603. }
  604. };
  605. }
  606. else {
  607. var opts = {
  608. seriesDefaults: {
  609. rendererOptions: {
  610. barPadding: 0
  611. }
  612. }
  613. };
  614. }
  615. plot1.replot(opts);
  616. });
  617. $('.ui-icon-image').each(function() {
  618. $(this).bind('click', function(evt) {
  619. var chart = $(this).closest('div.quintile-outer-container').find('div.jqplot-target');
  620. var imgelem = chart.jqplotToImageElem();
  621. var div = $('div.overlay-chart-container-content');
  622. div.empty();
  623. div.append(imgelem);
  624. $('div.overlay-shadow').fadeIn(600);
  625. div.parent().fadeIn(1000);
  626. div = null;
  627. });
  628. });
  629. $('div.overlay-chart-container-header div.ui-icon-closethick').click(function(){
  630. var div = $('div.overlay-chart-container-content');
  631. div.parent().fadeOut(600);
  632. $('div.overlay-shadow').fadeOut(1000);
  633. });
  634. function applyColors(maleColor, femaleColor, backgroundColor, bandColor) {
  635. var opts = {series:[{}, {}], grid:{rendererOptions:{plotBands:{}}}};
  636. opts.series[0].color = maleColor;
  637. opts.series[1].color = femaleColor;
  638. opts.grid.background = backgroundColor;
  639. opts.grid.rendererOptions.plotBands.color = bandColor;
  640. plot1.replot(opts);
  641. };
  642. $('#colorMale').colorpicker({
  643. colorFormat: '#HEX',
  644. showOn: 'button',
  645. buttonColorize: true,
  646. buttonImageOnly: true,
  647. parts: 'full',
  648. close: function(ui, color) {
  649. applyColors(color.formatted, plot1.series[1].color, plot1.grid.background, plot1.grid.plotBands.color);
  650. }
  651. });
  652. $('#colorFemale').colorpicker({
  653. colorFormat: '#HEX',
  654. showOn: 'button',
  655. buttonColorize: true,
  656. buttonImageOnly: true,
  657. parts: 'full',
  658. close: function(ui, color) {
  659. applyColors(plot1.series[0].color, color.formatted, plot1.grid.background, plot1.grid.plotBands.color);
  660. }
  661. });
  662. $('#colorBackground').colorpicker({
  663. colorFormat: '#HEX',
  664. showOn: 'button',
  665. buttonColorize: true,
  666. buttonImageOnly: true,
  667. parts: 'full',
  668. close: function(ui, color) {
  669. applyColors(plot1.series[0].color, plot1.series[1].color, color.formatted, plot1.grid.plotBands.color);
  670. }
  671. });
  672. $('#colorPlotBands').colorpicker({
  673. colorFormat: '#HEX',
  674. showOn: 'button',
  675. buttonColorize: true,
  676. buttonImageOnly: true,
  677. parts: 'full',
  678. close: function(ui, color) {
  679. applyColors(plot1.series[0].color, plot1.series[1].color, plot1.grid.background, color.formatted);
  680. }
  681. });
  682. });
  683. </script>
  684. <!-- End example scripts -->
  685. <!-- Don't touch this! -->
  686. <?php include "commonScripts.html" ?>
  687. <!-- End Don't touch this! -->
  688. <!-- Additional plugins go here -->
  689. <script class="include" type="text/javascript" src="../plugins/jqplot.categoryAxisRenderer.js"></script>
  690. <!-- 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. -->
  691. <script class="include" type="text/javascript" src="../plugins/jqplot.pyramidAxisRenderer.js"></script>
  692. <script class="include" type="text/javascript" src="../plugins/jqplot.pyramidGridRenderer.js"></script>
  693. <script class="include" type="text/javascript" src="../plugins/jqplot.pyramidRenderer.js"></script>
  694. <script class="include" type="text/javascript" src="../plugins/jqplot.canvasTextRenderer.js"></script>
  695. <script class="include" type="text/javascript" src="../plugins/jqplot.canvasAxisLabelRenderer.js"></script>
  696. <script class="include" type="text/javascript" src="../plugins/jqplot.json2.js"></script>
  697. <script class="include" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js"></script>
  698. <script class="include" type="text/javascript" src="kcp.print.js"></script>
  699. <script src="colorpicker/jquery.colorpicker.js"></script>
  700. <!-- End additional plugins -->
  701. <?php include "closer.php"; ?>