From 50668f5e263143fb49754435545c29600f86c01b Mon Sep 17 00:00:00 2001 From: doomsayer2 Date: Thu, 24 May 2018 16:20:33 +0200 Subject: [PATCH 1/4] Negative Flip of values boilerplate. (refs #177) --- src/data_import.ts | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/src/data_import.ts b/src/data_import.ts index d55926a..630615f 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,8 +281,14 @@ class DataImport implements MAppViews { setTimeout(() => { // Before rework the keys of the data SimpleLogging.log('import special button',''); + this.reworkKeys(this.parseResults); this.makeNodesUnique(); + this.reworkNegativeValues(this.parseResults); + + console.log('results:', this.parseResults.data.filter((o) => { + return o.valueNode > 1000; + })); if(this.editMode) { const msg = `You have ERRORS in your Table. This would produce a strange behaving @@ -289,15 +296,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 +366,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 +399,6 @@ class DataImport implements MAppViews { delete e[keys[i]]; } }); - this.parseResults.data = data; } @@ -410,6 +420,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. From 7313ca1706a6ac2f0bd916cab16a41f60ee3ca6f Mon Sep 17 00:00:00 2001 From: doomsayer2 Date: Fri, 25 May 2018 11:18:49 +0200 Subject: [PATCH 2/4] Finishes the negative value case and removes unnecessary logs. (closes #177) --- src/data_import.ts | 12 ++++-------- src/flowSorter.ts | 5 +---- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/data_import.ts b/src/data_import.ts index 630615f..8f40185 100644 --- a/src/data_import.ts +++ b/src/data_import.ts @@ -283,12 +283,8 @@ class DataImport implements MAppViews { SimpleLogging.log('import special button',''); this.reworkKeys(this.parseResults); - this.makeNodesUnique(); this.reworkNegativeValues(this.parseResults); - - console.log('results:', this.parseResults.data.filter((o) => { - return o.valueNode > 1000; - })); + this.makeNodesUnique(); if(this.editMode) { const msg = `You have ERRORS in your Table. This would produce a strange behaving @@ -299,9 +295,9 @@ class DataImport implements MAppViews { 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); + events.fire(AppConstants.EVENT_DATA_PARSED, 'parsed'); + d3.select('.dataLoadingView').classed('invisibleClass', true); + d3.select('.dataVizView').classed('invisibleClass', false); }); } }, 4000); 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); } From 6f8b535aabd82206ba2a8545f0d705c8a60158d4 Mon Sep 17 00:00:00 2001 From: doomsayer2 Date: Fri, 25 May 2018 11:28:50 +0200 Subject: [PATCH 3/4] Makes hatched nodes clickable to add them to search box. (closes #178) --- src/sankey_diagram.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 From c7ab503b6c6cec22b053e1a9bcd0cce9607a8b8e Mon Sep 17 00:00:00 2001 From: doomsayer2 Date: Fri, 25 May 2018 11:39:33 +0200 Subject: [PATCH 4/4] Adds the donor dataset for download. (closes #179) --- src/app_constants.ts | 3 ++- src/language.ts | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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/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) + `;