hi,
I got this data (this is all the data btw),
Quote:IT 2006 2007 233 11 234 18 232 18 233 16
IT 2007 2008 240 14 239 16 250 16 229 14
IT 2008 2009 250 10 247 12 244 14 247 8
ENG 2006 2007 234 15 233 17 231 19 233 20
ENG 2007 2008 240 8 250 10 260 17 252 21
ENG 2008 2009 235 6 240 10 232 16 235 17
NL 2006 2007 200 11 222 13 244 19 222 14
NL 2007 2008 220 9 232 19 219 14 231 11
NL 2008 2009 242 10 232 10 188 10 208 10
SPA 2006 2007 264 10 230 17 260 12 299 19
SPA 2007 2008 263 13 230 22 250 22 309 19
SPA 2008 2009 275 11 250 18 275 17 300 16
It's about football stats and goes like:
country - start season - end season - goals trimester 1 - penaltys trimester 1 - goals trimester 2 - penaltys trimester 2 - goals trimester 3 - penaltys trimester 3 - goals trimester 4 - penaltys trimester 4
I want to visualize the data like this:
So in the scrollbar you start by 2006 and go threw each trimester and every season.
To work with the data i use this:
Code:
Record[] records;
void setup(){
String[] lines = loadStrings("data_voetbal2.txt");
records = new Record[lines.length];
for (int i = 0; i < lines.length; i++) {
String[] pieces = split(lines[i], '\t'); // Load data into array
if (pieces.length == 11) {
records[recordCount] = new Record(pieces);
recordCount++;
}
}
}
class Record {
String land;
int seizoen_s, seizoen_e;//start end
int k1_g, k1_p, k2_g, k2_p, k3_g, k3_p, k4_g, k4_p;
public Record(String[] pieces) {
land = pieces[0];
seizoen_s = int(pieces[1]);//start season
seizoen_e = int(pieces[2]);//end season
k1_g = int(pieces[3]);//goals trimester 1
k1_p = int(pieces[4]);//penaltys trimester 1
k2_g = int(pieces[5]);//goals trimester 2
k2_p = int(pieces[6]);//penaltys trimester 2
k3_g = int(pieces[7]);//goals trimester 3
k3_p = int(pieces[8]);//penaltys trimester 3
k4_g = int(pieces[9]);//goals trimester 4
k4_p = int(pieces[10]);//penaltys trimester 4
}
}
My problem is how can i use a scrollbar for this way.
I use the scrollbar code from the blue processing book.
Only this one goes smooth and not in steps like 20 pixel shifts.
Also how can i use it with the data, the data can be stored different if needed btw.
I will put all my code i got this far in the next post maybe it helps.
Code:Scrollbar bar1;
void setup() {
bar1 = new Scrollbar(10, height-30, 700, 10, 0.0, 100.0);
}
void draw(){
bar1.update(mouseX, mouseY);
bar1.display();
}
void mousePressed() {
bar1.press(mouseX, mouseY);
}
void mouseReleased() {
bar1.release();
}
Code:class Scrollbar {
int x, y; // The x- and y-coordinates
float sw, sh; // Width and height of scrollbar
float pos; // Position of thumb
float posMin, posMax; // Max and min values of thumb
boolean rollover; // True when the mouse is over
boolean locked; // True when its the active scrollbar
float minVal, maxVal; // Min and max values for the thumb
Scrollbar(int xp, int yp, int w, int h, float miv, float mav) {
x = xp;
y = yp;
sw = w;
sh = h;
minVal = miv;
maxVal = mav;
pos = x + sw / 2 - sh / 2;
posMin = x;
posMax = x + sw - sh;
}
// Updates the over boolean and the position of the thumb
void update(int mx, int my) {
if (over(mx, my) == true) {
rollover = true;
} else {
rollover = false;
}
if (locked == true) {
pos = constrain(mx - sh / 2, posMin, posMax);
}
}
// Locks the thumb so the mouse can move off and still update
void press(int mx, int my) {
if (rollover == true) {
locked = true;
} else {
locked = false;
}
}
// Resets the scrollbar to neutral
void release() {
locked = false;
}
// Returns true if the cursor is over the scrollbar
boolean over(int mx, int my) {
if ((mx > x) && (mx < x + sw) && (my > y) && (my < y + sh)) {
return true;
} else {
return false;
}
}
// Draws the scrollbar to the screen
void display() {
fill(255);
rect(x, y, sw, sh);
if ((rollover == true) || (locked == true)) {
fill(0);
} else {
fill(102);
}
rect(pos, y, sh, sh);
}
// Returns the current value of the thumb
float getPos() {
float scalar = sw / (sw - sh);
float ratio = (pos - x) * scalar;
float offset = minVal + (ratio / sw * (maxVal - minVal));
return offset;
}
}