Skip to content

Commit

Permalink
Completed first full version of system
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Kenny committed May 23, 2015
1 parent 78ecfb7 commit ddf5996
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 65 deletions.
115 changes: 94 additions & 21 deletions SetLayersViaVote.jsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,51 @@
// NAME:
// SaveLayers
// SetLayersViaVote

// DESCRIPTION:
// Saves each layer in the active document to a PNG or JPG file named after the layer.
// These files will be created in the current document folder.
// Sets layer opacity for Irish constituency map for vote resuts

// REQUIRES:
// Adobe Photoshop CS2 or higher

// VERSIONS:
// 27 March 2013 by Robin Parmar ([email protected])
// preferences stored in object
// auto-increment file names to prevent collisions
// properly handles layer groups
// header added
// code comments added
// main() now has error catcher
// counts number of layers
// many little code improvements

// Based on "SaveLayers" script by
// 26 Sept 2012 by Johannes on stackexchange
// original version

// This edit by Simon Kenny 23 May 2015


// enable double-clicking from Finder/Explorer (CS2 and higher)
#target photoshop
app.bringToFront();

var data = [];

function openData() {
var dataFile = new File(app.activeDocument.path + '/results.csv');
dataFile.open('r');
dataFile.readln(); // Skip first line
while (!dataFile.eof) {
var dataFileLine = dataFile.readln();
var dataFilePieces = dataFileLine.split(',');
data.push({
num: dataFilePieces[0],
name: dataFilePieces[1],
yes: dataFilePieces[2],
no: dataFilePieces[3],
boxesOpened: dataFilePieces[4],
turnOut: dataFilePieces[5],
hasData: dataFilePieces[4] > 0
});
}
dataFile.close();
}

