-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transaction.pde
128 lines (111 loc) · 4.17 KB
/
Transaction.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
public class Transaction {
int year;
String countryName;
Country country;
float amount;
String unAgencyAbbrev;
Agency agency;
boolean hover; // mouse is hovering over
boolean highlight; // change display to be the highlight mode.
// Style Info
// Normal, Faded, Highlight
color transLineClr, transMarkerClr;
float transStrokeWeight;
float transAlphaVal;
PVector agencyLoc, amountLoc, countryLoc; // make getters/setters for these
PVector agencyLocTarg, amountLocTarg, countryLocTarg; // make getters/setters for these
public Transaction (int _year, String _cName, float _amt, String _unAgencyAbbrev) {
year = _year;
countryName = _cName;
amount = _amt;
unAgencyAbbrev = _unAgencyAbbrev;
agencyLoc = new PVector();
amountLoc = new PVector();
countryLoc = new PVector();
agencyLocTarg = new PVector();
amountLocTarg = new PVector();
countryLocTarg = new PVector();
// Set to normal vals
transLineClr = color(0);
transMarkerClr =color(0);
transAlphaVal = powMap((int)amount, Math.E, transactionMax, transactionMin, 255, 47);
transStrokeWeight = .33;
hover = false;
highlight = false;
}
void resetHoverHighlight() { // feels a little hacky but lets get it working first and see.
hover = false;
highlight = false;
}
void checkHover() {
// println("Check Hover For Transaction: "+ countryName + ", " + unAgencyAbbrev + ", " + amount);
if ( ( abs(amountLoc.x - mouseX) < 150) && (abs(amountLoc.y - mouseY) < 3)) { // change this hover area to be wider but short like 50px and 2px
hover = true;
highlight = true;
univHover = true;
// set related Agency and Country objects to highlight = true;
// println("country: " + country.countryName);
country.highlight = true;
// println("unAgencyAbbrev: " + unAgencyAbbrev);
// println("agency: " + agency.agencyName);
agency.highlight = true;
} else {
hover = false;
}
}
void updateStyle() {
if (univHover) { // if true, then set this object to either highlighted or faded style
if (hover || highlight) { // true, highlighted style
transLineClr = unBlueClr;
transMarkerClr = unBlueClr;
transAlphaVal = 255;
transStrokeWeight = 1;
} else { // false, fade style
transLineClr = color(0);
transMarkerClr =color(0);
transAlphaVal = 29;
transStrokeWeight = .29;
}
} else { // false, default style
transLineClr = color(0);
transMarkerClr =color(0);
transAlphaVal = powMap((int)amount, Math.E, transactionMax, transactionMin, 255, 47);
transStrokeWeight = .33;
}
}
void update() {
// agencyLoc = agency.currLoc; // don't think I need these, just reference the object directly
// countryLoc = country.currLoc;
amountLoc.x = fundingAxis1.x;
if (fundingScaleLinLog) {
amountLoc.y = map(amount, fundingAxisMax, fundingAxisMin, fundingAxis1.y, fundingAxis2.y); // change transactionMax to funding order of magnitude max.
} else {
// amountLoc.y = powMap((int)amount, fundingAxisLogBase, fundingAxisMax, fundingAxisMin, fundingAxis1.y, fundingAxis2.y);
amountLoc.y = map(log(amount), log(pow(10, 9)), 0, fundingAxis1.y, fundingAxis2.y);
}
}
void render() {
noFill();
stroke(transLineClr, transAlphaVal);
strokeWeight(transStrokeWeight);
curveTightness(.5);
beginShape();
curveVertex(agency.currLoc.x, agency.currLoc.y+750); // first control point
curveVertex(agency.currLoc.x, agency.currLoc.y); // also the first data point
curveVertex(amountLoc.x, amountLoc.y);
curveVertex(country.currLoc.x, country.currLoc.y);
curveVertex(country.currLoc.x+1000, country.currLoc.y-500); // ending control point
endShape();
if (hover) {
fill(unBlueClr);
// rect(amountLoc.x, amountLoc.y, 10, 10); // testing idea to show vertical $ range of mouseover
}
}
void setTransactionCountry() {
country = findCountryByName(countryName);
}
void setTransactionAgency() {
agency = findAgencyByUnAbbrev(unAgencyAbbrev);
if(agency == null) println("error seeting agency for abbrev: "+unAgencyAbbrev);
}
}