Skip to content

Commit

Permalink
Merge pull request #181 from VALIDproject/feature_negativeValuesFlip
Browse files Browse the repository at this point in the history
Feature negative values flip
  • Loading branch information
doomsayer2 authored May 25, 2018
2 parents 5e678a8 + c7ab503 commit 8be40b6
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/app_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ export class AppConstants {
static SANKEY_TOP_MARGIN = 10;
static SANKEY_NODE_PADDING = 20;

//FILE DOWNLOADS
// FILE DOWNLOADS
static ASYLUM_FILE = 'https://dl.dropboxusercontent.com/s/cr3iu0adtb77de6/Asylum_Seekers_Data.csv?dl=0';
static FARM_FILE = 'https://dl.dropboxusercontent.com/s/zunih3hkcooh1gm/Farm_Subsidies_Data.csv?dl=0';
static MEDIA_FILE = 'https://dl.dropboxusercontent.com/s/34ev5sr6u3xdisq/Media_Transperency_Data.csv?dl=0';
static FILE4 = 'https://dl.dropboxusercontent.com/s/k4dhuh7hnmoclzf/Simple_Data.csv?dl=0';
static OECD_FILE = 'https://dl.dropboxusercontent.com/s/cvigz33c3g8h5be/Aid_Payments_OECD.csv?dl=0'
}
36 changes: 29 additions & 7 deletions src/data_import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {MAppViews} from './app';
import {AppConstants} from './app_constants';
import {USAGE_INFO, DOWNLOAD_INFO, DOWNLOAD_DIALOG} from './language';
import SimpleLogging from './simpleLogging';
import time = d3.time;

const keyRep: Array<string> = ['sourceNode', 'targetNode', 'timeNode', 'valueNode', 'attribute1', 'attribute2'];

Expand Down Expand Up @@ -280,7 +281,9 @@ class DataImport implements MAppViews {
setTimeout(() => {
// Before rework the keys of the data
SimpleLogging.log('import special button','');

this.reworkKeys(this.parseResults);
this.reworkNegativeValues(this.parseResults);
this.makeNodesUnique();

if(this.editMode) {
Expand All @@ -289,15 +292,15 @@ class DataImport implements MAppViews {
alertify.closeLogOnClick(true).delay(0).error(msg);
console.log('In edit mode');
} else {
d3.select('.dataLoadingView').classed('invisibleClass', true);
d3.select('.dataVizView').classed('invisibleClass', false);
this.storeData();
events.fire(AppConstants.EVENT_DATA_PARSED, 'parsed');

console.log('Not in edit mode');
Promise.resolve(this.storeData()).then(res => {
console.log('res: ', res);
events.fire(AppConstants.EVENT_DATA_PARSED, 'parsed');
d3.select('.dataLoadingView').classed('invisibleClass', true);
d3.select('.dataVizView').classed('invisibleClass', false);
});
}
}, 4000);

}
});
}
Expand Down Expand Up @@ -359,6 +362,10 @@ class DataImport implements MAppViews {
localStorage.setItem('dataLoaded', 'loaded');
localStorage.setItem('fileName', this.uploadedFileName);
localStorage.setItem('columnLabels', JSON.stringify(this.reworkColumnLabels(this.parseResults.meta.fields)));

return new Promise((resolve) => {
resolve('Data storage finished.');
});
}

/**
Expand Down Expand Up @@ -388,7 +395,6 @@ class DataImport implements MAppViews {
delete e[keys[i]];
}
});

this.parseResults.data = data;
}

Expand All @@ -410,6 +416,22 @@ class DataImport implements MAppViews {
});
}

/**
* This function is used to remove negative values if there are some in order to display the data
* appropriately. Furthermore the source and target are flipped in order to represen the change.
* @param json with the original data
*/
private reworkNegativeValues(json) {
const data = json.data;
data.forEach(o => {
if (o.valueNode < 0) {
[o.sourceNode, o.targetNode] = [o.targetNode, o.sourceNode];
o.valueNode = (o.valueNode * -1) + '';
}
});
this.parseResults.data = data;
}

/**
* This function creates a html table to view the data from the .csv in a visual browser.
* The first 10 rows only are shown for a better viusal experience.
Expand Down
5 changes: 1 addition & 4 deletions src/flowSorter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ export default class FlowSorter implements MAppViews {
private constructor(parent: Element, private options: any) {
this.parentDOM = options.sortBySelector;
this.parentDOM2 = options.orderBySelector;
console.log(this.parentDOM, this.parentDOM2, '.... blalbalallbalb');
}

// TODO: AR renmae all occurence of sortMode with sortType or order Type where it's necessary.
// TODO: AR the other boilerplate is ready and set up for the stlye and so.
/**
* Initialize the view and return a promise
* that is resolved as soon the view is completely initialized.
Expand Down Expand Up @@ -295,7 +292,7 @@ export default class FlowSorter implements MAppViews {
// Class is a singleton an therefore only one object can exist => get object with this method
public static getInstance(parent?: Element, options?: any): FlowSorter {
if (FlowSorter.instance === null || FlowSorter.instance === undefined) {
console.log('flowsorter created with parent ' + parent);
// console.log('flowsorter created with parent ' + parent);
FlowSorter.instance = new FlowSorter(parent, options);
}

Expand Down
7 changes: 7 additions & 0 deletions src/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,12 @@ export const DOWNLOAD_DIALOG = `You can download the following sample files by k
</td>
<td class='rightTD'><a href=${AppConstants.FARM_FILE}>Download Data (.csv)</a></td>
</tr>
<tr>
<td class='leftTD'><strong>Aid payments OECD</strong><br/>
Aid payments from EU countries to developing countries in the last 10 years.
<a target='_blank' href='http://dx.doi.org/10.1787/data-00072-en'>Source</a>
</td>
<td class='rightTD'><a href=${AppConstants.OECD_FILE}>Download Data (.csv)</a></td>
</tr>
</tbody>
</table>`;
13 changes: 13 additions & 0 deletions src/sankey_diagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,19 @@ class SankeyDiagram implements MAppViews {
} else {
return sankey.nodeWidth() - Math.max(this.minFraction * sankey.nodeWidth() * d.overall / d.value, 1);
}
})
.on('click', function(d: any) {
if (d.sourceLinks.length > 0) {
const txtSource = '"' + d.name + '"';
$('#entitySearchFilter').val(txtSource);
$('#entitySearchButton').trigger('click');
$('#entitySearchFilter').addClass('flash');
} else {
const txtTarget = '"' + d.name + '"';
$('#mediaSearchFilter').val(txtTarget);
$('#mediaSearchButton').trigger('click');
$('#mediaSearchFilter').addClass('flash');
}
});

// Add in the title for the nodes
Expand Down

0 comments on commit 8be40b6

Please sign in to comment.