HTML: Use jqplot to draw profile.

Use jqplot to draw dive profile, Depth and pressure curves. add the
library Javascript files under the theme directory and editing the
exporter. Load them to the HTML template dynamically with
synchronization as they are dependant on each other.
Also Adding min version of JQuery that is needed by the library.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Gehad elrobey 2014-06-26 16:43:57 +03:00 committed by Dirk Hohndel
parent ac46158d65
commit 023187a73e
8 changed files with 287 additions and 25 deletions

View file

@ -98,6 +98,11 @@ void DiveLogExportDialog::exportHtmlInit(const QString &filename)
copy_and_overwrite(searchPath + "dive_export.html", filename); copy_and_overwrite(searchPath + "dive_export.html", filename);
copy_and_overwrite(searchPath + "list_lib.js", exportFiles + "list_lib.js"); copy_and_overwrite(searchPath + "list_lib.js", exportFiles + "list_lib.js");
copy_and_overwrite(searchPath + "poster.png", exportFiles + "poster.png"); copy_and_overwrite(searchPath + "poster.png", exportFiles + "poster.png");
copy_and_overwrite(searchPath + "jqplot.highlighter.min.js", exportFiles + "jqplot.highlighter.min.js");
copy_and_overwrite(searchPath + "jquery.jqplot.min.js", exportFiles + "jquery.jqplot.min.js");
copy_and_overwrite(searchPath + "jqplot.canvasAxisTickRenderer.min.js", exportFiles + "jqplot.canvasAxisTickRenderer.min.js");
copy_and_overwrite(searchPath + "jqplot.canvasTextRenderer.min.js", exportFiles + "jqplot.canvasTextRenderer.min.js");
copy_and_overwrite(searchPath + "jquery.min.js", exportFiles + "jquery.min.js");
copy_and_overwrite(searchPath + (ui->themeSelection->currentText() == "Light" ? "light.css" : "sand.css"), copy_and_overwrite(searchPath + (ui->themeSelection->currentText() == "Light" ? "light.css" : "sand.css"),
exportFiles + "theme.css"); exportFiles + "theme.css");
} }

View file

