Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' into issue_100_pdf_signing
Browse files Browse the repository at this point in the history
  • Loading branch information
msom committed Jun 1, 2017
2 parents e8dbbfe + 55dafef commit 36d9975
Show file tree
Hide file tree
Showing 27 changed files with 336 additions and 280 deletions.
3 changes: 3 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
- Adds PDF signing.
[msom]

- Improves party results.
[msom]

1.10.1 (2017-05-31)
~~~~~~~~~~~~~~~~~~~

Expand Down
10 changes: 7 additions & 3 deletions docs/format_election_de.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,13 @@ Es werden folgende Spalten ausgewertet und sollten vorhanden sein:

Name|Beschreibung
---|---
`Partei`|Der Name der Partei.
`Stimmen`|Die Anzahl Stimmen.
`Sitze`|Die Anzahl Sitze.
`year`|Das Jahr der Wahl.
`total_votes`|Die Gesamtanzahl der Stimmen der Wahl.
`name`|Der Name der Partei.
`color`|Die Farbe der Partei.
`mandates`|Die Anzahl Mandate der Partei.
`votes`|Die Anzahl Stimmen der Partei.


### Template

Expand Down
9 changes: 6 additions & 3 deletions docs/format_election_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,12 @@ The following columns will be evaluated and should exist:

Name|Description
---|---
`Partei`|The name of the party.
`Stimmen`|The number of votes.
`Sitze`|The number of mandates.
`year`|The year of the election.
`total_votes`|The total votes of the election.
`name`|The name of the party.
`color`|The color of the party.
`mandates`|The number of mandates.
`votes`|The number of votes.

### Template

Expand Down
10 changes: 7 additions & 3 deletions docs/format_election_fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,13 @@ The following columns will be evaluated and should exist:

Nom|Description
---|---
`Partei`|The name of the party.
`Stimmen`|The number of votes.
`Sitze`|The number of mandates.
`year`|The year of the election.
`total_votes`|The total votes of the election.
`name`|The name of the party.
`color`|The color of the party.
`mandates`|The number of mandates.
`votes`|The number of votes.


### Template

Expand Down
9 changes: 6 additions & 3 deletions docs/format_election_it.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,12 @@ The following columns will be evaluated and should exist:

Nome|Descrizione
---|---
`Partei`|The name of the party.
`Stimmen`|The number of votes.
`Sitze`|The number of mandates.
`year`|The year of the election.
`total_votes`|The total votes of the election.
`name`|The name of the party.
`color`|The color of the party.
`mandates`|The number of mandates.
`votes`|The number of votes.

### Template

Expand Down
9 changes: 6 additions & 3 deletions docs/format_election_rm.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,12 @@ The following columns will be evaluated and should exist:

Num|Descripziun
---|---
`Partei`|The name of the party.
`Stimmen`|The number of votes.
`Sitze`|The number of mandates.
`year`|The year of the election.
`total_votes`|The total votes of the election.
`name`|The name of the party.
`color`|The color of the party.
`mandates`|The number of mandates.
`votes`|The number of votes.

### Template

Expand Down
7 changes: 5 additions & 2 deletions docs/open_data_de.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,12 @@ Die Rohdaten sind als CSV verfügbar. Die folgenden Felder sind enthalten:

Name|Description
---|---
`year`|Das Jahr der Wahl.
`total_votes`|Die Gesamtanzahl der Stimmen der Wahl.
`name`|Der Name der Partei.
`mandates`|Die Anzahl gewonnener Sitze.
`votes`|Die Anzahl erhaltener Stimmen.
`color`|Die Farbe der Partei.
`mandates`|Die Anzahl Mandate der Partei.
`votes`|Die Anzahl Stimmen der Partei.

3 Abstimmungsresultate
----------------------
Expand Down
3 changes: 3 additions & 0 deletions docs/open_data_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ The raw data is available as CSV. The following fields are included:

Name|Description
---|---
`year`|The year of the election.
`total_votes`|The total votes of the election.
`name`|The name of the party.
`color`|The color of the party.
`mandates`|The number of mandates.
`votes`|The number of votes.

Expand Down
3 changes: 3 additions & 0 deletions docs/open_data_fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ The raw data is available as CSV. The following fields are included:

Name|Description
---|---
`year`|The year of the election.
`total_votes`|The total votes of the election.
`name`|The name of the party.
`color`|The color of the party.
`mandates`|The number of mandates.
`votes`|The number of votes.

Expand Down
3 changes: 3 additions & 0 deletions docs/open_data_it.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ The raw data is available as CSV. The following fields are included:

Name|Description
---|---
`year`|The year of the election.
`total_votes`|The total votes of the election.
`name`|The name of the party.
`color`|The color of the party.
`mandates`|The number of mandates.
`votes`|The number of votes.

