(function (){ var a = {"cwl_A":5400,"pixelWavelengthPairs":[{"px":0,"lambda_A":3050},{"px":8549,"lambda_A":11600}],"putMarkerToCwl":false,"lambda-precision":2,"extremeWavelengths_A":[3450,11200]}; var timeoutLen = 200; var t = document.getElementById("main_spectrum"); t.setAttribute("data-mapping", JSON.stringify(a)); if (!t.getAttribute("src")){ console.log("image has no meaningful source declared"); timeoutLen *= 3; t.src = "?imgproxy="+encodeURIComponent(a.cubeLocation + "/" + a.averageFilename); } if (a["lambda-precision"]){ t.setAttribute("data-lambda-precision", a["lambda-precision"]); } setTimeout(function (){ a.cwl_px = OnImage_wavelengthAToPixel(t, a.cwl_A); if (typeof a.putMarkerToCwl === "undefined"){ a.putMarkerToCwl = true; }else{ a.putMarkerToCwl = a.putMarkerToCwl ? true : false; } t.setAttribute("last-click-on-real-pixel", a.cwl_px); t.setAttribute("last-click-on-real-wavelength", a.cwl_A); if (a.extremeWavelengths_A){ a.extremeWavelengths_A_source = "source-json"; var ex = []; ex.push(OnImage_wavelengthAToPixel(t, a.extremeWavelengths_A[0])); ex.push(OnImage_wavelengthAToPixel(t, a.extremeWavelengths_A[1])); ex = ex.map(function (e){ return Math.round(e - a.cwl_px); }).join(","); t.setAttribute("data-extreme-pixel-shifts", ex); }else{ // it may have come from the image a.extremeWavelengths_A_source = "cube-enumeration"; var ex = t.getAttribute("data-extreme-pixel-shifts", ex).split(","); ex = ex.map(function (e){ e = parseFloat(e); return Math.round(OnImage_pixelToWavelength_A(t, a.cwl_px+e)); }); a.extremeWavelengths_A = ex; } t.setAttribute("data-mapping", JSON.stringify(a)); t.addEventListener("mousemove", SpectrumMouseMoveListener); t.addEventListener("mouseleave", SpectrumMouseLeaveListener); t.addEventListener("click", SpectrumMouseClickListener); OnImage_getFirstParentWithTagname(t, "a").addEventListener("keydown", SpectrumKeydownListener); if (a.putMarkerToCwl){ console.log("put marker to CWL has been requested"); OnImage_setMarkerToWavelength(t, a.cwl_A); } if (a.putMarkerToPixelOffset){ console.log("put marker to PIXEL_OFFSET has been requested"); OnImage_setMarkerToWavelength(t, OnImage_pixelToWavelength_A(t, a.putMarkerToPixelOffset)); } if (a.putMarkerToWavelength){ console.log("put marker to WAVELENGTH has been requested"); OnImage_setMarkerToWavelength(t, a.putMarkerToWavelength); } if (a.putCursorToWavelength){ console.log("put cursor to WAVELENGTH has been requested"); setTimeout(function (){ OnImage_placeClickOntoRealWavelength(t, a.putCursorToWavelength); }, 100); } var cwl_shower = OnImage_getFirstParentWithTagname(t, "table").getElementsByClassName("cwl_angstrom")[0]; cwl_shower.innerHTML = a.cwl_A; [/* marked-wavelengths-a */].forEach(function (lambda_A){ OnImage_setMarkerToWavelength(t, lambda_A, WavelengthToColor(lambda_A)); }); if (a.markersRelativeToCwl){ a.markersRelativeToCwl = a.markersRelativeToCwl.map(function (m){ var weKnowThePixelShift = false; var weKnowTheWavelengthShift = false; if (parseFloat(m.shift_A) === parseFloat(m.shift_A)){ weKnowTheWavelengthShift = true; } if (parseFloat(m.shift_px) === parseFloat(m.shift_px)){ weKnowThePixelShift = true; } if ((weKnowThePixelShift)&&(!weKnowTheWavelengthShift)){ m.shift_A = OnImage_pixelToWavelength_A(t, m.shift_px); } if ((!weKnowThePixelShift)&&(weKnowTheWavelengthShift)){ m.shift_px = OnImage_wavelengthAToPixel(t, m.shift_A); console.log(m); } return m; }); a.markersRelativeToCwl.forEach(function (e){ var lambda_A = a.cwl_A + e.shift_A; OnImage_setMarkerToWavelength(t, lambda_A, WavelengthToColor(lambda_A)); }); } if (a.markers){ a.markers = a.markers.map(function (m){ var weKnowThePixel = false; var weKnowTheWavelength = false; if (parseFloat(m.lambda_A) === parseFloat(m.lambda_A)){ weKnowTheWavelength = true; } if (parseFloat(m.px) === parseFloat(m.px)){ weKnowThePixel = true; } if ((weKnowThePixel)&&(!weKnowTheWavelength)){ m.lambda_A = OnImage_pixelToWavelength_A(t, m.px); } if ((!weKnowThePixel)&&(weKnowTheWavelength)){ m.px = OnImage_wavelengthAToPixel(t, m.lambda_A); console.log(m); } return m; }); a.markers.forEach(function (e){ var lambda_A = e.lambda_A; OnImage_setMarkerToWavelength(t, lambda_A, WavelengthToColor(lambda_A)); }); } OnImage_getTheLambdaEditor(t).addEventListener("keyup", function (e){ if (e.key === "Enter" || e.keyCode === 13) { SpectrumLambdaEditorEnterListener(t); }; }); OnImage_getThePixelShiftEditor(t).addEventListener("keyup", function (e){ if (e.key === "Enter" || e.keyCode === 13) { SpectrumPixelShiftEditorEnterListener(t); }; }); OnImage_enqueueAddExtremeBlurs(t, a); }, timeoutLen); })();