function main() {
// two quick checks
// a quick check
if(!okDocument()) {
alert("Document must be a layered PSD.");
return;
}
var ok = confirm("This document contains " + activeDocument.layers.length + " top level layers.\nBe aware that large numbers of layers will take some time!\nContinue?");
if(!ok) return

// user preferences
prefs = new Object();
Expand All @@ -42,11 +54,70 @@ function main() {
prefs.filePath = app.activeDocument.path;
prefs.count = 0;

//instantiate dialogue
Dialog();
openData();

saveLayers(activeDocument);
alert("Saved " + prefs.count + " files.");
//saveLayers(activeDocument);
//alert("Saved " + prefs.count + " files.");
setOpacity(activeDocument);
}

var NUM_CONSTITUENCIES = 43;

var QTR_1 = 0.4;
var QTR_2 = 0.5;
var QTR_3 = 0.7;

var RED_START = QTR_1;
var RED_END = QTR_2;
var YELLOW_START = QTR_1;
var YELLOW_MID = QTR_2;
var YELLOW_END = QTR_3;
var GREEN_START = QTR_2;
var GREEN_END = QTR_3;

/*
var RED_START = 0.2
var RED_END = 0.5;
var YELLOW_START = 0.3;
var YELLOW_MID = 0.4;
var YELLOW_END = 0.7;
var GREEN_START = 0.5;
var GREEN_END = 0.7;
*/

function setOpacity(ref) {
for( var i = 0 ; i < NUM_CONSTITUENCIES ; i++ ) {
if( data[i].hasData ) {
var yes = data[i].yes;
var red = yes < RED_END ? 1 - ((yes-RED_START)*(1/(RED_END-RED_START))) : 0;
if( yes < RED_START ) {
red = 1;
}
var yellow = yes >= YELLOW_MID && yes < YELLOW_END ?
((yes-YELLOW_MID)*(1/(YELLOW_END-YELLOW_MID))) : 0;
/*
var yellow = 0;
if( yes >= YELLOW_START && yes < YELLOW_MID ) {
yellow = ((yes-YELLOW_START)*(1/(YELLOW_MID-YELLOW_START)));
} else if( yes >= YELLOW_MID && yes < YELLOW_END ) {
yellow = 1 - ((yes-YELLOW_MID)*(1/(YELLOW_END-YELLOW_MID)));
}
*/
var green = yes >= GREEN_START ? ((yes-GREEN_START)*(1/(GREEN_END-GREEN_START))) : 0;
if( yes > GREEN_END ) {
green = 1;
}
var num = i + 1;
ref.artLayers.getByName(''+(i+1)+' red').opacity = red * 100;
ref.artLayers.getByName(''+(i+1)+' yellow').opacity = yellow * 100;
//ref.artLayers.getByName(''+(i+1)+' yellow').opacity = 0;
ref.artLayers.getByName(''+(i+1)+' green').opacity = green * 100;
} else {
ref.artLayers.getByName(''+(i+1)+' red').opacity = 0;
ref.artLayers.getByName(''+(i+1)+' yellow').opacity = 0;
ref.artLayers.getByName(''+(i+1)+' green').opacity = 0;
}
}
}

function saveLayers(ref) {
Expand All @@ -60,6 +131,7 @@ function saveLayers(ref) {
// recurse if current layer is a group
saveLayers(layer);
} else {
/*
// otherwise make sure the layer is visible and save it
for(var j = 0 ; j < len ; j++ ) {
if( ref.layers[j] == layer ) {
Expand All @@ -69,6 +141,7 @@ function saveLayers(ref) {
}
}
saveImage(layer.name);
*/
}
}
}
Expand Down
Binary file not shown.
File renamed without changes.
Binary file added ireland-constituencies-for-script-with-words.psd
Binary file not shown.
Binary file added ireland-constituencies-for-script.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ireland-constituencies-for-script.psd
Binary file not shown.
File renamed without changes.
File renamed without changes
Binary file removed map/outline.png
Binary file not shown.
88 changes: 44 additions & 44 deletions results.csv
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
#,Name,Yes,No,Spoilt,Boxes opened,Turnout,,
1,Donegal North East,,,,,,,
2,Donegal South West,,,,,,,
3,Sligo-North Leitrim,,,,,,,
4,Cavan-Monaghan,,,,,,,
5,Louth,63%,37%,,?,,,
6,Meath East,,,,,,,
7,Meath West,,,,,,,
8,Longford-Westmeath,,,,,,,
9,Roscommon-South Leitrim,48%,52%,,50%,,,
10,Mayo,54%,46%,,30%,,,
11,Galway West,62%,38%,,100%,,,
12,Galway East,,,,,,,
13,Laois-Offaly,,,,,,,
14,Kildare North,,,,,,,
15,Kildare South,,,,,,,
16,Wicklow,,,,,,,
17,Carlow-Kilkenny,,,,,,,
18,Tipperary North,55%,35%,,,,,
19,Tipperary South,55%,45%,,,,,
20,Clare,58%,42%,,,,,
21,Limerick City,64%,36%,,,,,
22,Limerick,54%,46%,,,,,
23,Kerry North-West Limerick,57%,43%,,,,,
24,Kerry South,,,,,,,
25,Cork South West,,,,,,,
26,Cork North West,,,,,,,
27,Cork North Central,63%,37%,,34%,,,
28,Cork South Central,65%,35%,,96%,,,
29,Cork East,,,,,,,
30,Waterford,,,,,,,
31,Wexford,,,,,,,
32,Dublin North,71%,29%,,28%,,,
33,Dublin West,71%,29%,,100%,64%,,
34,Dublin North East,,,,,,,
35,Dublin North Central,,,,,,,
36,Dublin North West,70%,30%,,,,,
37,Dublin Central,,,,,,,
38,Dublin South East,,,,,,,
39,Dublin South Central,,,,,,,
40,Dublin Mid West,71%,29%,,100%,63%,,
41,Dublin South West,71%,29%,,89%,,,
42,Dublin South,70%,30%,,62%,,,
43,Dún Laoghaire,71%,,,89%,,,
#,Name,Yes,No,Boxes opened,Turnout
1,Donegal North East,0.5,0.5,0,0.5
2,Donegal South West,0.5,0.5,0,0.5
3,Sligo-North Leitrim,0.58,0.42,1,0.58
4,Cavan-Monaghan,0.5,0.5,0,0.5
5,Louth,0.63,0.37,0.01,0.5
6,Meath East,0.64,0.36,1,0.6
7,Meath West,0.5,0.5,0,0.5
8,Longford-Westmeath,0.54,0.46,1,0.55
9,Roscommon-South Leitrim,0.48,0.52,0.5,0.5
10,Mayo,0.54,0.46,0.3,0.5
11,Galway West,0.61,0.39,1,0.5
12,Galway East,0.53,0.47,1,0.5
13,Laois-Offaly,0.5,0.5,0,0.5
14,Kildare North,0.7,0.3,1,0.62
15,Kildare South,0.5,0.5,0,0.5
16,Wicklow,0.5,0.5,0,0.5
17,Carlow-Kilkenny,0.5,0.5,0,0.5
18,Tipperary North,0.55,0.45,0.01,0.5
19,Tipperary South,0.55,0.45,0.01,0.5
20,Clare,0.58,0.42,0.01,0.5
21,Limerick City,0.63,0.37,1,0.5
22,Limerick,0.54,0.46,1,0.5
23,Kerry North-West Limerick,0.57,0.43,0.01,0.5
24,Kerry South,0.5,0.5,0,0.5
25,Cork South West,0.5,0.5,0,0.5
26,Cork North West,0.5,0.5,0,0.5
27,Cork North Central,0.64,0.36,1,0.6
28,Cork South Central,0.65,0.35,0.96,0.5
29,Cork East,0.5,0.5,0,0.5
30,Waterford,0.5,0.5,0,0.5
31,Wexford,0.5,0.5,0,0.5
32,Dublin North,0.71,0.29,0.28,0.5
33,Dublin West,0.71,0.29,1,0.64
34,Dublin North East,0.5,0.5,0,0.5
35,Dublin North Central,0.5,0.5,0,0.5
36,Dublin North West,0.7,0.3,0.01,0.5
37,Dublin Central,0.5,0.5,0,0.5
38,Dublin South East,0.5,0.5,0,0.5
39,Dublin South Central,0.5,0.5,0,0.5
40,Dublin Mid West,0.71,0.29,1,0.63
41,Dublin South West,0.71,0.29,1,0.63
42,Dublin South,0.7,0.3,0.62,0.5
43,Dún Laoghaire,0.71,0.29,0.89,0.5
Binary file modified results.numbers
Binary file not shown.
Binary file added vote-with-names-full-size.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vote-with-names.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ddf5996

Please sign in to comment.