Commits

Anonymous committed a64f4a1

Minor fixes to image export. Rework to pass in options object rather than just x and y offsets.

Comments (0)

Files changed (3)

examples/customHighlighterCursorTrendline.html

   <script language="javascript" type="text/javascript" src="../src/plugins/jqplot.trendline.js"></script>
   <!-- END: load jqplot -->
 
+
+  
+  <script class="code" type="text/javascript">
+
+    $(document).ready(function () {
+
+      $.jqplot.config.enablePlugins = true;
+
+      s1 = [['23-May-08',1],['24-May-08',4],['25-May-08',2],['26-May-08', 6]];
+
+      plot1 = $.jqplot('test',[s1],{
+         title: 'Highlighting, Dragging, Cursor and Trend Line',
+         axes: {
+             xaxis: {
+                 renderer: $.jqplot.DateAxisRenderer,
+                 tickOptions: {
+                     formatString: '%#m/%#d/%y'
+                 },
+                 numberTicks: 4
+             },
+             yaxis: {
+                 tickOptions: {
+                     formatString: '$%.2f'
+                 }
+             }
+         },
+         highlighter: {
+             sizeAdjust: 10,
+             tooltipLocation: 'n',
+             tooltipAxes: 'y',
+             tooltipFormatString: '<b><i><span style="color:red;">hello</span></i></b> %.2f',
+             useAxesFormatters: false
+         },
+         cursor: {
+             show: true
+         }
+      });
+    });
+</script>
+
+<script type="text/javascript" src="example.js"></script>
+
   </head>
   <body>
 <?php include "nav.inc"; ?>
 <div id="test" class="plot" style="width:500px;height:300px;"></div>
-<script language="javascript" type="text/javascript"><!--
-
-    $.jqplot.config.enablePlugins = true;
-    
-   s1 = [['23-May-08',1],['24-May-08',4],['25-May-08',2],['26-May-08',
-6]];
-
-
-   plot1 = $.jqplot('test',[s1],{
-       title: 'Highlighting, Dragging, Cursor and Trend Line',
-       axes: {
-           xaxis: {
-               renderer: $.jqplot.DateAxisRenderer,
-               tickOptions: {
-                   formatString: '%b %#d, %Y'
-               },
-               numberTicks: 4
-           },
-           yaxis: {
-               tickOptions: {
-                   formatString: '$%.2f'
-               }
-           }
-       },
-       highlighter: {
-           sizeAdjust: 10,
-           tooltipLocation: 'n',
-           tooltipAxes: 'y',
-           tooltipFormatString: '<b><i><span style="color:red;">hello</span></i></b> %.2f',
-           useAxesFormatters: false
-       },
-       cursor: {
-           show: true
-       }
-   });
---></script>
 
   </body>
 </html>

examples/exportImage.html

   
   <link rel="stylesheet" type="text/css" href="../src/jquery.jqplot.css" />
   <link rel="stylesheet" type="text/css" href="../examples/examples.css" />
+  <!--[if lt IE 9]>
+    <script type="text/javascript" src="../src/excanvas.js"></script>
+  <![endif]-->
   
   <!-- BEGIN: load jquery -->
   <script language="javascript" type="text/javascript" src="../src/jquery.js"></script>
        }
      } 
     });
-
-    $('#imgdiv').hide();
 });
 
-function makeImage() {
-  var imgelem = $('#chart1').jqplotToImageElem();
-  $('#imgdiv').append(imgelem);
-  $('#imgdiv').show();
-}
-
 </script>
 
 
 <?php include "nav.inc"; ?>
         
     <div id="chart1" style="margin-top:20px; margin-left:20px; width:300px; height:200px;"></div>
-    <button onclick="makeImage();">Make Image</button>
-    <div id="imgdiv"></div>
         
     <div id="chart2" style="margin-top:20px; margin-left:20px; width:300px; height:200px;"></div>
 
+<script type="text/javascript">
+$(document).ready(function(){
+
+    if (!$.jqplot.use_excanvas) {
+        $('div.jqplot-target').each(function(){
+            // Add a view image button
+            var btn = $(document.createElement('button'));
+            btn.text('View as PNG');
+            btn.bind('click', {chart: $(this)}, function(evt) {
+            evt.data.chart.jqplotViewImage();
+            });
+            $(this).after(btn);
+
+            // add a save image button
+            btn = $(document.createElement('button'));
+            btn.text('Save as PNG');
+            btn.bind('click', {chart: $(this)}, function(evt) {
+            evt.data.chart.jqplotSaveImage();
+            });
+            $(this).after(btn);
+            btn = null;
+        });
+    }
+});
+</script>
 
   </body>
 </html>

src/jqplot.toImage.js

     // Not gauranteed to work, even on canvas supporting browsers due to 
     // limitations with location.href and browser support.
     $.fn.jqplotSaveImage = function() {
-        var imgData = $(this).jqplotToImageStr(options);
+        var imgData = $(this).jqplotToImageStr({});
         if (imgData) {
             window.location.href = imgData.replace("image/png", "image/octet-stream");
         }
     // Not gauranteed to work, even on canvas supporting browsers due to
     // limitations with window.open and arbitrary data.
     $.fn.jqplotViewImage = function() {
-        var imgData = $(this).jqplotToImageStr(0,0);
+        var imgData = $(this).jqplotToImageStr({});
         if (imgData) {
             window.open(imgData);
         }