Expand Down
3 changes: 3 additions & 0 deletions docs/open_data_rm.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ The raw data is available as CSV. The following fields are included:

Name|Description
---|---
`year`|The year of the election.
`total_votes`|The total votes of the election.
`name`|The name of the party.
`color`|The color of the party.
`mandates`|The number of mandates.
`votes`|The number of votes.

Expand Down
14 changes: 12 additions & 2 deletions docs/templates/election_party_results.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
Partei,Stimmen,Sitze
BDP,60387,1
name,color,year,total_votes,votes,mandates
AL,#a74c97,2017,0,0,0
BDP,#efb52c,2017,0,0,0
CVP,#ff6300,2017,0,0,0
EDU,#7f6b65,2017,0,0,0
EVP,#e3c700,2017,0,0,0
FDP,#4068c8,2017,0,0,0
GLP,#aeca00,2017,0,0,0
Grüne,#4abb3e,2017,0,0,0
Piraten,#333333,2017,0,0,0
SP,#db3c27,2017,0,0,0
SVP,#3f841a,2017,0,0,0

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions onegov/election_day/assets/js/__tests__/d3.chart.grouped.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ const results = [
{"active": false, "group": "CCC", "value": {"front": 10, "back": 10}, "item": "1000"},
{"active": true, "group": "CCC", "value": {"front": 10, "back": 10}, "item": "2000"},
{"active": false, "group": "CCC", "value": {"front": 10, "back": 10}, "item": "3000"},
{"active": false, "group": "DDDD", "value": {"front": 25, "back": 30}, "item": "1000"},
{"active": true, "group": "DDDD", "value": {"front": 25, "back": 30}, "item": "2000"},
{"active": false, "group": "DDDD", "value": {"front": 25, "back": 30}, "item": "3000"},
{"active": false, "group": "EEEEE", "value": {"front": 50, "back": 40}, "item": "1000"},
{"active": true, "group": "EEEEE", "value": {"front": 50, "back": 40}, "item": "2000"},
{"active": false, "group": "EEEEE", "value": {"front": 50, "back": 40}, "item": "3000"},
{"active": false, "group": "DDDD", "value": {"front": 25, "back": 30}, "item": "1000", "color": "#ff6300"},
{"active": true, "group": "DDDD", "value": {"front": 25, "back": 30}, "item": "2000", "color": "#ff6300"},
{"active": false, "group": "DDDD", "value": {"front": 25, "back": 30}, "item": "3000", "color": "#ff6300"},
{"active": false, "group": "EEEEE", "value": {"front": 50, "back": 40}, "item": "1000", "color": "#4068c8"},
{"active": true, "group": "EEEEE", "value": {"front": 50, "back": 40}, "item": "2000", "color": "#4068c8"},
{"active": false, "group": "EEEEE", "value": {"front": 50, "back": 40}, "item": "3000", "color": "#4068c8"},
{"active": false, "group": "FFFFFF", "value": {"front": 100, "back": 100}, "item": "1000"},
{"active": true, "group": "FFFFFF", "value": {"front": 100, "back": 100}, "item": "2000"},
{"active": false, "group": "FFFFFF", "value": {"front": 100, "back": 100}, "item": "3000"},
Expand Down Expand Up @@ -130,7 +130,7 @@ describe('Grouped bar chart', () => {
expect(chart.width()).toBe(2000);
});

it('renders a svg with wrong more groups and labels as in the data', () => {
it('renders a svg with more groups and labels as in the data', () => {
var document = jsdom.jsdom();
var chart = groupedChart({
width: 700,
Expand Down
79 changes: 56 additions & 23 deletions onegov/election_day/assets/js/d3.chart.grouped.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@
if (params.interactive) interactive = params.interactive;
}

var updateScales = function(scale) {
// Adjusts the x/dx scales to the current width. If there is not
// enough space to show all bars, layout all bars of one group
// to the same position.
scale.x.rangeRoundPoints([0, width], 1.0);
scale.simple = (width < data.groups.length * data.labels.length * options.barOuterWidth * 1.2);
if (scale.simple) {
scale.dx.range([-Math.round(options.barOuterWidth/2)]);
} else {
scale.dx.rangeRoundBands([
-(data.labels.length * options.barOuterWidth)/2,
(data.labels.length * options.barOuterWidth)/2
]);
}
};

var chart = function(container) {

// Try to read a default width from the container if none is given
Expand Down Expand Up @@ -62,9 +78,10 @@
x: d3.scale.ordinal(),
dx: d3.scale.ordinal(),
y: {
front: d3.scale.linear().range([height - options.axisHeight, 0]),
back: d3.scale.linear().range([height - options.axisHeight, 0])
}
front: d3.scale.linear().rangeRound([height - options.axisHeight, 0]),
back: d3.scale.linear().rangeRound([height - options.axisHeight, 0])
},
simple: false
};

var axis = {front: null, back: null, all: null};
Expand All @@ -74,17 +91,11 @@
if (data.results && data.labels && data.groups && data.maximum && data.axis_units) {

// Adjust the scales
scale.x.domain(data.groups).rangeRoundPoints([0, width], 1.0);
scale.dx
.domain(data.labels)
.rangeRoundBands(
[
-(data.labels.length * options.barOuterWidth)/2,
(data.labels.length * options.barOuterWidth)/2
]
);
scale.x.domain(data.groups);
scale.dx.domain(data.labels);
scale.y.front.domain([0, data.maximum.front]);
scale.y.back.domain([0, data.maximum.back]);
updateScales(scale);

// Add the labels
label = canvas.selectAll('.label')
Expand Down Expand Up @@ -155,15 +166,22 @@
.enter().append('g')
.attr('class', 'bar back')
.attr('transform', function(d) {
return 'translate(' + (scale.x(d.group) + scale.dx(d.item)) + ',' + scale.y.back(d.value.back) + ')';
return 'translate(' + Math.round(scale.x(d.group) + scale.dx(d.item)) + ',' + scale.y.back(d.value.back) + ')';
})
.attr('visibility', function(d) {
return (scale.simple && !d.active) ? 'hidden' : 'visible';
});
bar.back.append('rect')
.attr('width', options.barInnerWidth)
.attr('height', function(d) {
return height - options.axisHeight - scale.y.back(d.value.back) + 1;
})
.style('fill', function(d) {
if (d.color) return d.color;
return d.active ? options.colorActive : options.colorInactive;
})
.style('fill-opacity', function(d) {
if (d.color && !d.active) return 0.3;
});

// ... front
Expand All @@ -172,28 +190,37 @@
.enter().append('g')
.attr('class', 'bar front')
.attr('transform', function(d) {
return 'translate(' + (scale.x(d.group) + scale.dx(d.item) + 1) + ',' + scale.y.front(d.value.front) + ')';
return 'translate(' + Math.round(scale.x(d.group) + scale.dx(d.item)) + ',' + scale.y.front(d.value.front) + ')';
})
.attr('visibility', function(d) {
return (scale.simple && !d.active) ? 'hidden' : 'visible';
});
bar.front.append('rect')
.attr('width', options.barInnerWidth - 2)
.attr('width', options.barInnerWidth - 1)
.attr('height', function(d) {
return height - options.axisHeight - scale.y.front(d.value.front) + 1;
})
.attr('fill-opacity', 0.0)
.attr('stroke', '#000')
.attr('stroke-width', 2);
.attr('stroke-dasharray', function(d) {
return d.active ? 'initial' : '2 2';
})
.attr('stroke-width', 1);
bar.front.each(function(d) {
if (data.maximum.front / data.groups.length < 5) {
var value = 0;
for (value = 1; value < d.value.front; ++value) {
var y = scale.y.front(value) - scale.y.front(d.value.front);
d3.select(this).append('line')
.attr('x1', 2)
.attr('x1', 0)
.attr('y1', y)
.attr('x2', options.barInnerWidth - 4)
.attr('x2', options.barInnerWidth - 1)
.attr('y2', y)
.attr('stroke-width', 2)
.attr('stroke', '#000');
.attr('stroke', '#000')
.attr('stroke-dasharray', function(d) {
return d.active ? 'initial' : '2 2';
})
.attr('stroke-width', 1);
}
}
});
Expand Down Expand Up @@ -263,7 +290,13 @@
// Resize
width = $(container).width() - margin.left - margin.right;
svg.attr('width', width + margin.left + margin.right);
scale.x.rangeRoundPoints([0, width], 1.0);
updateScales(scale);
bar.front.attr('visibility', function(d) {
return (scale.simple && !d.active) ? 'hidden' : 'visible';
});
bar.back.attr('visibility', function(d) {
return (scale.simple && !d.active) ? 'hidden' : 'visible';
});

label.attr('transform', function(d) {
return 'translate(' + scale.x(d) + ',' + height + ')';
Expand All @@ -272,10 +305,10 @@
return 'translate(' + (width - options.tickWidth) + ',0)';
});
bar.front.attr('transform', function(d) {
return 'translate(' + (scale.x(d.group) + scale.dx(d.item) + 1) + ',' + scale.y.front(d.value.front) + ')';
return 'translate(' + Math.round(scale.x(d.group) + scale.dx(d.item)) + ',' + scale.y.front(d.value.front) + ')';
});
bar.back.attr('transform', function(d) {
return 'translate(' + (scale.x(d.group) + scale.dx(d.item)) + ',' + scale.y.back(d.value.back) + ')';
return 'translate(' + Math.round(scale.x(d.group) + scale.dx(d.item)) + ',' + scale.y.back(d.value.back) + ')';
});
}
});
Expand Down
Loading

0 comments on commit 36d9975

Please sign in to comment.