', {'class': 'btn list-group list-group-item thumb-panel'});
+ thumbBorder.popover({
+ trigger : 'hover',
+ placement: 'top',
+ html: true,
+ container: 'body',
+ content: chartCanvas,
+ });
+ thumbContainer.append(thumbBorder);
+
+ var thumbLabel = $('
', {'class': 'thumb-label'}).text(t.name);
+ thumbBorder.append(thumbLabel);
+
+ var thumbImage = $('
', {'src': loadingURL, 'class': 'thumb-loading', 'width': 32, 'height': 32});
+ thumbBorder.append(thumbImage);
+
+ $('#thumbrow').append(thumbContainer);
+
+ var img = new Image();
+ img.addEventListener('load', function() {
+ chartContext.drawImage(img, chartImageX, chartImageY);
+
+ thumbImage.removeClass('thumb-loading');
+ thumbImage.prop('src', url);
+ thumbImage.width(128);
+ thumbImage.height(128);
+ }, false);
+
+ img.addEventListener('error', function() {
+ chartContext.fillStyle = '#fff';
+ chartContext.fillRect(chartImageX+2, chartImageY+2, 508, 508);
+ chartContext.font = '28px serif';
+ chartContext.textAlign = 'center'
+ chartContext.fillStyle = '#000';
+ chartContext.fillText('Source Image Unavailable', chartWidth / 2, chartImageY + 256);
+ thumbImage.prop('src', failedURL);
+ }, false);
+
+ img.src = url;
+}
+
+function setup() {
+ // Calculate the current fractional year
+ var now = new Date();
+ $('#outepoch').val((now.getUTCFullYear() + now.getUTCMonth() / 12.0).toFixed(2));
+
+ $('#download').hide();
+ $('#download').click(function() {
+ if (targetData.length == 0)
+ return;
+
+ var zip = new JSZip();
+ for (var i in targetData) {
+ var data = new Image();
+ data.src = targetData[i][1].toDataURL();
+ zip.file(targetData[i][0].name + '.png', data.src.substr(data.src.indexOf(',')+1), {base64: true});
+ }
+
+ zip.generateAsync({type:'blob'}).then(function (blob) {
+ saveAs(blob, 'charts.zip');
+ });
+ });
+
+ $('#generate').click(function() {
+ var outepoch = $("input[name='outepoch']").val();
+ var size = $("input[name='size']").val();
+ var survey = $("select[name='survey']").val();
+ var type = $("input[name='type']:checked").val();
+ var coords = $("textarea[name='coords']").val().split('\n');
+
+ if (parseFloat(size) != size) {
+ $('#error').html('Unable to parse "' + size + '" as a number');
+ return;
+ }
+
+ if (size <= 1 || size > 100) {
+ $('#error').html('Field size must be between 1 and 100 arcmin');
+ return;
+ }
+
+ if (parseFloat(outepoch) != outepoch) {
+ $('#error').html('Unable to parse "' + outepoch + '" as a number');
+ return;
+ }
+
+ if (outepoch <= 1900 || outepoch > 2100) {
+ $('#error').html('Observing epoch must be between 1900 and 2100');
+ return;
+ }
+
+ $('#error').html('');
+ $('#thumbrow').empty();
+ $('#chartrow').empty();
+ targetData = [];
+
+ var targets = [];
+ for (var i in coords)
+ {
+ var parts = coords[i].split(/\s+/);
+ var line = Number(i) + 1;
+
+ // Skip blank lines
+ if (parts.length == 1 && parts[0] == '')
+ continue;
+
+ var name = parts[0];
+ var ra = parts[1];
+ var dec = parts[2];
+ var rapm = parts[3];
+ var decpm = parts[4];
+ var epoch = parts[5];
+
+ if (ra === undefined || !testSexagesimal.test(ra)) {
+ $('#error').html('Line ' + line + ': Unable to parse "' + ra + '" as HH:MM:SS');
+ return;
+ }
+
+ if (dec === undefined || !testSexagesimal.test(dec)) {
+ $('#error').html('Line ' + line + ': Unable to parse "' + dec + '" as DD:MM:SS');
+ return;
+ }
+
+ if (rapm === undefined || parseFloat(rapm) != rapm) {
+ $('#error').html('Line ' + line + ': Unable to parse "' + rapm + '" as number');
+ return;
+ }
+
+ if (decpm === undefined || parseFloat(decpm) != decpm) {
+ $('#error').html('Line ' + line + ': Unable to parse "' + decpm + '" as number');
+ return;
+ }
+
+ if (epoch === undefined || parseFloat(epoch) != epoch) {
+ $('#error').html('Line ' + line + ': Unable to parse "' + epoch + '" as number');
+ return;
+ }
+
+ // Enumerate through line to find start of comment (if it exists)
+ // Want to make sure we take all character from the start of the comment
+ var comment = undefined;
+ if (parts.length > 6) {
+ var start = 0;
+ for (var j = 0; j < 7; j++)
+ start = coords[i].indexOf(parts[j], start);
+ comment = coords[i].substring(start);
+ }
+
+ targets.push({
+ 'name': name,
+ 'ra': ra,
+ 'dec': dec,
+ 'rapm': rapm,
+ 'decpm': decpm,
+ 'epoch': epoch,
+ 'comment': comment,
+ 'survey': survey,
+ 'size': size,
+ 'annotate': type == 'annotated',
+ 'outepoch': outepoch,
+ });
+ }
+
+ if (targets.length == 0)
+ return;
+
+ $('#generate').removeClass('btn-primary').addClass('btn-default').text('Regenerate');
+ $('#download').show();
+ for (i in targets)
+ generateChart(targets[i]);
+ });
+}
diff --git a/templates/input.html b/templates/input.html
index bbb59b1..a192df3 100644
--- a/templates/input.html
+++ b/templates/input.html
@@ -40,7 +40,7 @@
Finding chart generator
-
+