Skip to content

Commit

Permalink
always use m instead of cm, use lambda api
Browse files Browse the repository at this point in the history
  • Loading branch information
SiggyF committed May 6, 2017
1 parent e04e53a commit 7ddcc15
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
6 changes: 3 additions & 3 deletions app/data/models.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"engine": "Delft3D Flow",
"timeseries": "data/timeseries/dcsm.json",
"realtime": {
"points": "data/points"
"points": "https://tr4e0lb583.execute-api.us-east-1.amazonaws.com/dev/points",
"details": "https://tr4e0lb583.execute-api.us-east-1.amazonaws.com/dev/details/${location}"
},
"uv": {
"src": "models/movies/dcsm.mp4",
Expand All @@ -24,8 +25,7 @@
"extent": {
"sw": [49.264198303222656, -3.877345323562622],
"ne": [57.1629943847656, 9.84266757965088],
"time": ["2016-12-20T20:40:00Z", "2016-12-28T20:40:00Z"],
"waterlevel": [-2, 5]
"time": ["2017-05-01T20:40:00Z", "2017-05-08T20:40:00Z"]
},
"view": {
"zoom": 7,
Expand Down
45 changes: 35 additions & 10 deletions app/scripts/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,26 @@
// data is in the feature
Vue.set(this, 'series', [feature.properties.series]);
} else {
var url = 'data/details/' + _.get(feature, 'properties.locationCode', feature.id);
// get the url
let url = _.get(
this.model,
'realtime.details',
'data/details/${location}'
);

let location = _.get(feature, 'properties.locationCode', feature.id);

// we have a template url
if (_.includes(url, '${location}')) {
// fill in template
url = _.template(url)({location: location});
}

// we have a repository
if (this.repository !== '') {
url = urljoin(this.repository, 'data/details', feature.id);
url = urljoin(this.repository, url);
}

fetch(url)
.then((resp)=>{
return resp.json();
Expand Down Expand Up @@ -105,10 +121,19 @@

var xDomain = _.map(this.model.extent.time, d3.isoParse);
this.chart.xTime.domain(xDomain);
this.chart.yWaterlevel.domain(_.get(this.model.extent, 'waterlevel', [0, 1]));
var values = _.flatMap(_.flatMap(this.series, 'data'), 'value');
var extent = d3.extent(values);
var yDomain = _.get(
this.model.extent,
'waterlevel',
extent
);
this.chart.yWaterlevel.domain(yDomain);
this.chart.xAxis
.transition()
.call(d3.axisBottom(this.chart.xTime));
this.chart.yAxis
.transition()
.call(
d3.axisLeft(this.chart.yWaterlevel)
.ticks(5)
Expand Down Expand Up @@ -136,9 +161,9 @@
return this.chart.xTime(t0);
})
.attr('y', (d) => {
var y = this.model.extent.waterlevel[1];
var y = yDomain[1];
if (!_.isNil(d.to)) {
y = d.to / 100.0;
y = d.to;
}
return this.chart.yWaterlevel(y);
})
Expand All @@ -149,13 +174,13 @@
return width;
})
.attr('height', (d) => {
var y0 = this.model.extent.waterlevel[0];
var y0 = yDomain[0];
if (!_.isNil(d.from)) {
y0 = d.from / 100.0;
y0 = d.from;
}
var y1 = this.model.extent.waterlevel[1];
var y1 = yDomain[1];
if (!_.isNil(d.to)) {
y1 = d.to / 100.0;
y1 = d.to;
}
var height = this.chart.yWaterlevel(y0) - this.chart.yWaterlevel(y1);
if (height < 0) {
Expand Down Expand Up @@ -184,7 +209,7 @@
return x;
})
.y((d) => {
var y = this.chart.yWaterlevel(d.s1 || d.value / 100.0);
var y = this.chart.yWaterlevel(d.s1 || d.value);
// cm/m
return y;
});
Expand Down
21 changes: 15 additions & 6 deletions app/scripts/realtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,23 @@
},
methods: {
fetchPoints() {
var url = 'data/points';

if (_.isNil(this.model)) {
// no model yet, wait for watch
return;
}

let url = _.get(
this.model,
'realtime.points',
'data/points'
);

// we have a repository
if (this.repository !== '') {
if (_.isNil(this.model)) {
// no model yet, wait for watch
return;
}
url = urljoin(this.repository, this.model.realtime.points);
url = urljoin(this.repository, url);
}

fetch(url)
.then((resp) => {
return resp.json();
Expand Down

0 comments on commit 7ddcc15

Please sign in to comment.