Skip to content

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
makmanalp committed Dec 13, 2018
2 parents 6f73d23 + 1903f28 commit 891296b
Show file tree
Hide file tree
Showing 197 changed files with 4,944 additions and 323 deletions.
3 changes: 2 additions & 1 deletion .bowerrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"directory": "bower_components",
"analytics": false
"analytics": false,
"registry": "https://registry.bower.io"
}
2 changes: 1 addition & 1 deletion .env.mexico
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ OTHER_LOCALE=en-mex
DEFAULT_LOCALE=es-mex
API_URL=http://cide.cid-labs.com/api/
ROOT_URL= /
DOWNLOAD_URL=https://s3-us-west-2.amazonaws.com/datlas-mexico-downloads-prod/68a2904b27d4c3bf24ff7d5def7926d285d6577c
DOWNLOAD_URL=https://s3-us-west-2.amazonaws.com/datlas-mexico-downloads-prod
MAP_URL=http://mapserver.inegi.org.mx/MGN/mge2010v5_0.zip
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2018, Center for International Development at Harvard University
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1,050 changes: 1,050 additions & 0 deletions NOTICE

Large diffs are not rendered by default.

73 changes: 38 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#atlas-subnational-frontend
# Subnational Atlas Frontend Code

This README outlines the details of collaborating on this Ember application.
A short introduction of this app could easily go here.
Expand All @@ -8,52 +8,56 @@ A short introduction of this app could easily go here.
You will need the following things properly installed on your computer.

