function loadBinaryFloatArray(url, convertFunction, variable_name, onLoaded) { var mRequest = new XMLHttpRequest(); mRequest.open('GET', url); mRequest.responseType = 'arraybuffer'; mRequest.onreadystatechange = function () { if (this.readyState === 4) { // Get bytes var buffer = this.response; var dataview = new DataView(buffer); // Create buffer (4 bytes / float) var mFloatArray = new Float64Array(buffer.byteLength / 8); // Copy floats for (var i = 0; i < mFloatArray.length; i++) { mFloatArray[i] = dataview.getFloat64(i * 8,true); // At every 8th byte } onLoaded(convertFunction(Array.prototype.slice.call(mFloatArray)),variable_name) } }; mRequest.send(); } function ArrayTo3Array(arr) { return arr.reduce(function (rows, key, index) { return (index % 3 == 0 ? rows.push([key]) : rows[rows.length-1].push(key)) && rows; }, []); } function ArrayTo4Array(arr) { return arr.reduce(function (rows, key, index) { return (index % 4 == 0 ? rows.push([key]) : rows[rows.length-1].push(key)) && rows; }, []); } function ParseCsv(url, variable_name,onLoaded) { var mRequest = new XMLHttpRequest(); mRequest.open('GET', url); mRequest.responseType = 'text'; mRequest.onreadystatechange = function () { if (this.readyState === 4) { var txtArray = mRequest.responseText.split(/\r|\n/); outArray=[] for (var i=0;i0){ outArray.push(txtArray[i].split(',')) } } onLoaded(outArray,variable_name) } } mRequest.send() } function binosearch(data, jd) { let start=0, end=data.length-1; // Iterate while start not meets end while (start<=end){ // Find the mid index let mid=Math.floor((start + end)/2); // If element is present at mid, return True if (data[mid][0] 0) { startDay = binosearch(data, jd) } else { startDay = 0 } var len=Math.min(samples, data.length-startDay) var xd=new Array(len) var yd=new Array(len) for (i=startDay;i"+caption+"", font:{color:"#FF", size:13}, arrowcolor:"#CCC", xanchor: "center", yanchor: "middle" } } var basePlots=[] var onLoadedFunc var numLoaded=0 function loadPlots(onLoaded) { onLoadedFunc=onLoaded loadBinaryFloatArray('/data/Mercury_3D.dat',ArrayTo4Array,'SunToMercury',TestLoadPlot) loadBinaryFloatArray('/data/Venus_3D.dat',ArrayTo4Array,'SunToVenus',TestLoadPlot) loadBinaryFloatArray('/data/Earth_3D.dat',ArrayTo4Array,'SunToEarth',TestLoadPlot) loadBinaryFloatArray('/data/Mars_3D.dat',ArrayTo4Array,'SunToMars',TestLoadPlot) loadBinaryFloatArray('/data/Roadster_3D.dat',ArrayTo4Array,'SunToRoadster',TestLoadPlot) loadBinaryFloatArray('/data/Ceres_3D.dat',ArrayTo4Array,'SunToCeres',TestLoadPlot) } function TestLoadPlot(data,name) { window[name]=data if (PlotsAreReady()) { onLoadedFunc() } } function PlotsAreReady() { return exists(typeof(SunToMercury)) && exists(typeof(SunToVenus)) && exists(typeof(SunToEarth)) && exists(typeof(SunToMars)) && exists(typeof(SunToRoadster)) && exists(typeof(SunToCeres)) } function exists(v) { return v != 'undefined' } function getBasePlots() { var mercuryPlot=plotOrbit(SunToMercury,90,"Mercury",'#7a8278',2) var venusPlot=plotOrbit(SunToVenus,256,"Venus",'#c67f37',2) var earthPlot=plotOrbit(SunToEarth,366,"Earth",'#226de5',2) var marsPlot=plotOrbit(SunToMars,688,"Mars",'#d6492c',2) var roadsterPlot=plotOrbit(SunToRoadster,570,"Roadster",'#2c7c1d',4) var ceresPlot=plotOrbit(SunToCeres,1681,"Ceres",'#d9e0d7',2) return [mercuryPlot,venusPlot,earthPlot,marsPlot,roadsterPlot,ceresPlot] } function getDefaultPlots() { if (basePlots.length==0) { basePlots=getBasePlots() } return basePlots } //TODO: Figure out a much better system for this! function GetLocationImagesFromIndex(index) { var Mercury=CreateImageAtIndexPoint(SunToMercury,index,"/icon/Mercury.png","Mercury",[40,0],[.15,.15],0) var Venus=CreateImageAtIndexPoint(SunToVenus,index,"/icon/Venus.png","Venus",[-40,0],[.2,.2],0) var Earth=CreateImageAtIndexPoint(SunToEarth,index,"/icon/Earth.png","Earth",[30,0],[.2,.2],0) var Mars=CreateImageAtIndexPoint(SunToMars,index,"/icon/Mars.png","Mars",[-30,0],[.2,.2],0) var Roadster=CreateImageAtIndexPoint(SunToRoadster,index,"/icon/Tesla.png","Roadster",[0,-30],[.15,.15],0) var Ceres=CreateImageAtIndexPoint(SunToCeres,index,"/icon/Ceres.png","Ceres",[0,-30],[.15,.15],0) var Sun=CreateImage(0,0,"/icon/Sun.png","",[0,0],[.4,.4]) return [Mercury, Venus, Earth,Mars,Roadster,Ceres,Sun] } function GetLocationImages(jd) { var Mercury=estLocationPlot(SunToMercury,jd,"/icon/Mercury.png","Mercury",[40,0],[.15,.15]) var Venus=estLocationPlot(SunToVenus,jd,"/icon/Venus.png","Venus",[-40,0],[.2,.2]) var Earth=estLocationPlot(SunToEarth,jd,"/icon/Earth.png","Earth",[30,0],[.2,.2]) var Mars=estLocationPlot(SunToMars,jd,"/icon/Mars.png","Mars",[-30,0],[.2,.2]) var Roadster=estLocationPlot(SunToRoadster,jd,"/icon/Tesla.png","Roadster",[0,-30],[.15,.15]) var Ceres=estLocationPlot(SunToCeres,jd,"/icon/Ceres.png","Ceres",[0,-30],[.15,.15]) var Sun=CreateImage(0,0,"/icon/Sun.png","",[0,0],[.4,.4]) return [Mercury, Venus, Earth,Mars,Roadster,Ceres,Sun] } function PlotStartDate() { if (PlotsAreReady()){ return SunToRoadster[0][0]; } return 0 } function PlotEndDate() { if (PlotsAreReady()){ return SunToRoadster[SunToRoadster.length-1][0]; } return 0 } function getDefaultPlotLayout() { var size = { width: window.innerWidth || document.body.clientWidth, height: window.innerHeight || document.body.clientHeight } var tempWidth=(size.width<600)?size.width:((size.width-10)*0.75) var width=Math.min(tempWidth-30,size.height*.75) return { width:width, height:width, title:"Solar System", autosize:false, hovermode:false, font:{color:"#F5F5F5"}, plot_bgcolor:"black", paper_bgcolor:"#FFF3", opacity:0, xaxis: { range: [-2, 2], zeroline:false, fixedrange: true, showticklabels: false, autorange: false, title:'', showgrid:false }, yaxis: { scaleanchor: "x", showticklabels: false, zeroline:false, range: [-2, 2], scaleRatio:1, fixedrange: true, autorange: false, title:'', showgrid:false }, margin: { l: 30, r: 30, b: 30, t: 30, pad: 4 }, legend: { xref:"paper", yref:"paper", x:0, y:0, bgcolor:'#FFF4', borderwidth:2, font:{color:"#DDD"}, } } } function getUnixFromJulian(jd ) { return (jd- 2440587.5)*86400.0; } function getJulianFromUnix(unixSecs ) { return ( unixSecs / 86400.0 ) + 2440587.5; } // This file is Copyright 2018 Old Ham Media. All rights reserved.