@ -7,25 +7,37 @@
//advance settings window// //advance settings window//
load_scripts(); load_scripts();
function load_scripts(){ function load_script_sync(name)
{
var fileref=document.createElement('script');
fileref.setAttribute("type","text/javascript");
fileref.async = false;
fileref.setAttribute("src", location.pathname + "_files/" + name);
document.getElementsByTagName("head")[0].appendChild(fileref);
}
function load_scripts()
{
var fileref=document.createElement("link"); var fileref=document.createElement("link");
fileref.setAttribute("rel", "stylesheet"); fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css"); fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", location.pathname+"_files/theme.css"); fileref.setAttribute("href", location.pathname + "_files/theme.css");
document.getElementsByTagName("head")[0].appendChild(fileref); document.getElementsByTagName("head")[0].appendChild(fileref);
fileref=document.createElement('script'); fileref=document.createElement('script');
fileref.setAttribute("src", location.pathname+"_files/file.json"); fileref.setAttribute("src", location.pathname + "_files/file.json");
document.getElementsByTagName("head")[0].appendChild(fileref); document.getElementsByTagName("head")[0].appendChild(fileref);
fileref=document.createElement('script'); fileref=document.createElement('script');
fileref.setAttribute("src", location.pathname+"_files/settings.json"); fileref.setAttribute("src", location.pathname + "_files/settings.json");
document.getElementsByTagName("head")[0].appendChild(fileref); document.getElementsByTagName("head")[0].appendChild(fileref);
fileref=document.createElement('script'); load_script_sync("list_lib.js");
fileref.setAttribute("type","text/javascript"); load_script_sync("jquery.min.js");
fileref.setAttribute("src", location.pathname+"_files/list_lib.js"); load_script_sync("jquery.jqplot.min.js");
document.getElementsByTagName("head")[0].appendChild(fileref); load_script_sync("jqplot.highlighter.min.js");
load_script_sync("jqplot.canvasAxisTickRenderer.min.js");
load_script_sync("jqplot.canvasTextRenderer.min.js");
} }
var advanced_shown=false; var advanced_shown=false;
@ -164,8 +176,12 @@ function changeAdvSearch(e){
</div> </div>
</center> </center>
<div id="diveprofile"> <div id="diveprofile">
<center>
<h2 id="dive_no"></h2>
<h3 id="dive_location"></h3>
</center>
<h2 class="det_hed">Dive profile</h2> <h2 class="det_hed">Dive profile</h2>
<canvas id="profileCanvas"></canvas> <div style="width:100%" id="chart1"></div>
</div> </div>
<div id="diveinfo"> <div id="diveinfo">
<h2 class="det_hed">Dive Information</h2> <h2 class="det_hed">Dive Information</h2>
@ -174,7 +190,7 @@ function changeAdvSearch(e){
<h2 class="det_hed">Dive equipments</h2> <h2 class="det_hed">Dive equipments</h2>
</div> </div>
<div id="bookmarks"> <div id="bookmarks">
<h2 class="det_hed">Bookmarks</h2> <h2 class="det_hed">Events</h2>
</div> </div>
<div id="divestats"> <div id="divestats">
<h2 class="det_hed">Dive stats</h2> <h2 class="det_hed">Dive stats</h2>

View file

@ -0,0 +1,57 @@
/**
* jqPlot
* Pure JavaScript plotting plugin using jQuery
*
* Version: 1.0.0r1095
*
* Copyright (c) 2009-2011 Chris Leonello
* jqPlot is currently available for use in all personal or commercial projects
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
* choose the license that best suits your project and use it accordingly.
*
* Although not required, the author would appreciate an email letting him
* know of any substantial use of jqPlot. You can reach the author at:
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
*
* If you are feeling kind and generous, consider supporting the project by
* making a donation at: http://www.jqplot.com/donate.php .
*
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
*
* version 2007.04.27
* author Ash Searle
* http://hexmen.com/blog/2007/03/printf-sprintf/
* http://hexmen.com/js/sprintf.js
* The author (Ash Searle) has placed this code in the public domain:
* "This code is unrestricted: you are free to use it however you like."
*
* included jsDate library by Chris Leonello:
*
* Copyright (c) 2010-2011 Chris Leonello
*
* jsDate is currently available for use in all personal or commercial projects
* under both the MIT and GPL version 2.0 licenses. This means that you can
* choose the license that best suits your project and use it accordingly.
*
* jsDate borrows many concepts and ideas from the Date Instance
* Methods by Ken Snyder along with some parts of Ken's actual code.
*
* Ken's origianl Date Instance Methods and copyright notice:
*
* Ken Snyder (ken d snyder at gmail dot com)
* 2008-09-10
* version 2.0.2 (http://kendsnyder.com/sandbox/date/)
* Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
*
* jqplotToImage function based on Larry Siden's export-jqplot-to-png.js.
* Larry has generously given permission to adapt his code for inclusion
* into jqPlot.
*
* Larry's original code can be found here:
*
* https://github.com/lsiden/export-jqplot-to-png
*
*
*/
(function(a){a.jqplot.CanvasAxisTickRenderer=function(b){this.mark="outside";this.showMark=true;this.showGridline=true;this.isMinorTick=false;this.angle=0;this.markSize=4;this.show=true;this.showLabel=true;this.labelPosition="auto";this.label="";this.value=null;this._styles={};this.formatter=a.jqplot.DefaultTickFormatter;this.formatString="";this.prefix="";this.fontFamily='"Trebuchet MS", Arial, Helvetica, sans-serif';this.fontSize="10pt";this.fontWeight="normal";this.fontStretch=1;this.textColor="#666666";this.enableFontSupport=true;this.pt2px=null;this._elem;this._ctx;this._plotWidth;this._plotHeight;this._plotDimensions={height:null,width:null};a.extend(true,this,b);var c={fontSize:this.fontSize,fontWeight:this.fontWeight,fontStretch:this.fontStretch,fillStyle:this.textColor,angle:this.getAngleRad(),fontFamily:this.fontFamily};if(this.pt2px){c.pt2px=this.pt2px}if(this.enableFontSupport){if(a.jqplot.support_canvas_text()){this._textRenderer=new a.jqplot.CanvasFontRenderer(c)}else{this._textRenderer=new a.jqplot.CanvasTextRenderer(c)}}else{this._textRenderer=new a.jqplot.CanvasTextRenderer(c)}};a.jqplot.CanvasAxisTickRenderer.prototype.init=function(b){a.extend(true,this,b);this._textRenderer.init({fontSize:this.fontSize,fontWeight:this.fontWeight,fontStretch:this.fontStretch,fillStyle:this.textColor,angle:this.getAngleRad(),fontFamily:this.fontFamily})};a.jqplot.CanvasAxisTickRenderer.prototype.getWidth=function(d){if(this._elem){return this._elem.outerWidth(true)}else{var f=this._textRenderer;var c=f.getWidth(d);var e=f.getHeight(d);var b=Math.abs(Math.sin(f.angle)*e)+Math.abs(Math.cos(f.angle)*c);return b}};a.jqplot.CanvasAxisTickRenderer.prototype.getHeight=function(d){if(this._elem){return this._elem.outerHeight(true)}else{var f=this._textRenderer;var c=f.getWidth(d);var e=f.getHeight(d);var b=Math.abs(Math.cos(f.angle)*e)+Math.abs(Math.sin(f.angle)*c);return b}};a.jqplot.CanvasAxisTickRenderer.prototype.getAngleRad=function(){var b=this.angle*Math.PI/180;return b};a.jqplot.CanvasAxisTickRenderer.prototype.setTick=function(b,d,c){this.value=b;if(c){this.isMinorTick=true}return this};a.jqplot.CanvasAxisTickRenderer.prototype.draw=function(c,f){if(!this.label){this.label=this.prefix+this.formatter(this.formatString,this.value)}if(this._elem){if(a.jqplot.use_excanvas&&window.G_vmlCanvasManager.uninitElement!==undefined){window.G_vmlCanvasManager.uninitElement(this._elem.get(0))}this._elem.emptyForce();this._elem=null}var e=f.canvasManager.getCanvas();this._textRenderer.setText(this.label,c);var b=this.getWidth(c);var d=this.getHeight(c);e.width=b;e.height=d;e.style.width=b;e.style.height=d;e.style.textAlign="left";e.style.position="absolute";e=f.canvasManager.initCanvas(e);this._elem=a(e);this._elem.css(this._styles);this._elem.addClass("jqplot-"+this.axis+"-tick");e=null;return this._elem};a.jqplot.CanvasAxisTickRenderer.prototype.pack=function(){this._textRenderer.draw(this._elem.get(0).getContext("2d"),this.label)}})(jQuery);

57
theme/jqplot.canvasTextRenderer.min.js vendored Normal file

File diff suppressed because one or more lines are too long

57
theme/jqplot.highlighter.min.js vendored Normal file

File diff suppressed because one or more lines are too long

BIN
theme/jquery.jqplot.min.js vendored Normal file

Binary file not shown.

BIN
theme/jquery.min.js vendored Normal file

Binary file not shown.

View file

@ -869,25 +869,87 @@ function get_dive_HTML(dive)
'</td></tr></table><div style="margin:10px;"><p class="words">Notes: </p>' + dive.notes + '</div>'; '</td></tr></table><div style="margin:10px;"><p class="words">Notes: </p>' + dive.notes + '</div>';
}; };
var ZERO_C_IN_MKELVIN = 273150;
function mkelvin_to_C(mkelvin)
{
return (mkelvin - ZERO_C_IN_MKELVIN) / 1000.0;
}
function mbar_to_bar(mbar){
return mbar/1000;
}
function mm_to_meter(mm){
return mm/(1000);
}
var plot1;
/** /**
*Main canvas draw function *Main canvas draw function
*this calls the axis and grid initialization functions. *this calls the axis and grid initialization functions.
*/ */
function canvas_draw() function canvas_draw(){
{ document.getElementById("chart1").innerHTML="";
var c = document.getElementById("profileCanvas"); var d1 = new Array();
c.width = window.innerWidth; var d2 = new Array();
c.height = window.innerHeight; for (var i =0; i< items[dive_id].samples.length;i++){
canvas_showGrid(); d1.push([items[dive_id].samples[i][0]/60,-1*mm_to_meter(items[dive_id].samples[i][1])]);
canvas_showAxisInfo(); if (items[dive_id].samples[i][2]!=0) {
var ctx = c.getContext("2d"); d2.push([items[dive_id].samples[i][0]/60,mbar_to_bar(items[dive_id].samples[i][2])]);
ctx.lineWidth = 4 //variable width }
//draw starting line, draw all samples then draw the final line.
canvas_drawline(ctx, [0,0], points[0]);
for (var i = 1; i < points.length; i++) {
canvas_drawline(ctx, points[i - 1], points[i]);
} }
canvas_drawline(ctx, points[points.length - 1], [MAX_WIDTH,0]); plot1 = $.jqplot('chart1', [d1,d2], {
grid: {
drawBorder: true,
shadow: false,
background: 'rgba(0,0,0,0)'
},
highlighter: { show: true },
seriesDefaults: {
shadowAlpha: 0.1,
shadowDepth: 2,
fillToZero: true
},
series: [{
color: 'rgba(35,58,58,.6)',
negativeColor: 'rgba(35,58,58,.6)',
showMarker: true,
showLine: true,
fill: true,
yaxis:'yaxis',
},{
color: 'rgba(44, 190, 160, 0.7)',
showMarker: false,
rendererOptions: {
smooth: true,
},
yaxis:'y2axis',
},],
axes: {
xaxis: {
pad: 1.0,
tickRenderer: $.jqplot.CanvasAxisTickRenderer ,
tickOptions: {
showGridline: false,
formatString:'%i min',
angle: -30
}
},
yaxis: {
max: 0,
tickRenderer: $.jqplot.CanvasAxisTickRenderer ,
tickOptions:{ formatString:'%.2f'},
pad: 2.05
},
y2axis: {
tickRenderer: $.jqplot.CanvasAxisTickRenderer ,
tickOptions:{ formatString:'%ibar'},
pad: 3.05
},
}
});
} }
/** /**
@ -906,14 +968,21 @@ function showDiveDetails(dive)
MAX_WIDTH = items[dive_id].duration; MAX_WIDTH = items[dive_id].duration;
//draw the canvas and initialize the view //draw the canvas and initialize the view
canvas_draw();
document.getElementById("diveinfo").innerHTML = get_dive_HTML(items[dive_id]); document.getElementById("diveinfo").innerHTML = get_dive_HTML(items[dive_id]);
document.getElementById("dive_equipments").innerHTML = get_cylinders_HTML(items[dive_id]); document.getElementById("dive_equipments").innerHTML = get_cylinders_HTML(items[dive_id]);
document.getElementById("bookmarks").innerHTML=get_bookmarks_HTML(items[dive_id]); document.getElementById("bookmarks").innerHTML=get_bookmarks_HTML(items[dive_id]);
setDiveTitle(items[dive_id]);
//hide the list of dives and show the canvas. //hide the list of dives and show the canvas.
document.getElementById("diveListPanel").style.display = 'none'; document.getElementById("diveListPanel").style.display = 'none';
document.getElementById("divePanel").style.display = 'block'; document.getElementById("divePanel").style.display = 'block';
canvas_draw();
}
function setDiveTitle(dive){
document.getElementById("dive_no").innerHTML="Dive No. "+(settings.subsurfaceNumbers === '0'?
dive.number : dive.subsurface_number);
document.getElementById("dive_location").innerHTML=dive.location;
} }
/** /**
@ -924,6 +993,7 @@ function unshowDiveDetails(dive)
{ {
start = dive_id; start = dive_id;
viewInPage(); viewInPage();
plot1 = null;
document.getElementById("diveListPanel").style.display = 'block'; document.getElementById("diveListPanel").style.display = 'block';
document.getElementById("divePanel").style.display = 'none'; document.getElementById("divePanel").style.display = 'none';
} }