Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/export chart #59

Open
wants to merge 11 commits into
base: feature/chart-export
Choose a base branch
from
1 change: 1 addition & 0 deletions control-panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<button id="new-controls">New</button>
<button id="edit-controls">Edit</button>
<button id="saveas-controls">Save As</button>
<button id="savepng-controls">Save as Image</button>
<button id="refresh-controls">Refresh</button>
<button id="help-profile" class="profile-help">Help</button>
</div>
Expand Down
4 changes: 2 additions & 2 deletions js/beer-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ function drawBeerChart(beerToDraw, div){

$("button.save-curr-beer-chart").button({ icons: {primary: "ui-icon-refresh" }, text: false }).click(function(){
var img = document.getElementById('hiddenBeerChartImg');
Dygraph.Export.asPNG(beerChart, img);
window.location.href = img.src.replace('image/png','image/octet-stream');
Dygraph.Export.asPNG(currBeerChart, img);

});

var idx = 0;
Expand Down
8 changes: 8 additions & 0 deletions js/control-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ function applySettings(){
var profileTable;
var profileEdit;
var profileSelect;
var currBeerProfileChart;

function renderProfile(beerProfile) {
"use strict";
Expand All @@ -166,6 +167,7 @@ function renderProfile(beerProfile) {
$("#profileTableName").text(decodeURIComponent(window.profileName));
$("button#edit-controls").show();
$("button#saveas-controls").show();
$("button#savepng-controls").show();
drawProfileChart("profileChartDiv", profileTable );
}

Expand Down Expand Up @@ -323,6 +325,7 @@ function drawProfileChart(divId, profileObj) {
profileObj.toCSV(true, ['date', 'temperature']),
chartConfig
);
currBeerProfileChart = chart;
}

function loadProfile(profile, onProfileLoaded) {
Expand Down Expand Up @@ -586,6 +589,11 @@ $(document).ready(function(){
profileEdit.render( profileTable.toJSON() );
showProfileEditDialog(true, "Save Temperature Profile As", true);
}).hide();

$("button#savepng-controls").button({ icons: {primary: "ui-icon-copy" } }).click(function() {
var img = document.getElementById('hiddenBeerChartImg');
Dygraph.Export.asPNG(currBeerProfileChart, img);
}).hide();

$("button#help-profile").button({ icons: {primary: "ui-icon-help" } }).click(function() {
showProfileHelpDialog();
Expand Down
7 changes: 6 additions & 1 deletion js/dygraph-extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ Dygraph.Export.isSupported = function () {
Dygraph.Export.asPNG = function (dygraph, img, userOptions) {
"use strict";
var canvas = Dygraph.Export.asCanvas(dygraph, userOptions);
img.src = canvas.toDataURL();
//img.src = canvas.toDataURL();
window.open(canvas.toDataURL("image/png"));

//img.download = "chart.png";
//img.href = canvas.toDataURL("image/png").replace(/^data:image\/[^;]/, 'data:application/octet-stream');

};

/**
Expand Down