diff --git a/src/app_constants.ts b/src/app_constants.ts index 9faa5ed..d077cde 100644 --- a/src/app_constants.ts +++ b/src/app_constants.ts @@ -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' } diff --git a/src/data_import.ts b/src/data_import.ts index d55926a..8f40185 100644 --- a/src/data_import.ts +++ b/src/data_import.ts @@ -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 = ['sourceNode', 'targetNode', 'timeNode', 'valueNode', 'attribute1', 'attribute2']; @@ -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) { @@ -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); - } }); } @@ -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.'); + }); } /** @@ -388,7 +395,6 @@ class DataImport implements MAppViews { delete e[keys[i]]; } }); - this.parseResults.data = data; } @@ -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. diff --git a/src/flowSorter.ts b/src/flowSorter.ts index 1cdb33c..8c16c32 100644 --- a/src/flowSorter.ts +++ b/src/flowSorter.ts @@ -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. @@ -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); } diff --git a/src/language.ts b/src/language.ts index 9171c15..4f3a366 100644 --- a/src/language.ts +++ b/src/language.ts @@ -92,5 +92,12 @@ export const DOWNLOAD_DIALOG = `You can download the following sample files by k Download Data (.csv) + + Aid payments OECD
+ Aid payments from EU countries to developing countries in the last 10 years. + Source + + Download Data (.csv) + `; diff --git a/src/sankey_diagram.ts b/src/sankey_diagram.ts index 58722b1..c61223e 100644 --- a/src/sankey_diagram.ts +++ b/src/sankey_diagram.ts @@ -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