Skip to content

Commit

Permalink
Merge pull request MaxBo#638 from MaxBo/feature/Frontend
Browse files Browse the repository at this point in the history
Feature/frontend
  • Loading branch information
ChrFr authored Oct 22, 2019
2 parents 2425000 + 1018cbb commit 6f8dfba
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
9 changes: 7 additions & 2 deletions repair/js/views/common/baseview.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ var BaseView = Backbone.View.extend(
},

/** format a number to currently set language **/
format: function(value){
return value.toLocaleString(this.language);
format: function(value, forceSignum){
var formatted = value.toLocaleString(this.language);
if (this.forceSignum){
if (value > 0) formatted = '+' + formatted;
if (value == 0) formatted = '+-0';
}
return formatted;
},

/**
Expand Down
1 change: 1 addition & 0 deletions repair/js/views/common/filter-flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ var FilterFlowsView = BaseView.extend(
displayWarnings: true,
filter: filter
});
this.flowsView.loader = this.loader;
var displayLevel = this.displayLevelSelect.value;
this.flowsView.draw(displayLevel);
},
Expand Down
1 change: 0 additions & 1 deletion repair/js/views/common/flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ var FlowsView = BaseView.extend(
apiTag: 'flows',
apiIds: [ this.caseStudy.id, this.keyflowId]
});

this.loader.activate();
var data = {};
if (options.strategy)
Expand Down
18 changes: 6 additions & 12 deletions repair/js/views/common/flowsankey.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ var FlowSankeyView = BaseView.extend(
selectable: true,
gradient: false,
stretchFactor: (this.stretchInput) ? this.stretchInput.value: 1,
selectOnDoubleClick: (dblclkCheck) ? dblclkCheck.checked : false
selectOnDoubleClick: (dblclkCheck) ? dblclkCheck.checked : false,
forceSignum: this.forceSignum
})

// redirect the event with same properties
Expand Down Expand Up @@ -213,14 +214,12 @@ var FlowSankeyView = BaseView.extend(
fractions.forEach(function(material){
var amount = (material.value != null) ? material.value: material.amount;
if (amount == 0) return;
if (_this.forceSignum && amount >= 0)
text += '+';
if (_this.showRelativeComposition){
fraction = amount / totalAmount,
value = Math.round(fraction * 100000) / 1000;
text += _this.format(value) + '%';
text += _this.format(value, _this.forceSignum) + '%';
} else {
text += _this.format(amount) + ' ' + gettext('t/year');
text += _this.format(amount, _this.forceSignum) + ' ' + gettext('t/year');
}
text += ' ' + material.name
if (material.avoidable) text += ' <i>' + gettext('avoidable') +'</i>';
Expand Down Expand Up @@ -263,9 +262,6 @@ var FlowSankeyView = BaseView.extend(
var crepr = compositionRepr(flow),
amount = flow.get('amount'),
value = (norm === 'log')? normalize(amount): Math.round(amount);

if (_this.forceSignum && amount >= 0)
amount = '+' + amount.toLocaleString(this.language);
links.push({
id: flow.id,
originalData: flow,
Expand Down Expand Up @@ -323,7 +319,7 @@ var FlowSankeyView = BaseView.extend(

var header = [gettext('origin'), gettext('origin') + '_code', gettext('origin') + '_wkt',
gettext('destination'), gettext('destination') + '_code', gettext('destination') + '_wkt',
gettext('amount'), gettext('composition')],
gettext('amount (t/year)'), gettext('composition')],
rows = [],
_this = this;
rows.push(header.join('\t'));
Expand All @@ -340,11 +336,9 @@ var FlowSankeyView = BaseView.extend(
destination = link.target,
originName = origin.name,
destinationName = (!link.isStock) ? destination.name : gettext('Stock'),
amount = _this.format(link.amount) + ' ' + link.units,
amount = _this.format(link.amount, _this.forceSignum),
composition = link.composition;

if (_this.forceSignum && amount >= 0)
amount = '-' + amount;
var originCode = origin.code,
destinationCode = (destination) ? destination.code: '',
originWkt = '',
Expand Down
1 change: 1 addition & 0 deletions repair/js/views/status-quo/workshop-flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ var FlowsWorkshopView = BaseView.extend(
materials: this.materials,
filter: filter
});
this.flowsView.loader = this.loader;
this.draw();
},

Expand Down
1 change: 1 addition & 0 deletions repair/js/views/strategy/modified-flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ var ModifiedFlowsView = BaseView.extend(
filter: filter,
strategy: this.strategy
});
this.flowsView.loader = this.loader;
this.draw();
},

Expand Down
9 changes: 8 additions & 1 deletion repair/js/visualizations/sankey.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ class Sankey{
.size([this.width * this.stretchFactor, this.height])
.align(alignment);
this.selectable = options.selectable;
this.forceSignum = options.forceSignum;
this.gradient = options.gradient;
this.selectOnDoubleClick = options.selectOnDoubleClick || false;
}

format(d) {
return d.toLocaleString(this.language);
var formatted = d.toLocaleString(this.language);
if (this.forceSignum){
if (d > 0) formatted = '+' + formatted;
if (d == 0) formatted = '+-0';
}
return formatted;
}

align(alignment){
Expand Down Expand Up @@ -175,6 +181,7 @@ class Sankey{
outSum += parseInt(link.amount || link.value);
if (!outUnits) outUnits = link.units;
}

var ins = "in: " + _this.format(inSum) + " " + (inUnits || ""),
out = "out: " + _this.format(outSum) + " " + (outUnits || "");
var text = (d.text) ? d.text + '<br>': '';
Expand Down

0 comments on commit 6f8dfba

Please sign in to comment.