Commit f2c414d8 authored by Moreau Nicolas's avatar Moreau Nicolas
Browse files

add reset zoom button

parent 9d8d0181
......@@ -224,6 +224,9 @@
<div id="slice" class="map" style="background-color:darkblue"></div>
</td>
<td>
<button id="zoomout">-</button>
<button id="zoomin">+</button>
<button id="zoomreset">Reset</button>
<div id="spectrum"></div>
</td>
</tr>
......@@ -329,13 +332,13 @@
var ENTER = function () { console.log(arguments.callee.name + ": entering."); };
var EXIT = function () { console.log(arguments.callee.name + ": exiting."); };
<%if(useSAMP){%>
var sAMPPublisher = null;
<%}%>
<%if(useSAMP){%>
var sAMPPublisher = null;
<%}%>
var ROI;
var summedPixelsSpectrumChart;
var spectrumChart
var spectrumChart;
var viewIn3D = function() {
window.open("getYtObj?relFITSFilePath="+relFITSFilePath+"&iRA0="+ROI.iRA0+"&iRA1="+ROI.iRA1+"&iDEC0="+ROI.iDEC0+"&iDEC1="+ROI.iDEC1+"&iFREQ0="+ROI.iFREQ0+"&iFREQ1="+ROI.iFREQ1);
};
......@@ -682,10 +685,10 @@ var SAMPPNGPublishControl = (function (Control) {
coordinateFormat: _coordinateFormatType_2 }),
new ol.control.FullScreen()
];
<%if(useSAMP){%>
let _sAMPPNGPublishControl_1 = new SAMPPNGPublishControl();
_sAMPPNGPublishControl_1.setHandler(sAMPPublisher.sendPNGSlice);
<%}%>
<%if(useSAMP){%>
let _sAMPPNGPublishControl_1 = new SAMPPNGPublishControl();
_sAMPPNGPublishControl_1.setHandler(sAMPPublisher.sendPNGSlice);
<%}%>
_map_1 = new ol.Map({
target: _divSlice,
view: new ol.View({
......@@ -693,12 +696,12 @@ var SAMPPNGPublishControl = (function (Control) {
center: ol.extent.getCenter(_extent),
resolution: hidden_canvas_1.width / 512
})
<%if(useSAMP){%>
,
controls: ol.control.defaults().extend([
_sAMPPNGPublishControl_1
])
<%}%>
<%if(useSAMP){%>
,
controls: ol.control.defaults().extend([
_sAMPPNGPublishControl_1
])
<%}%>
});
_graticule_1 = new ol.Graticule({
......@@ -772,10 +775,10 @@ var SAMPPNGPublishControl = (function (Control) {
new ol.control.FullScreen()
];
<%if(useSAMP){%>
let _sAMPPNGPublishControl_2 = new SAMPPNGPublishControl();
_sAMPPNGPublishControl_2.setHandler(sAMPPublisher.sendPNGSummedSlices);
<%}%>
<%if(useSAMP){%>
let _sAMPPNGPublishControl_2 = new SAMPPNGPublishControl();
_sAMPPNGPublishControl_2.setHandler(sAMPPublisher.sendPNGSummedSlices);
<%}%>
_map_2 = new ol.Map({
target: _divSummedSlices,
......@@ -784,12 +787,12 @@ var SAMPPNGPublishControl = (function (Control) {
center: ol.extent.getCenter(_extent),
resolution: hidden_canvas_2.width / 512
})
<%if(useSAMP){%>
,
controls: ol.control.defaults().extend([
_sAMPPNGPublishControl_2
])
<%}%>
<%if(useSAMP){%>
,
controls: ol.control.defaults().extend([
_sAMPPNGPublishControl_2
])
<%}%>
});
document.getElementById("summedslices").addEventListener("mouseenter", function() {
......@@ -905,9 +908,9 @@ var SAMPPNGPublishControl = (function (Control) {
});
_map_1.addLayer(_im_layer_1);
}
<% if(useSAMP){%>
sAMPPublisher.setSliceRelPNGPath(path_to_png);
<%}%>
<% if(useSAMP){%>
sAMPPublisher.setSliceRelPNGPath(path_to_png);
<%}%>
document.getElementById('loading').style.display="none";
console.log("$.post('/png', {'si': _sliceIndex, 'path': _path}).done(: exiting");
}
......@@ -955,9 +958,9 @@ var SAMPPNGPublishControl = (function (Control) {
_map_2.addLayer(_im_layer_2);
_map_2.addLayer(_box_layer_2);
}
<%if(useSAMP){%>
<%if(useSAMP){%>
sAMPPublisher.setSummedSlicesRelPNGPath(path_to_png);
<%}%>
<%}%>
document.getElementById('loading').style.display="none";
console.log("$.post('/sumpng', {'si0': _sliceIndex0, 'si1': _sliceIndex1, 'relFITSFilePath': relFITSFilePath}).done() : exiting");
});
......@@ -1457,26 +1460,26 @@ var SAMPPNGPublishControl = (function (Control) {
plotData.y = temparr;
}
}
<%if(useSAMP){%>
//Create a FITS file containing the spectrum supposedly to publish it via SAMP.
if(_ctype3 === "FREQ" || _ctype3 === "VRAD"){
$.post("",{"method":"createFits","relFITSFilePath":_relFITSFilePath, "iRA": iRA, "iDEC": iDEC})
.done(
function(resp) {
console.log("A FITS file has been created for the spectrum.");
var x = JSON.parse(resp);
sAMPPublisher.setSpectrumPath(x["result"]);
}
)
.fail(
function(err) {
var msg = "POST failed" + JSON.stringify(err, 0, 4);
console.log(msg);
alert(msg);
}
);
}
<%}%>
<%if(useSAMP){%>
//Create a FITS file containing the spectrum supposedly to publish it via SAMP.
if(_ctype3 === "FREQ" || _ctype3 === "VRAD"){
$.post("",{"method":"createFits","relFITSFilePath":_relFITSFilePath, "iRA": iRA, "iDEC": iDEC})
.done(
function(resp) {
console.log("A FITS file has been created for the spectrum.");
var x = JSON.parse(resp);
sAMPPublisher.setSpectrumPath(x["result"]);
}
)
.fail(
function(err) {
var msg = "POST failed" + JSON.stringify(err, 0, 4);
console.log(msg);
alert(msg);
}
);
}
<%}%>
plotData.xaxis = "x";
......@@ -1565,6 +1568,8 @@ var SAMPPNGPublishControl = (function (Control) {
usePreAllocated: true
},
xAxis: {
gridLineColor: '#000000',
lineColor: '#000000',
title: {
text: xtitle
},
......@@ -1590,14 +1595,17 @@ var SAMPPNGPublishControl = (function (Control) {
}
},
yAxis: {
gridLineColor: '#000000',
lineColor: '#000000',
title: {
text: ytitle
}
}
},
tooltip:{
/*formatter : function(){
return '( ' + this.x.toFixed(4) + ', ' + this.y.toFixed(4); + ')';
}*/
plotOptions: {
series: {
animation: false,
lineWidth : 1
}
},
series: [
{
......@@ -1622,15 +1630,47 @@ var SAMPPNGPublishControl = (function (Control) {
console.log("SpectrumViewer: exiting");
};
$("#zoomin").on('click', function(){
console.log(spectrumChart);
console.log(" min :" + spectrumChart.xAxis[0].min + " max : " + spectrumChart.xAxis[0].max);
let factor = Math.abs((spectrumChart.xAxis[0].min - spectrumChart.xAxis[0].max) * 0.2);
let minVal = spectrumChart.xAxis[0].min + factor;
let maxVal = spectrumChart.xAxis[0].max - factor;
console.log("factor : "+factor);
console.log("min : "+minVal + " , max : "+ maxVal);
spectrumChart.xAxis[0].setExtremes(minVal, maxVal);
});
$("#zoomout").on('click', function(){
let factor = Math.abs((spectrumChart.xAxis[0].min - spectrumChart.xAxis[0].max) * 0.2);
let minVal = spectrumChart.xAxis[0].min - factor;
let maxVal = spectrumChart.xAxis[0].max + factor;
spectrumChart.xAxis[0].setExtremes(minVal, maxVal);
});
$("#zoomreset").on('click', function(){
spectrumChart.xAxis[0].setExtremes(undefined, undefined);
});
function SummedPixelsSpectrumViewer (relFITSFilePath, FITSHeader, itsGD){
console.log("SummedPixelsSpectrumViewer: entering");
var xtitle = "undefined";
var ytitle = "undefined";
let _averageSpectrum = null;
var toptitle = function ( value, unit ) {
return value.toExponential(4) + " (" + unit + ")";
};
}
this.setAverageSpectrum = function(averageSpectrum){
console.log("### setAverageSpectrum");
console.log(averageSpectrum);
_averageSpectrum = averageSpectrum;
}
var toptitle_unit = "";
if (_instrume == "SITELLE") {
......@@ -1687,40 +1727,40 @@ var SAMPPNGPublishControl = (function (Control) {
xaxis: 'x'
};
var plotData2 = JSON.parse(JSON.stringify(_frequencyPlot));
let _companion = null;
//let _companion = null;
/*
** set the companion
*/
this.setCompanion = function(who) {
/*this.setCompanion = function(who) {
_companion = who;
}
}*/
/*
** get the companion
*/
this.getCompanion = function() {
/*this.getCompanion = function() {
return _companion;
}
}*/
/*
** Who triggered the relayout ?
*/
let _relayoutTriggeredBy = null;
//let _relayoutTriggeredBy = null;
/*
** Set who triggered the relayout
*/
this.setRelayoutTriggeredBy = function(who) {
/*this.setRelayoutTriggeredBy = function(who) {
_relayoutTriggeredBy = who;
}
}*/
/*
** Get who triggered the relayout.
*/
this.getRelayoutTriggeredBy = function() {
/*this.getRelayoutTriggeredBy = function() {
return _relayoutTriggeredBy;
}
}*/
//Plotly.newPlot(_itsGD, _frequencyPlot, _layout);
this.plot = function (iRA0, iRA1, iDEC0, iDEC1, zmin, zmax) {
......@@ -1729,18 +1769,18 @@ var SAMPPNGPublishControl = (function (Control) {
title: {
text: ''
},
chart: {
chart: {
zoomType: 'x',
panning: true,
panKey: 'shift',
events:{
selection: function(event){
this.xAxis[0].update({
plotBands : [{ // visualize the weekend
from: event.xAxis[0].min,
to: event.xAxis[0].max,
color: 'rgba(68, 170, 213, .2)'
}]
plotBands : [{
from: event.xAxis[0].min,
to: event.xAxis[0].max,
color: 'rgba(68, 170, 213, .2)'
}]
});
var imin = Math.round((event.xAxis[0].min - plotData2.x[0]) / (plotData2.x[1]-plotData2.x[0]));
......@@ -1771,7 +1811,8 @@ var SAMPPNGPublishControl = (function (Control) {
console.log("This should not happen");
}
}
summedAverageSpectrum = sumArr(averageSpectrum, 0, averageSpectrum.length, cdelt3prim);
this.setTitle({text:toptitle(summedAverageSpectrum/unitRescale(summedPixelsSpectrumUnit(_bunit)), toptitle_unit)});
return false;
}
}
......@@ -1787,12 +1828,22 @@ var SAMPPNGPublishControl = (function (Control) {
},
crosshair : true,
reversed : false,
gridLineColor: '#000000',
lineColor: '#000000'
},
yAxis: {
gridLineColor: '#000000',
lineColor: '#000000',
title: {
text: ytitle
}
},
plotOptions: {
series: {
animation: false,
lineWidth : 1
}
},
tooltip:{
formatter : function(){
return '( ' + this.x.toFixed(4) + ', ' + this.y.toFixed(4); + ')';
......@@ -1803,155 +1854,154 @@ var SAMPPNGPublishControl = (function (Control) {
]
});
document.getElementById('loading').style.display = 'block';
$.post("",{"method":"getAverageSpectrum", "relFITSFilePath":_relFITSFilePath, "iRA0": iRA0, "iRA1": iRA1, "iDEC0": iDEC0, "iDEC1": iDEC1 }).done(function(resp) {
console.log("SummedPixelsSpectrumViewer : callback of getAverageSpectrum: entering ");
document.getElementById('loading').style.display='none';
var x = JSON.parse(resp);
document.getElementById('loading').style.display = 'block';
$.post("",{"method":"getAverageSpectrum", "relFITSFilePath":_relFITSFilePath, "iRA0": iRA0, "iRA1": iRA1, "iDEC0": iDEC0, "iDEC1": iDEC1 }).done(function(resp) {
console.log("SummedPixelsSpectrumViewer : callback of getAverageSpectrum: entering ");
document.getElementById('loading').style.display='none';
var x = JSON.parse(resp);
<%if(useSAMP){%>
// Let's inform the SAMP hub
if ("absFITSFilePath" in x["result"]) {
sAMPPublisher.setAverageSpectrumFile(x["result"]["absFITSFilePath"]);
}
else {
console.log("Strange we should have found a key 'absFITSFilePath'");
}
<%}%>
<%if(useSAMP){%>
// Let's inform the SAMP hub
if ("absFITSFilePath" in x["result"]) {
sAMPPublisher.setAverageSpectrumFile(x["result"]["absFITSFilePath"]);
}
else {
console.log("Strange we should have found a key 'absFITSFilePath'");
}
<%}%>
var averageSpectrum = x["result"]["averageSpectrum"];
averageSpectrum = x["result"]["averageSpectrum"];
var cdelt3prim = 0.;
var summedAverageSpectrum = 0;
var start = zmin ? zmin : 0;
var end = zmax ? zmax : averageSpectrum.length;
//var cdelt3prim = 0.;
var summedAverageSpectrum = 0;
var start = zmin ? zmin : 0;
var end = zmax ? zmax : averageSpectrum.length;
var xIndexes = Array.apply(null, Array(averageSpectrum.length)).map(function(x, i) { return i; });
var xData = new Array(averageSpectrum.length);
var xIndexes = Array.apply(null, Array(averageSpectrum.length)).map(function(x, i) { return i; });
var xData = new Array(averageSpectrum.length);
// Draw x-axis in Velocities (plot on bottom right)
let rlen = averageSpectrum.length;
// Draw x-axis in Velocities (plot on bottom right)
let rlen = averageSpectrum.length;
let coeff = 1;
let coeff = 1;
if ((_origin === "GILDAS Consortium") && (_ctype3 === "VRAD")){
//~ _cunit3 = "M/S";
cdelt3prim = Math.abs(_cdelt3) * unitFactor[getCunit3()] / unitFactor[defaultOutputUnit[_ctype3]];
if ((_origin === "GILDAS Consortium") && (_ctype3 === "VRAD")){
//~ _cunit3 = "M/S";
cdelt3prim = Math.abs(_cdelt3) * unitFactor[getCunit3()] / unitFactor[defaultOutputUnit[_ctype3]];
}
else if (_origin.startsWith("CASA")) {
if (_ctype3 == "FREQ"){
cdelt3prim = speedOfLight /1000. * Math.abs(_cdelt3) / _restfreq;
}
else if (_origin.startsWith("CASA")) {
if (_ctype3 == "FREQ"){
cdelt3prim = speedOfLight /1000. * Math.abs(_cdelt3) / _restfreq;
}
else{
cdelt3prim = Math.abs(_cdelt3) * unitFactor[getCunit3()] / unitFactor[defaultOutputUnit[_ctype3]];
}
else{
cdelt3prim = Math.abs(_cdelt3) * unitFactor[getCunit3()] / unitFactor[defaultOutputUnit[_ctype3]];
}
else if (_instrume == "SITELLE") {
if ( _cdelt1 && _cdelt2 ) {
cdelt3prim = _cdelt3 / Math.abs(_cdelt1 * _cdelt2 * 3600.0 * 3600.0);
}
else {
cdelt3prim = _cdelt3;
}
}
else if (_instrume == "SITELLE") {
if ( _cdelt1 && _cdelt2 ) {
cdelt3prim = _cdelt3 / Math.abs(_cdelt1 * _cdelt2 * 3600.0 * 3600.0);
}
else if (_instrume == "MUSE") {
cdelt3prim = 1;
else {
cdelt3prim = _cdelt3;
}
}
else if (_instrume == "MUSE") {
cdelt3prim = 1;
}
for (var i = 0; i < rlen; i++) {
let tmp = linearTabulator(_crval3, _cdelt3, _crpix3, i+1);
if (getCunit3() in unitFactor) {
switch (_ctype3) {
for (var i = 0; i < rlen; i++) {
let tmp = linearTabulator(_crval3, _cdelt3, _crpix3, i+1);
if (getCunit3() in unitFactor) {
switch (_ctype3) {
case 'FREQ':
let tmp1 = f2v(tmp * unitFactor[getCunit3()], _restfreq) / unitFactor[defaultOutputUnit['VRAD']];
if (_cdelt3 > 0) {
xData[rlen-i-1] = tmp1;
}
else {
xData[i] = tmp1;
}
break;
case 'FREQ':
let tmp1 = f2v(tmp * unitFactor[getCunit3()], _restfreq) / unitFactor[defaultOutputUnit['VRAD']];
if (_cdelt3 > 0) {
xData[rlen-i-1] = tmp1;
}
else {
xData[i] = tmp1;
}
break;
case 'VRAD' :
if (_cdelt3 > 0) {
xData[i] = tmp * unitFactor[getCunit3()] / unitFactor[defaultOutputUnit[_ctype3]];
}
else {
xData[rlen-i-1] = tmp * unitFactor[getCunit3()] / unitFactor[defaultOutputUnit[_ctype3]];
}
break;
case 'VRAD' :
if (_cdelt3 > 0) {
xData[i] = tmp * unitFactor[getCunit3()] / unitFactor[defaultOutputUnit[_ctype3]];
}
else {
xData[rlen-i-1] = tmp * unitFactor[getCunit3()] / unitFactor[defaultOutputUnit[_ctype3]];
}
break;
case 'WAVE':
case 'WAVN':
case 'AWAV' :
if ( _cdelt3 > 0 ) {
xData[i] = tmp;
}
else {
xData[rlen-i-1] = tmp;
}
break;
case 'WAVE':
case 'WAVN':
case 'AWAV' :
if ( _cdelt3 > 0 ) {
xData[i] = tmp;
}
else {
xData[rlen-i-1] = tmp;
}
break;
default:
console.log("This should not happen");
}
default:
console.log("This should not happen");
}
}
plotData2.x = xData;
switch (_ctype3) {
case 'FREQ' :
if (_cdelt3 > 0) {
plotData2.y = revertArray(averageSpectrum);
}
else {
plotData2.y = averageSpectrum;
}
break;
}
plotData2.x = xData;
case 'VRAD':
case 'WAVE':
case 'WAVN':
case 'AWAV':
averageSpectrum = averageSpectrum.map(function(x) {return x* unitRescale(summedPixelsSpectrumUnit(_bunit))});
switch (_ctype3) {
case 'FREQ' :
if (_cdelt3 > 0) {
plotData2.y = averageSpectrum;
plotData2.y = revertArray(averageSpectrum);
}
else {
plotData2.y = revertArray(averageSpectrum);
plotData2.y = averageSpectrum;
}
break;
default:
console.log("This should not happen");
break;
case 'VRAD':
case 'WAVE':
case 'WAVN':
case 'AWAV':
averageSpectrum = averageSpectrum.map(function(x) {return x* unitRescale(summedPixelsSpectrumUnit(_bunit))});
if (_cdelt3 > 0) {
plotData2.y = averageSpectrum;
}
let highChartData = [];
for(let i=0; i< plotData2.x.length; i++){
highChartData.push([plotData2.x[i], plotData2.y[i]]);
else {
plotData2.y = revertArray(averageSpectrum);
}
summedAverageSpectrum = sumArr(averageSpectrum, start, end, cdelt3prim);
summedPixelsSpectrumChart.setTitle({text:toptitle(summedAverageSpectrum/unitRescale(summedPixelsSpectrumUnit(_bunit)), toptitle_unit)});
summedPixelsSpectrumChart.series[0].update({
name : '',
// unlimited number of points when zooming
cropThreshold: Infinity,
showInLegend: false,
marker: {
radius : 1
},
data: highChartData,
}
);
var data = [];
var justRelayedout = false;
break;
default:
console.log("This should not happen");
break;
}
let highChartData = [];