Commit a9fd02b4 authored by Caillat Michel's avatar Caillat Michel
Browse files

Added the function createAndAppendFromHTML

parent d6619aab
......@@ -9,26 +9,26 @@
/*
** A class to convert a right ascension expressed in decimal degree into an integer value expressing a pixel index.
*/
let RADDtoPixelConverter = function(radd0, radd1, rapix0, rapix1) {
console.log("let RADDtoPixelConverter = function(radd0, radd1, rapix0, rapix1) { : entering");
let _radd0 = radd0;
let _rapix0 = rapix0;
let _slope = (rapix1 - rapix0) / (radd1 - radd0);
var RADDtoPixelConverter = function(radd0, radd1, rapix0, rapix1) {
console.log("var RADDtoPixelConverter = function(radd0, radd1, rapix0, rapix1) { : entering");
var _radd0 = radd0;
var _rapix0 = rapix0;
var _slope = (rapix1 - rapix0) / (radd1 - radd0);
console.log("_radd0 = " + _radd0 + ", _rapix0 = " + _rapix0);
this.convert = function(radd) {
return _rapix0 + (radd - _radd0) * _slope;
}
console.log("let RADDtoPixelConverter = function(radd0, radd1, rapix0, rapix1) { : exiting");
console.log("var RADDtoPixelConverter = function(radd0, radd1, rapix0, rapix1) { : exiting");
};
/*
** A class to convert a declination expressed in decimal degree into an integer value expressing a pixel index.
*/
let DECDDtoPixelConverter = function(decdd0, decdd1, decpix0, decpix1) {
let _decdd0 = decdd0;
let _decpix0 = decpix0;
let _slope = (decpix1 - decpix0) / (decdd1 - decdd0);
var DECDDtoPixelConverter = function(decdd0, decdd1, decpix0, decpix1) {
var _decdd0 = decdd0;
var _decpix0 = decpix0;
var _slope = (decpix1 - decpix0) / (decdd1 - decdd0);
this.convert = function(decdd) {
return _decpix0 + (decdd - _decdd0) * _slope;
......@@ -39,7 +39,7 @@ let DECDDtoPixelConverter = function(decdd0, decdd1, decpix0, decpix1) {
** Converts a decimal number expected to represent an angle in degree
** into a string expressing a right ascension ( H:M:S)
*/
let DecDeg2HMS = function(deg,sep=':'){
var DecDeg2HMS = function(deg,sep=':'){
//if(any(deg< 0 | deg>360)){stop('All deg values should be 0<=d<=360')}
//if (deg < 0)
//deg[deg < 0] = deg[deg < 0] + 360
......@@ -54,12 +54,12 @@ let DecDeg2HMS = function(deg,sep=':'){
** Converts a decimal number expected to represent an angle in degree
** into a string expressing a declination ( D:M:S)
*/
let DecDeg2DMS = function(deg,sep=':'){
let sign = deg < 0 ? '-':'+';
var DecDeg2DMS = function(deg,sep=':'){
var sign = deg < 0 ? '-':'+';
deg = Math.abs(deg);
let DEG = Math.floor(deg);
let MIN = Math.floor((deg - DEG) * 60);
let SEC = (deg - DEG - MIN/60) * 3600;
var DEG = Math.floor(deg);
var MIN = Math.floor((deg - DEG) * 60);
var SEC = (deg - DEG - MIN/60) * 3600;
SEC = Math.floor(SEC*1000.) / 1000.;
if (SEC < 0.) SEC = 0.; if (SEC > 60) SEC = 60.;
......@@ -73,18 +73,32 @@ let DecDeg2DMS = function(deg,sep=':'){
** with the given parameter ra0pix, ra1pix ( interval in pixels )
** and ra0, ra1 ( the same interval in decimal degrees)
*/
function raLabelFormatter (ra0pix, ra1pix, ra0, ra1) {
let _ra0pix = ra0pix;
let _ra1pix = ra1pix;
let _ra0 = ra0;
let _ra1 = ra1;
let _slope = ((_ra1 - _ra0) / (_ra1pix - _ra0pix))
class RaLabelFormatter {
static enter(what) {
console.group(this.name + "." + what);
}
static exit() {
console.groupEnd();
}
constructor(ra0pix, ra1pix, ra0, ra1) {
RaLabelFormatter.enter(this.constructor.name);
this.ra0pix = ra0pix;
this.ra1pix = ra1pix;
this.ra0 = ra0;
this.ra1 = ra1;
this.slope = ((this.ra1 - this.ra0) / (this.ra1pix - this.ra0pix));
RaLabelFormatter.exit();
}
/*
** Returns the string representation of a RA in HMS given its input value in pixels.
*/
this.format = function(rapix) {
let res = _ra0 + (rapix - _ra0pix) * _slope;
format(rapix) {
//RaLabelFormatter.enter(this.format.name);
var res = this.ra0 + (rapix - this.ra0pix) * this.slope;
//RaLabelFormatter.exit();
return DecDeg2HMS(res);
}
};
......@@ -96,15 +110,29 @@ function raLabelFormatter (ra0pix, ra1pix, ra0, ra1) {
** with the given parameter dec0pix, dec1pix ( interval in pixels )
** and dec0, dec1 ( the same interval in decimal degrees)
*/
function decLabelFormatter (dec0pix, dec1pix, dec0, dec1) {
let _dec0pix = dec0pix;
let _dec1pix = dec1pix;
let _dec0 = dec0;
let _dec1 = dec1;
let _slope = ((_dec1 - _dec0) / (_dec1pix - _dec0pix))
this.format = function(decpix) {
let res = _dec0 + (decpix - _dec0pix) * _slope;
class DecLabelFormatter {
static enter(what) {
console.group(this.name + "." + what);
}
static exit() {
console.groupEnd();
}
constructor(dec0pix, dec1pix, dec0, dec1) {
DecLabelFormatter.enter(this.constructor.name);
this.dec0pix = dec0pix;
this.dec1pix = dec1pix;
this.dec0 = dec0;
this.dec1 = dec1;
this.slope = ((this.dec1 - this.dec0) / (this.dec1pix - this.dec0pix));
DecLabelFormatter.exit();
}
format(decpix) {
//DecLabelFormatter.enter(this.format.name);
var res = this.dec0 + (decpix - this.dec0pix) * this.slope;
//DecLabelFormatter.exit();
return DecDeg2DMS(res);
}
};
......@@ -217,11 +245,23 @@ function str2FloatArray(s, range=false) {
return result;
}
/*
** A function which creates a document fragment out of an HTML string and appends it to the content of an existing element.
** The HTML string is assumed to describe a single element ( e.g. one signle div, p, etc. ).
** Returns the created element.
*/
function createAndAppendFromHTML(html, element) {
var template = document.createElement('template');
template.innerHTML = html.trim();
$(element).append(template.content.cloneNode(true));
return element.lastChild;
}
/*
** Two functions to log when a function is entered and exited
*/
function ENTER() {
let caller = ENTER.caller;
var caller = ENTER.caller;
if (caller == null) {
result = "_TOP_";
}
......@@ -232,7 +272,7 @@ function ENTER() {
}
function EXIT() {
let caller = EXIT.caller;
var caller = EXIT.caller;
if (caller == null) {
result = "_TOP_";
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment