class DeweyL1 extends DeweyL2 implements MapModel { MapLayout algorithm = new PivotBySplitSize(); Mappable[] items; boolean contentsVisible; boolean contentsVisibleOld; boolean layoutValid; float darkness; public DeweyL1(DeweyL1 parent, String id, String name, int level, int country, int cIdx) { super(parent, id, name, level, country, cIdx); } void updateColors() { super.updateColors(); for (int i = 0; i < items.length; i++) { DeweyL2 di = (DeweyL2) items[i]; di.updateColors(); } } void checkLayout() { if (!layoutValid) { if (getItemCount() != 0) { algorithm.layout(this, bounds); } layoutValid = true; } } boolean mousePressed() { if (mouseInside()) { if (contentsVisible) { // Pass the mouse press to the child items for (int i = 0; i < items.length; i++) { DeweyL2 di = (DeweyL2) items[i]; if (di.mousePressed()) { return true; } } } else { // not opened if (mouseButton == LEFT) { if (parent == countries[country].zoomItem) { showContents(); } else { parent.zoomIn(); } } else if (mouseButton == RIGHT) { if (parent == countries[country].zoomItem) { parent.zoomOut(); } else { parent.hideContents(); } } return true; } } return false; } // Zoom to the parent's boundary, zooming out from this item void zoomOut() { if (parent != null) { // Close contents of any opened children for (int i = 0; i < items.length; i++) { if (items[i] instanceof DeweyL1) { ((DeweyL1)items[i]).hideContents(); } } parent.zoomIn(); } if(parent!=null) { Mappable[] neighbors = countries[country].rootItem.items; for (int i = 0; i < neighbors.length; i++) { DeweyL1 itemL1 = (DeweyL1) neighbors[i]; DeweyL2 itemL2 = (DeweyL2) neighbors[i]; if(itemL1.contentsVisibleOld) itemL1.showContents(); // recall contents visible itemL2.active = true; } } } void zoomIn() { if(parent!=null) { Mappable[] neighbors = countries[country].rootItem.items; for (int i = 0; i < neighbors.length; i++) { DeweyL1 itemL1 = (DeweyL1) neighbors[i]; DeweyL2 itemL2 = (DeweyL2) neighbors[i]; itemL1.contentsVisibleOld = itemL1.contentsVisible; // remind contents visible itemL1.hideContents(); itemL2.active = false; } showContents(); } countries[country].zoomItem = this; countries[country].zoomBounds.target(x, y, w, h); ///width, h/height); } void showContents() { contentsVisible = true; } void hideContents() { // Prevent the user from closing the root level if (parent != null) { contentsVisible = false; } } void draw() { // doesnt work yet /* for(int i = 0; i < countries[country].enabled.length; i++) { if(!countries[country].enabled[i]) { println("."); oldSize = getSize(); setSize(0); } else if( countries[country].enabled[i] && oldSize != getSize() ) { println(","); setSize(oldSize); } }*/ checkLayout(); calcBox(); if (contentsVisible) { for (int i = 0; i < items.length; i++) { items[i].draw(); } } else { super.draw(); } if (contentsVisible) { if (mouseInside()) { if (parent == countries[country].zoomItem) { countries[country].taggedItem = this; } } } if (mouseInside()) { //darkness *= 0.05; } else { //darkness += (30 - darkness) * 0.20; } if (parent == countries[country].zoomItem) { colorMode(RGB, 255); fill(0, darkness); stroke(255,255); strokeWeight(1); rect(boxLeft, boxTop, boxRight, boxBottom); noStroke(); } } void drawTitle() { if (!contentsVisible) { super.drawTitle(); } } void drawTag() { float boxHeight = textAscent() + textPadding*2; if (boxBottom - boxTop > boxHeight*2) { // if the height of the box is at least twice the height of the tag, // draw the tag inside the box itself fill(0, 128); rect(boxLeft, boxTop, boxRight, boxTop+boxHeight); fill(255); textAlign(LEFT, TOP); text(name, boxLeft+textPadding, boxTop+textPadding); } else if (boxTop > boxHeight) { // if there's enough room to draw above, draw it there fill(0, 128); rect(boxLeft, boxTop-boxHeight, boxRight, boxTop); fill(255); text(name, boxLeft+textPadding, boxTop-textPadding); } else if (boxBottom + boxHeight < height) { // otherwise draw the tag below fill(0, 128); rect(boxLeft, boxBottom, boxRight, boxBottom+boxHeight); fill(255); textAlign(LEFT, TOP); text(name, boxLeft+textPadding, boxBottom+textPadding); } } Mappable[] getItems() { return items; } int getItemCount() { return items.length; } } // MapLayout algorithm = new SliceLayout(); // MapLayout algorithm = new StripTreemap(); // MapLayout algorithm = new SquarifiedLayout(); // MapLayout algorithm = new PivotBySplitSize(); // MapLayout algorithm = new PivotBySize(); // MapLayout algorithm = new PivotByMiddle(); // MapLayout algorithm = new OrderedTreemap(); // MapLayout algorithm = new BinaryTreeLayout();