From 56d84302cf1009b43fe1c486024294ace70c7686 Mon Sep 17 00:00:00 2001 From: Goutte Date: Mon, 15 Oct 2018 12:44:07 +0200 Subject: [PATCH] Continue the great refacto and improve ticks @Vincent --- web/run.py | 3 +-- web/static/js/main.js | 69 +++++++++++++++++++++++++++++++++++++++++---------------------------- 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/web/run.py b/web/run.py index b51a3fe..f783e0d 100755 --- a/web/run.py +++ b/web/run.py @@ -649,8 +649,7 @@ def get_data_for_target(target_config, input_slug, # Keep adding exceptions here until you can't or become mad - # First model has priority: ignore data from other models - if dkey not in all_data: + if dkey not in all_data: # since first model has priority # /!\ MUST be in the same order as PROPERTIES all_data[dkey] = ( dtime.strftime("%Y-%m-%dT%H:%M:%S+00:00"), diff --git a/web/static/js/main.js b/web/static/js/main.js index 21e64b3..7ec6146 100644 --- a/web/static/js/main.js +++ b/web/static/js/main.js @@ -69,14 +69,24 @@ this.time_series = []; } + /** + * This is called by the inline bootstrap javascript code. + * This ain't in the constructor because it might return a Promise later on. + * (for the loader, for example) + * + * @param started_at string + * @param stopped_at string + */ init(started_at, stopped_at) { // "This is called by the inline bootstrap javascript code.\nThis ain't in the constructor because it might return a Promise later on.\n(for the loader, for example)"; const app = this; - started_at = moment(started_at).hours(0).minutes(0).seconds(0); - stopped_at = moment(stopped_at).hours(0).minutes(0).seconds(0); + + started_at = moment(started_at).utc().hours(0).minutes(0).seconds(0); + stopped_at = moment(stopped_at).utc().hours(0).minutes(0).seconds(0); this.setStartAndStop(started_at, stopped_at); this.loadAndCreatePlots(started_at, stopped_at); window.addEventListener('resize', () => app.resize()); + return this; } @@ -86,6 +96,7 @@ url = url.replace('', target_slug); url = url.replace('', started_at); url = url.replace('', stopped_at); + return url; } @@ -284,8 +295,13 @@ }); } + /** + * + * @param started_at moment(.js) datetime object + * @param stopped_at moment(.js) datetime object + * @returns {SpaceWeather} + */ loadAndCreatePlots(started_at, stopped_at) { - // "started_at: moment(.js) datetime object\nstopped_at: moment(.js) datetime object"; let targets; let res$; let k; @@ -595,18 +611,6 @@ } init() { - let ref$; - let width; - let height; - let formatMillisecond; - let formatSecond; - let formatMinute; - let formatHour; - let formatDay; - let formatWeek; - let formatMonth; - let formatYear; - let multiFormat; let clipId; let i$; let len$; @@ -621,7 +625,9 @@ bottom: 30, left: 80 }; - ref$ = this.recomputeDimensions(), width = ref$[0], height = ref$[1]; + let dimensions = this.recomputeDimensions(); + let width = dimensions[0]; + let height = dimensions[1]; this.xDataExtent = d3.extent(this.data, d => d.x); this.yDataExtent = d3.extent(this.data, d => d.y); if (this.options['started_at']) { @@ -632,15 +638,15 @@ } this.xScale = d3.scaleTime().domain(this.xDataExtent); this.yScale = d3.scaleLinear().domain(this.yDataExtent); - formatMillisecond = d3.utcFormat(".%L"); - formatSecond = d3.utcFormat(":%S"); - formatMinute = d3.utcFormat("%H:%M"); - formatHour = d3.utcFormat("%H:%M"); - formatDay = d3.utcFormat("%a %d"); - formatWeek = d3.utcFormat("%b %d"); - formatMonth = d3.utcFormat("%B"); - formatYear = d3.utcFormat("%Y"); - multiFormat = date => { + const formatMillisecond = d3.utcFormat(".%L"); + const formatSecond = d3.utcFormat(":%S"); + const formatMinute = d3.utcFormat("%H:%M"); + const formatHour = d3.utcFormat("%H:%M"); + const formatDay = d3.utcFormat("%a %d"); + const formatWeek = d3.utcFormat("%b %d"); + const formatMonth = d3.utcFormat("%B"); + const formatYear = d3.utcFormat("%Y"); + const multiFormat = date => { if (date > d3.timeSecond(date)) { return formatMillisecond(date); } @@ -663,8 +669,10 @@ if (date > d3.timeYear(date)) { return formatMonth(date); } + return formatYear(date); }; + // let formatScience = d3.utcFormat("%Y"); this.xAxis = d3.axisBottom().tickFormat(multiFormat).ticks(7); this.yAxis = d3.axisLeft().ticks(10); this.svg = d3.select(this.container).append('svg'); @@ -681,8 +689,8 @@ this.createCatalogLayers(); this.horizontalLines = []; if (this.options['horizontalLines']) { - for (i$ = 0, len$ = (ref$ = this.options['horizontalLines']).length; i$ < len$; ++i$) { - line = ref$[i$]; + for (i$ = 0, len$ = (dimensions = this.options['horizontalLines']).length; i$ < len$; ++i$) { + line = dimensions[i$]; lineElement = this.svg.append("line").attr("class", "line horitonal-line").style("stroke", "orange").style("stroke-dasharray", "3, 2"); this.horizontalLines.push({ 'element': lineElement, @@ -898,7 +906,12 @@ createCatalogLayer(started_at, stopped_at) { let layer_rect; - layer_rect = this.pathWrapper.append("rect").attr('y', 0).attr('height', this.plotHeight).attr('fill', '#FFFD64C2'); + layer_rect = this.pathWrapper.append("rect") + .attr('y', 0) + .attr('height', this.plotHeight) + .attr('fill', '#FFFD64C2'); + //won't work, possibly because of our input catcher rect. + //layer_rect.append('svg:title').text("!"); return layer_rect; } -- libgit2 0.21.2