Skip to content

Commit

Permalink
Use react 19
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshingles committed Dec 7, 2024
1 parent 0801d62 commit baa4a47
Show file tree
Hide file tree
Showing 10 changed files with 398 additions and 316 deletions.
31 changes: 18 additions & 13 deletions atlasserver/forcephot/templates/tasklist-react.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,25 @@
$(document).ready(inactivityTimer);
</script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/plotly.js/2.35.0/plotly.min.js" integrity="sha512-L205fVN73b8Ft9dbuwTVGFb4FHVSOPpCLMQzcHa4r0+CuUswxzK/JRW7glZrpC+bO3Yaka0DYYDmtlhVbmnX+g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script type="text/javascript">
const jslcdataglobal = new Object();
const jslabelsglobal = new Object();
const jslimitsglobal = new Object();
</script>
<script type="importmap">
{
"imports": {
{% if debug %}
<!-- development -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/plotly.js/2.24.3/plotly-basic.min.js" integrity="sha512-Qim/xu0OSUPEvOUcNVZoGTDa+m4Ll1EZ+DQhsmMTlMZIj7NxvwQl6pGY0/gwlj19w0KEZ0S8ymSWUpqarPYGBQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js" crossorigin></script>
<script src="https://unpkg.com/react/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom/umd/react-dom.development.js" crossorigin></script>
<script type="text/babel" src="{% static 'js/queuepage/src/newrequest.jsx' %}"></script>
<script type="text/babel" src="{% static 'js/queuepage/src/task.jsx' %}"></script>
<script type="text/babel" src="{% static 'js/queuepage/src/tasklist.jsx' %}"></script>
"react": "https://esm.sh/react@19/?dev",
"reactdom": "https://esm.sh/react-dom@19/client?dev",
{% else %}
<!-- production -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/plotly.js/2.24.3/plotly-basic.min.js" integrity="sha512-Qim/xu0OSUPEvOUcNVZoGTDa+m4Ll1EZ+DQhsmMTlMZIj7NxvwQl6pGY0/gwlj19w0KEZ0S8ymSWUpqarPYGBQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://unpkg.com/react@18/umd/react.production.min.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js" crossorigin></script>
<script type="text/javascript" src="{% static 'js/queuepage.min.js' %}?ver=20230727"></script>
"react": "https://esm.sh/react@19/",
"reactdom": "https://esm.sh/react-dom@19/client/",
{% endif %}
"newrequest": "{% static 'js/newrequest.min.js' %}"
}
}
</script>
<script type="module" src="{% static 'js/tasklist.min.js' %}?ver=20241206"></script>
{% endblock %}
72 changes: 71 additions & 1 deletion static/js/lightcurveplotly.min.js
Original file line number Diff line number Diff line change
@@ -1 +1,71 @@
"use strict";!function(){for(var l=lcdivname,a=(jslimitsglobal[l].today-jslimitsglobal[l].xmin)/20,e=jslimitsglobal[l].xmin-a,o=jslimitsglobal[l].xmax+a,s=jslimitsglobal[l].xmin-jslimitsglobal[l].discoveryDate-a,t=jslimitsglobal[l].today-jslimitsglobal[l].discoveryDate+a,i=jslimitsglobal[l].ymin,r=jslimitsglobal[l].ymax,c=["#6A5ACD","#008000","#DAA520","#A0522D","#FF69B4","#DC143C","#708090","#FFD700","#0000FF","#4B0082","#800080","#008B8B","#FF8C00","#A52A2A","#DB7093","#800000","#B22222","#9ACD32","#FA8072","#000000"],b=[],g=0;g<jslcdataglobal[l].length;g++){var m=[],d=[],n=[],j=[],h=[];if(jslcdataglobal[l][g]){for(var y=0;y<jslcdataglobal[l][g].length;y++)jslcdataglobal[l][g][y]&&jslcdataglobal[l][g][y].length>0&&(3==jslcdataglobal[l][g][y].length?(m.push(jslcdataglobal[l][g][y][0]),d.push(jslcdataglobal[l][g][y][1]),n.push(jslcdataglobal[l][g][y][2])):(j.push(jslcdataglobal[l][g][y][0]),h.push(jslcdataglobal[l][g][y][1])));var f={x:m,y:d,error_y:{type:"data",array:n,visible:!0,width:errorbarsize,color:c[jslabelsglobal[l][g].color],opacity:.4},type:"scatter",mode:"markers",name:jslabelsglobal[l][g].label,marker:{color:c[jslabelsglobal[l][g].color],opacity:.4,line:{width:0,color:"black"},size:markersize}};"-"==jslabelsglobal[l][g].label.charAt(0)?f.marker.symbol="diamond":f.marker.symbol="circle",b.push(f);var p={x:j,y:h,type:"scatter",mode:"markers",name:jslabelsglobal[l][g].label,marker:{color:c[jslabelsglobal[l][g].color],opacity:.4,symbol:"limit-arrow",line:{width:0,color:c[jslabelsglobal[l][g].color]},size:arrowsize}};b.push(p)}}if("undefined"!=typeof lcplotwidth)lcplotwidth;else $(l).innerWidth();if(l.includes("flux"))var v=!1,x="Flux / µJy";else v="reversed",x="AB Mag";var u={showlegend:!0,yaxis:{range:[i,r],autorange:v,tickformat:".1f",hoverformat:".2f",title:x},xaxis:{tickformat:".f",hoverformat:".5f",range:[e,o],title:"mjd"},margin:{l:70,r:0,b:30,t:30},height:lcplotheight};l.includes("forced")||(u.xaxis2={tickformat:".f",overlaying:"x",zeroline:!1,side:"top",hoverformat:".5f",range:[s,t],title:"days since earliest detection"}),Plotly.react(l.replace("#",""),b,u,{displayModeBar:!1,responsive:!0})}();
// 2018-06-25 KWS Javascript Lightcurve Plotting code using Plotly.
// The code was originally written for flot, so a
// conversion needs to be done at the beginning.
// Javascript code to plot the lightcurves. NOTE that it gets its data
// a data variable in the calling page. The trick is setting that data
// correctly.
//
// This code is free of HTML tags, with the exception of <DIV>.
//
// The code requires the following data to be set in the calling HTML:
//
// * jslcdata - an array of filter arrays - e.g. for each filter do this...
// jslcdata.push([[55973.492, 20.4057, 0.024156], [55973.4929, 20.3998, 0.022031]]);
//
// * jslabels - an array of labels - the same length as the array of filters - e.g.
// jslabels.push("g");
//
// * jslclimits - a dictionary of limit values, currently xmin, xmax, ymin, ymax,
// discoveryDate and today.
// First of all, setup some global variable based on data min and max to
// setup the padding on the graph and the x2 axis. This is done here, rather
// than in the calling page, because the padding, etc is presentation specific.
// GLOBAL VARIABLES BEGIN
// 2013-02-06 KWS Wrap the entire code in an anonymous function block. This forces
// everything within here into a different scope. It means that the
// plot code can be called multiple times on the same page without
// worrying about variable name clashes. Needed for window resize.
"use strict";(function(){// Need to set the div ID from the global data
var locallcdivname=lcdivname;//var lightcurve = $(locallcdivname);
// Always refer to the external data via the global variable and lcdivname.
var pad=20;// i.e. 5 percent
var xpadding=(jslimitsglobal[locallcdivname]["today"]-jslimitsglobal[locallcdivname]["xmin"])/pad;var xmin=jslimitsglobal[locallcdivname]["xmin"]-xpadding;var xmax=jslimitsglobal[locallcdivname]["xmax"]+xpadding;var x2min=jslimitsglobal[locallcdivname]["xmin"]-jslimitsglobal[locallcdivname]["discoveryDate"]-xpadding;var x2max=jslimitsglobal[locallcdivname]["today"]-jslimitsglobal[locallcdivname]["discoveryDate"]+xpadding;var ymin=jslimitsglobal[locallcdivname]["ymin"];var ymax=jslimitsglobal[locallcdivname]["ymax"];// color palette for each data series (up to 20 at the moment)
var colors=["#6A5ACD",//SlateBlue
"#008000",//Green
"#DAA520",//GoldenRod
"#A0522D",//Sienna
"#FF69B4",//HotPink
"#DC143C",//Crimson
"#708090",//SlateGray
"#FFD700",//Gold
"#0000FF",//Blue
"#4B0082",//Indigo
"#800080",//Purple
"#008B8B",//DarkCyan
"#FF8C00",//Darkorange
"#A52A2A",//Brown
"#DB7093",//PaleVioletRed
"#800000",//Maroon
"#B22222",//FireBrick
"#9ACD32",//YellowGreen
"#FA8072",//Salmon
"#000000"];//Black
// Should feed the colors form the calling page - better still, the CSS
var plotColors={"backgroundColor":"#FFFFFF","axisColor":"#000000","tickColor":"#BFBFBF","shadingColor":"#DDDDDD","tooltipBackground":"#EEEEFF","tooltipBorder":"#FFDDDD","todaylineColor":"FF0000"};// GLOBAL VARIABLES END
// So... Flot wanted [[x, y, error], [x, y, error], ...]
// Plotly wants [x, x, ...], [y, y, ...], [error, error, ...]. Should be easy to convert,
// but it's a bit of a pain!
// All the lightcurve data
var data=[];for(var filter=0;filter<jslcdataglobal[locallcdivname].length;filter++){// All the filter data
var detx=[];var dety=[];var dete=[];var nondetx=[];var nondety=[];if(jslcdataglobal[locallcdivname][filter]){for(var lc=0;lc<jslcdataglobal[locallcdivname][filter].length;lc++){// Split out the dets and non-dets into separate arrays
if(jslcdataglobal[locallcdivname][filter][lc]){if(jslcdataglobal[locallcdivname][filter][lc].length>0){if(jslcdataglobal[locallcdivname][filter][lc].length==3){// It's a det
detx.push(jslcdataglobal[locallcdivname][filter][lc][0]);dety.push(jslcdataglobal[locallcdivname][filter][lc][1]);dete.push(jslcdataglobal[locallcdivname][filter][lc][2])}else{// It's a non-det
nondetx.push(jslcdataglobal[locallcdivname][filter][lc][0]);nondety.push(jslcdataglobal[locallcdivname][filter][lc][1])}}}}// Add the plot properties
var tracedets={x:detx,y:dety,error_y:{type:"data",array:dete,visible:true,width:errorbarsize,color:colors[jslabelsglobal[locallcdivname][filter]["color"]],opacity:0.4},type:"scatter",mode:"markers",name:jslabelsglobal[locallcdivname][filter]["label"],marker:{color:colors[jslabelsglobal[locallcdivname][filter]["color"]],opacity:0.4,line:{width:0,color:"black"},size:markersize}};if(jslabelsglobal[locallcdivname][filter]["label"].charAt(0)=="-"){tracedets["marker"]["symbol"]="diamond"}else{tracedets["marker"]["symbol"]="circle"}data.push(tracedets);var tracenondets={x:nondetx,y:nondety,type:"scatter",mode:"markers",name:jslabelsglobal[locallcdivname][filter]["label"],marker:{color:colors[jslabelsglobal[locallcdivname][filter]["color"]],opacity:0.4,symbol:"limit-arrow",line:{width:0,color:colors[jslabelsglobal[locallcdivname][filter]["color"]]},size:arrowsize}};data.push(tracenondets)}}if(typeof lcplotwidth!=="undefined"){var w=lcplotwidth}else{var w=$(locallcdivname).innerWidth()}if(locallcdivname.includes("flux")){var yautorange=false;var ylabel="Flux / \xB5Jy"}else{var yautorange="reversed";var ylabel="AB Mag"}var layout={showlegend:true,yaxis:{range:[ymin,ymax],autorange:yautorange,tickformat:".1f",hoverformat:".2f",title:ylabel},xaxis:{tickformat:".f",hoverformat:".5f",range:[xmin,xmax],title:"mjd"},margin:{l:70,r:0,b:30,t:30},// width: w, //window.innerWidth,
// width: '100%',
height:lcplotheight//window.innerHeight
};//paper_bgcolor: 'rgba(0,0,0,0)'}
//plot_bgcolor: 'rgba(0,0,0,0)'}
// 2018-10-11 KWS Add another x axis if not forced photometry
if(!locallcdivname.includes("forced")){layout["xaxis2"]={tickformat:".f",overlaying:"x",zeroline:false,side:"top",hoverformat:".5f",range:[x2min,x2max],title:"days since earliest detection"}}Plotly.react(locallcdivname.replace("#",""),data,layout,{displayModeBar:false,responsive:true})})();

Loading

0 comments on commit baa4a47

Please sign in to comment.