* [Git](http://git-scm.com/)
* [Node.js](http://nodejs.org/) (with NPM)
* [Bower](http://bower.io/)
* [Node.js](http://nodejs.org/) (6.x with NPM -- we used 6.13.1)
* [Bower](http://bower.io/) with `npm install -g bower`
* [Ember CLI](http://www.ember-cli.com/)
* [PhantomJS](http://phantomjs.org/)

## Installation

* `git clone <repository-url>` this repository
* change into the new directory
* `npm install`
* `bower install`
* Get this repository on to your computer with `git clone <repository-url>` -
if you already have it then skip this step.
* Go to the terminal and move to this the new directory.
* Run `npm install`
* Run `bower install`

## Running / Development

* `ember server` or `ember s` (these are the same)
* Run `ember server` or `ember s` (these are the same)
* Visit your app at [http://localhost:4200](http://localhost:4200).

## Running on API [Depricated]
* clone `https://github.com/cid-harvard/colombia`
* get correct db file from Mali
* `cd` into the the repo
* put db file in `colombia/database.db`
* run `make dummy && make dev`

* In a seperate terminal window `cd` into the ember app
* Run `ember s --proxy http://127.0.0.1:8001/`

### Code Generators

Make use of the many generators for code, try `ember help generate` for more details

### Running Tests

* `ember test`
* `ember test --server`

## Subfolder

In the `config/enviroment.js` file adjust the `baseURL` variable in the `var ENV` object for the enviroment e.g. `enviroment === 'production'`
## Directory Structure

- `app.js` is the entry point for the application.
- `config/environment.js` is the main Ember configuration file for the
frontend. However for the most part you won't have to touch this file.
- In many cases, this file reads a hidden file in the main directory called
`.env` that contains the most common options, like the translation files to
use (`DEFAULT_LOCALE` and `OTHER_LOCALE`) and the address where the API will
be (`API_URL`) and the downloads files will be (`DOWNLOAD_URL`).
- `/app/locales` contains all of the translation keys.
- `/app/variables/data-variables.js` contains most of the configuration related
to website data, e.g. which products to show on the homepage dropdown, how
many years of trade data there are, what logos to show on the homepage, what
paths under `DOWNLOAD_URL` to find each download file etc. This is read by
`services/feature-toggle.js`.
- `instance-initializers/locale-setter.js` handles the locale / translation
settings.
- `mixins/table-map.js` includes many table related settings, including the
widths of each column and what columns to show in what page.
- The main application logic is contained in the `routes/` `controllers/` and
`templates/`. The routes determine what data to fetch and how, the
controllers handle display-related logic (and user events like clicks) and
the templates handle the actual HTML structure that ends up on the page. Read
the ember.js documentation for more on this.
- `router.js` has the mapping from URLs to files in `routes/blah.js`.

### Building

Current ENV files
* colombia
* mexico
* peru
Current `.env` files
* `colombia.env`
* `mexico.env`
* `peru.env`

To use a country
* run `ember build -e <enviroment>` e.g. `ember build -e colombia`
Expand Down Expand Up @@ -101,4 +105,3 @@ SUB-FOLDERS
* Development Browser Extensions
* [ember inspector for chrome](https://chrome.google.com/webstore/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi)
* [ember inspector for firefox](https://addons.mozilla.org/en-US/firefox/addon/ember-inspector/)

8 changes: 8 additions & 0 deletions app/adapters/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ export default DS.RESTAdapter.extend({
return 'metadata/products';
} else if(type === 'industry') {
return 'metadata/industries';
} else if(type === 'land-use') {
return 'metadata/land_uses';
} else if(type === 'agproduct') {
return 'metadata/agproducts';
} else if(type === 'nonag') {
return 'metadata/nonags';
} else if(type === 'livestock') {
return 'metadata/livestock';
}
}
});
Expand Down
8 changes: 1 addition & 7 deletions app/components/geo-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ export default Ember.Component.extend({
let data = this.get('data');
let varDependent = this.get('varDependent');

let quantize = d3.scale.quantize()
.domain([0, this.get('maxValue')])
.range(d3.range(5).map(function(i) { return 'q' + i + '-5'; }));
let quantize = this.get("scale");

let nestByDepartmentId = d3.nest()
.key(function(d) { return Ember.get(d,'department_id'); })
Expand Down Expand Up @@ -63,10 +61,6 @@ export default Ember.Component.extend({
return numeral(value).format('0.0a');
}
}),
maxValue: computed('data.[]', 'varDependent', function () {
let varDependent = this.get('varDependent');
return d3.max(this.get('data'), function(d) { return Ember.get(d, varDependent); });
}),
customLayerParams: computed('data.[]', function() {
return {
type: 'layer--',
Expand Down
12 changes: 12 additions & 0 deletions app/components/graphbuilder-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ export default Ember.Component.extend({
firstYear: computed('featureToggle.first_year', function() {
return parseInt(this.get('featureToggle.first_year'));
}),
isSingleYear: computed('dateExtent', function(){
let dateExtent = this.get('dateExtent');
if (dateExtent){
if (dateExtent[1] - dateExtent[0] > 0){
return false;
} else {
return true;
}
} else {
return false;
}
}),
disableIncreaseYear: computed('year', 'lastYear', function() {
return this.get('year') >= parseInt(this.get('lastYear'));
}),
Expand Down
45 changes: 39 additions & 6 deletions app/components/graphbuilder-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,16 @@ var SortableTableCell = TableCell.extend({
isModel: computed.alias('row.content.model'),
model: computed.alias('row.content.model'),
id: computed.alias('row.content.id'),
profileRoute: computed('model', function() {
return `${this.get('model')}.show`;
profileRoute: computed('model', 'controller.source', function() {
// Link to the profile of the model type (e.g. agproduct profile if viewing
// agproducts) unless we're looking at a location variable (e.g. where is
// this agproduct harvested), in which case link to locations.
var sourceIsLocation = _.contains(['cities', 'departments', 'municipalities'], this.get('controller.source'));
if (sourceIsLocation){
return 'location.show';
} else {
return `${this.get('model')}.show`;
}
})
});

Expand All @@ -69,8 +77,19 @@ export default EmberTableComponent.extend(TableMap, {
attributeBindings: ['height'],
selectionMode: 'mutiple',
tableMap: computed('source', function() {
let entityType = this.get('entityType');
let source = this.get('source');

let map = this.get(`${source}Map`);
if (entityType === "landUse"){
map = this.get("landUseLocationsMap");
} else if (entityType === "agproduct"){
map = this.get("agproductLocationsMap");
} else if (entityType === "nonag"){
map = this.get("nonagLocationsMap");
} else if (entityType === "livestock"){
map = this.get("livestockLocationsMap");
}

_.forEach(map, (mapping) => {
if(mapping.key === 'name' || mapping.key == 'parent') { return; }
Expand All @@ -90,7 +109,7 @@ export default EmberTableComponent.extend(TableMap, {
return this.get('tableMap').filter((column) => {

// Don't ever drop the "name" column
if(column.key == "name"){
if(column.key == "name" || column.key == "parent_name"){
return false;
}

Expand Down Expand Up @@ -135,6 +154,9 @@ export default EmberTableComponent.extend(TableMap, {
},
generateCellContent: function(column) {
return (row) => {
if(_.isNull(row.get(column.key))){
return 'N/A';
}
if(_.isNumber(row.get(column.key))){
let number = row.get(column.key);
return this.formatNumber(number, column.key, this.get('i18n'));
Expand All @@ -144,10 +166,12 @@ export default EmberTableComponent.extend(TableMap, {
let color = row.get('color');
let testSpan = Ember.String.htmlSafe('<i class="ember-table-color-marker" style=background-color:' + color + '></i>');
return testSpan + row.get(`parent_name_${this.get('i18n').display}`);
} else if(column.key === 'parent_name'){
return row.get(`parent_name_${this.get('i18n').display}`);
} else if(column.key === 'code'){
return row.get('code');
} else {
return 'N/A';
return row.get(column.key);
}
};
},
Expand All @@ -162,7 +186,10 @@ export default EmberTableComponent.extend(TableMap, {
'cog',
'coi',
'industry_coi',
'population'
'population',
'yield_ratio',
'yield_index',
'average_livestock_load',
];
var percentVars = [
'share',
Expand All @@ -181,7 +208,13 @@ export default EmberTableComponent.extend(TableMap, {
'export_value',
'import_value',
'monthly_wages',
'average_wages'
'average_wages',
'area',
'production_tons',
'land_sown',
'land_harvested',
'num_farms',
'num_livestock',
];

if(_.include(wageVarsInThousands, key)){
Expand Down
10 changes: 7 additions & 3 deletions app/components/multiples-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default Ember.Component.extend({
d.name = get(d.values[0], `name_short_${this.get('i18n').display}`) || d.key;
d.color = get(d.values[0], 'color') || '#ccc1b9';
d.code = get(d.values[0], 'code');
d.values = _.sortBy(d.values, "year");
});
return _.sortBy(nest, (d) => {
return -_.sum(d.values, varDependent);
Expand Down Expand Up @@ -110,7 +111,7 @@ export default Ember.Component.extend({
.attr('class', 'chart__title')
.on('click', expandTitle)
.text((d) => {
if(get(d, 'code') && dataType != 'locations') {
if(get(d, 'code') && !_.contains(['landUses', 'farmtypes', 'agproducts', 'nonags', 'livestock', 'locations'], this.get('dataType'))) {
return `${get(d, 'name')} - ${get(d, 'code')}`;
} else {
return get(d, 'name');
Expand Down Expand Up @@ -235,11 +236,14 @@ export default Ember.Component.extend({
},true)
.attr('dx', function() {
if (date === parseInt(xExtent[0])) {
return '-4';
return '30';
} else if (date === parseInt(xExtent[1])) {
return '4';
return '-30';
}
})
.attr('dy', function() {
return '-5';
})
.text(function(d) {
index = bisect(d.values, date, 0, d.values.length - 1);
let yValue = d.values[index] ? Ember.get(d.values[index], varDependent) : 0;
Expand Down
Loading

0 comments on commit 891296b

Please sign in to comment.