Commits

Chris Leonello committed 4f5ae1a

Added some comment and expanding example.

Comments (0)

Files changed (2)

examples/kcp_lorenz.php

             <div>
                 Data Series:
                 <ul>
-                    <li><input name="dataSeries" value="national" type="radio" checked />National</li>
-                    <li><input name="dataSeries" value="urban" type="radio" />Urban</li>
-                    <li><input name="dataSeries" value="rural" type="radio" />Rural</li>
+                    <li><input name="dataSeries" value="national" type="checkbox" checked />National</li>
+                    <li><input name="dataSeries" value="urban" type="checkbox" />Urban</li>
+                    <li><input name="dataSeries" value="rural" type="checkbox" />Rural</li>
                 </ul>
             </div>
 
             </div>
 
             <div>
-                Set lines at:
+                Cutoff Lines:
                 <ul>
-                    <li><input name="userLine1" value="42" type="text" size="8" /> and </li>
-                    <li><input name="userLine2" value="75" type="text" size="8" /></li>
+                    <li><input name="cutoffLines" value="showCutoffLines" type="checkbox" checked />Show</li>
+                    <li>Low:&nbsp;&nbsp;<input name="userLine1" value="42" type="text" size="6" /></li>
+                    <li>High:&nbsp;<input name="userLine2" value="75" type="text" size="6" /></li>
                 </ul>
             </div>
         </td>
 
     // make the plot
     
-    plot1 = $.jqplot("chart1", [dataSets.national], {
+    plot1 = $.jqplot("chart1", [dataSets.national, dataSets.urban, dataSets.rural], {
         title: "Lorenz Curve",
         // To control the size of the grid, can set the gridPadding option,
 
         // won't be overwritten.
 
         gridDimensions: {height: 290, width: 290},
+        seriesColors: ["#4bb2c5", "#c54b62", "#b2c54b"],
         cursor: {
             show: false
         },
             labelRenderer: $.jqplot.CanvasAxisLabelRenderer
         },
         seriesDefaults: {
-            showMarker: false,
-            color: "#4bb2c5"
+            showMarker: false
         },
+        series: [
+            {show: true},
+            {show: false},
+            {show: false}
+        ],
         axes: {
             xaxis: {
-                label: 'Per Capita Expenditure (local currency)',
+                label: '% of Population',
                 pad:0
             },
             yaxis: {
-                label: 'Population Share (%)',
+                label: '% of Expenditure',
                 pad: 0
             }
         },
                     name: "line5",
                     start: [0,0],
                     stop: [100,100],
-                    color: "#4bb2c5",
+                    color: "#666666",
                     shadow: false,
-                    showTooltip: false
+                    showTooltip: false,
+                    lineWidth: 3
                 }},
                 {horizontalLine: {
                     name: "line1",
     // initialize form elements
     // set these before attaching event handlers.
 
-    $("input[type=radio][name=dataSeries]").attr("checked", false);
-    $("input[type=radio][name=dataSeries][value=national]").attr("checked", true);
+    $("input[type=checkbox][name=dataSeries]").attr("checked", false);
+    $("input[type=checkbox][name=dataSeries][value=national]").attr("checked", true);
 
     $("input[type=radio][name=backgroundColor]").attr("checked", false);
     $("input[type=radio][name=backgroundColor][value=white]").attr("checked", true);
 
     $("input[type=checkbox][name=gridsVertical]").attr("checked", true);
     $("input[type=checkbox][name=gridsHorizontal]").attr("checked", true);
+    $("input[type=checkbox][name=cutoffLines]").attr("checked", true);
 
 
     // attach event handlers to form elements
         plot1.replot();
     });
 
-    $("input[type=radio][name=dataSeries]").change(function(){ 
-        var val = $(this).val();
-        plot1.series[0].data = dataSets[val];
+    $("input[type=checkbox][name=dataSeries]").change(function(){ 
 
         switch (val) {
             case "national":
         plot1.replot();
     });
 
+    $("input[type=checkbox][name=cutoffLines]").change(function(){
+        var co = plot1.plugins.canvasOverlay;
+        if (this.checked) {
+            co.get('line1').options.show = true;
+            co.get('line2').options.show = true;
+            co.get('line3').options.show = true;
+            co.get('line4').options.show = true;
+        }
+        else {
+            co.get('line1').options.show = false;
+            co.get('line2').options.show = false;
+            co.get('line3').options.show = false;
+            co.get('line4').options.show = false;
+        }
+        plot1.replot();
+    });
+
     $("input[type=text][name=userLine1]").keyup(function(){
         var val = parseFloat($(this).val());
 

src/jqplot.linearTickGenerator.js

 
             else if (keepMin) {
                 r[0] = axis_min                                         // min
-                r[2] = Math.ceil((axis_max - axis_min) / ss + 1.0);    // number of ticks
+                r[2] = Math.ceil((axis_max - axis_min) / ss + 1.0);     // number of ticks
                 r[1] = axis_min + (r[2] - 1) * ss;                      // max
                 var digitsMin = gsf(axis_min).digitsRight;
                 var digitsSS = gsf(ss).digitsRight;
                 if (digitsMin < digitsSS) {
-                    r[3] = bestFormatString(ss);                            // format string
+                    r[3] = bestFormatString(ss);                        // format string
                 }
                 else {
                     r[3] = '%.' + digitsMin + 'f';
             }
 
             else if (keepMax) {
-                r[1] = axis_max;                      // max
+                r[1] = axis_max;                                        // max
                 r[2] = Math.ceil((axis_max - axis_min) / ss + 1.0);     // number of ticks
                 r[0] = axis_max - (r[2] - 1) * ss;                      // min
                 var digitsMax = gsf(axis_max).digitsRight;
                 var digitsSS = gsf(ss).digitsRight;
                 if (digitsMax < digitsSS) {
-                    r[3] = bestFormatString(ss);                            // format string
+                    r[3] = bestFormatString(ss);                        // format string
                 }
                 else {
                     r[3] = '%.' + digitsMax + 'f';
 
                 var newti = bestInterval(tempr[1] - tempr[0], numberTicks);
 
-                r[0] = tempr[0];
-                r[2] = numberTicks;
-                r[4] = newti;
-                r[3] = bestFormatString(newti);
+                r[0] = tempr[0];                        // min
+                r[2] = numberTicks;                     // number of ticks
+                r[4] = newti;                           // tick interval
+                r[3] = bestFormatString(newti);         // format string
                 r[1] = r[0] + (r[2] - 1) * r[4];        // max
             }
         }