1
0
Fork 0
satnogs-network/network/static/js/observation_view.js

106 lines
3.7 KiB
JavaScript
Raw Normal View History

2017-02-11 06:59:02 -07:00
/* global d3 WaveSurfer URI */
2015-07-01 10:01:20 -06:00
$(document).ready(function() {
'use strict';
2015-07-01 10:01:20 -06:00
var observation_start = 1000 * $('#observation-info').data('start');
var observation_end = 1000 * $('#observation-info').data('end');
2015-07-01 10:01:20 -06:00
var observation_data = [];
var formatTime = function(timeSeconds) {
var minute = Math.floor(timeSeconds / 60); // get minute(integer) from timeSeconds
var tmp = Math.round(timeSeconds - (minute * 60)); // get second(integer) from timeSeconds
var second = (tmp < 10 ? '0' : '') + tmp; // make two-figured integer if less than 10
return String(minute + ':' + second); // combine minute and second in string
};
2017-02-11 06:59:02 -07:00
$('.observation-data').each(function(){
var $this = $(this);
var data_groundstation = $this.data('groundstation');
var data_time_start = 1000 * $this.data('start');
var data_time_end = 1000 * $this.data('end');
2015-07-01 10:01:20 -06:00
observation_data.push({label : data_groundstation, times : [{starting_time: data_time_start, ending_time: data_time_end}]});
2015-04-07 10:00:57 -06:00
});
2014-10-07 12:23:29 -06:00
2015-07-01 10:01:20 -06:00
var chart = d3.timeline()
.stack()
.beginning(observation_start)
.ending(observation_end)
.hover(function (d, i, datum) {
var div = $('#hoverRes');
var colors = chart.colors();
div.find('.coloredDiv').css('background-color', colors(i));
2015-07-01 10:01:20 -06:00
div.find('#name').text(datum.label);
})
.margin({left:140, right:10, top:0, bottom:50})
2017-02-11 06:59:02 -07:00
.tickFormat({format: d3.time.format.utc('%H:%M'), tickTime: d3.time.minutes, tickInterval: 30, tickSize: 6});
2015-07-01 10:01:20 -06:00
var svg_width = 1140;
if (screen.width < 1200) { svg_width = 940; }
if (screen.width < 992) { svg_width = 720; }
if (screen.width < 768) { svg_width = screen.width - 30; }
2017-02-11 06:59:02 -07:00
d3.select('#timeline').append('svg').attr('width', svg_width)
.datum(observation_data).call(chart);
2015-07-01 10:01:20 -06:00
// Waveform loading
2017-02-11 06:59:02 -07:00
$('.wave').each(function(){
var $this = $(this);
var wid = $this.data('id');
2015-07-01 10:01:20 -06:00
var wavesurfer = Object.create(WaveSurfer);
var data_payload_url = $this.data('payload');
2015-07-06 06:12:33 -06:00
var container_el = '#data-' + wid;
2015-07-07 08:28:08 -06:00
var loading = '#loading';
var $playbackTime = $('#playback-time-' + wid);
2015-07-01 10:01:20 -06:00
wavesurfer.init({
2017-02-11 06:59:02 -07:00
container: container_el,
waveColor: '#bf7fbf',
progressColor: 'purple'
2015-07-01 10:01:20 -06:00
});
2015-07-06 06:12:33 -06:00
wavesurfer.on('loading', function() {
$(loading).show();
});
$this.parents('.observation-data').find('.playpause').click( function(){
2015-07-01 10:01:20 -06:00
wavesurfer.playPause();
});
wavesurfer.load(data_payload_url);
2015-07-06 06:12:33 -06:00
wavesurfer.on('ready', function() {
$playbackTime.text(formatTime(wavesurfer.getCurrentTime()));
wavesurfer.on('audioprocess', function(evt) {
$playbackTime.text(formatTime(evt));
});
wavesurfer.on('seek', function(evt) {
$playbackTime.text(formatTime(wavesurfer.getDuration() * evt));
});
2015-07-06 06:12:33 -06:00
$(loading).hide();
});
2015-04-07 10:00:57 -06:00
});
2016-03-26 08:46:50 -06:00
// Hightlight Data block
2017-02-11 06:59:02 -07:00
var uri = new URI(location.href);
var data_id = uri.hash();
$(data_id).addClass('panel-info');
// Delete confirmation
2017-02-11 06:59:02 -07:00
var message = 'Do you really want to delete this Observation?';
var actions = $('#obs-delete');
if (actions.length) {
2017-02-11 06:59:02 -07:00
actions[0].addEventListener('click', function(e) {
if (! confirm(message)) {
e.preventDefault();
}
});
}
// Initialize tooltips
2016-03-26 08:46:50 -06:00
$('[data-toggle="tooltip"]').tooltip();
2014-10-07 12:23:29 -06:00
});