class deweyItem extends SimpleMapItem { deweyModel parent; String name; int dewey; int amount; int rank; float curP,prevP; color c; float boxLeft, boxTop; float boxRight, boxBottom; public deweyItem(){ } public deweyItem(deweyModel parent,int dewey,int amount, int rank, float curP, float prevP) { this.parent = parent; this.dewey = dewey; this.curP = curP; this.prevP = prevP; this.amount = amount; this.rank = rank; if(curP - prevP <= 0){ negChangePercent.add((prevP - curP) / prevP); }else{ if(prevP == 0){} //posChangePercent.add(10); else posChangePercent.add((curP - prevP) / prevP); } this.name = deweyItemName[dewey]; } void updateColors() { if (parent != null) { if(curP - prevP <= 0){ //int r = (int)(negChangePercent.percentile((prevP - curP) / prevP) * 204); c = lerpColor(downColor,0,negChangePercent.percentile((prevP - curP) / prevP)); }else{ if(prevP == 0) c = upColor; else c = lerpColor(0,upColor,posChangePercent.percentile((curP - prevP) / prevP)); //c = color(0,(int)(posChangePercent.percentile((curP - prevP) / prevP) * 204),0); } } } void calcBox() { boxLeft = zoomBounds.spanX(x, startX, endX); boxRight = zoomBounds.spanX(x+w, startX, endX); boxTop = zoomBounds.spanY(y, startY, endY); boxBottom = zoomBounds.spanY(y+h, startY, endY); } void draw(){ calcBox(); stroke(204); strokeWeight(0.5); fill(c); rect(boxLeft, boxTop, boxRight, boxBottom); if (mouseInside()) { rolloverItem = this; } if(rank < 10 && highlight){ noFill(); stroke(0,0,255); strokeWeight(3); rect(boxLeft+2, boxTop+2, boxRight-2, boxBottom-2); } } void highlightSameColor(color cs){ float cr = red(c),cg = green(c),cb = blue(c); float csr = red(cs),csg = green(cs),csb = blue(cs); double dif = sqrt(sq(cr - csr) + sq(cg - csg) + sq(cb - csb)); if(dif < 5 && boxRight <= endX){ stroke(255,255,0); strokeWeight(2); noFill(); rect(boxLeft, boxTop, boxRight, boxBottom); } } void drawTag(){ stroke(255,220,0); noFill(); strokeWeight(1); rect(boxLeft, boxTop, boxRight, boxBottom); stroke(128); strokeWeight(2); fill(180); textFont(tagfont); String tag = name + "\n" + "Checkout: " + (int)size; if(mouseX + textWidth(tag) + 16 < endX){ rect(mouseX,mouseY - 36,mouseX + textWidth(tag) + 16,mouseY); fill(0); text(tag,mouseX + 8,mouseY-24); }else{ rect(mouseX - textWidth(tag) - 16,mouseY - 36,mouseX,mouseY); fill(0); text(tag,mouseX - textWidth(tag) - 8,mouseY-24); } } boolean mouseInside() { return (mouseX > startX && mouseX < endX && mouseY > startY && mouseX > boxLeft && mouseX < boxRight && mouseY > boxTop && mouseY < boxBottom); } boolean mousePressed() { if (mouseInside()) { if (mouseButton == LEFT) { parent.zoomIn(); parent.showContents(); return true; } else if (mouseButton == RIGHT) { if(parent == zoomItem) { parent.zoomOut(); } else { parent.hideContents(); } return true; } } return false; } }