diff -r 803dbeb7c919 -r f0873867143a client/js/paper-renderer.js --- a/client/js/paper-renderer.js Wed Feb 27 19:04:36 2013 +0100 +++ b/client/js/paper-renderer.js Thu Feb 28 19:13:08 2013 +0100 @@ -1,6 +1,6 @@ Rkns.Renderer = { - _MARGIN_X: 80, - _MARGIN_Y: 50, + _MINIMAP_MARGIN_X: 20, + _MINIMAP_MARGIN_Y: 20, _MIN_DRAG_DISTANCE: 2, _NODE_SIZE_BASE: 25, _NODE_BUTTON_WIDTH: 40, @@ -22,6 +22,8 @@ _CLICKMODE_ENDEDGE : 3, _IMAGE_MAX_KB : 500, _NODE_SIZE_STEP: Math.LN2/4, + _MINIMAP_WIDTH: 160, + _MINIMAP_HEIGHT: 120, _USER_PLACEHOLDER : { color: "#000000", title: "(unknown user)", @@ -106,6 +108,7 @@ _textX = Math.cos(_centerRads) * (_outR + 3), _textY = Math.sin(_centerRads) * (_outR + 3), _segments = []; + _repr.renderer.buttons_layer.activate(); var _path = new paper.Path(); _path.add([_startXIn, _startYIn]); _path.arcTo([_centerXIn, _centerYIn], [_endXIn, _endYIn]); @@ -261,14 +264,19 @@ } this.last_circle_radius = 1; this.title.paragraphStyle.justification = 'center'; + + this.renderer.minimap.node_layer.activate(); + this.minimap_circle = new paper.Path.Circle([0, 0], 1); + this.renderer.minimap.node_group.addChild(this.minimap_circle); } Rkns.Renderer.Node.prototype.redraw = function() { + var _model_coords = new paper.Point(this.model.get("position")), + _baseRadius = Rkns.Renderer._NODE_SIZE_BASE * Math.exp((this.model.get("size") || 0) * Rkns.Renderer._NODE_SIZE_STEP); if (!this.paper_coords) { - var _model_coords = new paper.Point(this.model.get("position")); this.paper_coords = this.renderer.toPaperCoords(_model_coords); } - this.circle_radius = Rkns.Renderer._NODE_SIZE_BASE * Math.exp((this.model.get("size") || 0) * Rkns.Renderer._NODE_SIZE_STEP) * this.renderer.scale; + this.circle_radius = _baseRadius * this.renderer.scale; if (this.last_circle_radius !== this.circle_radius) { if (!this.renderer.renkan.read_only) { this.edit_button.setSectorSize(); @@ -292,7 +300,8 @@ this.title.content = this.model.get("title") || this.renderer.renkan.translate("(untitled)"); this.title.position = this.paper_coords.add([0, this.circle_radius + 1.5 *Rkns.Renderer._NODE_FONT_SIZE]); - this.circle.strokeColor = this.model.get("color") || (this.model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color"); + var _color = this.model.get("color") || (this.model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color"); + this.circle.strokeColor = _color; this.edit_button.moveTo(this.paper_coords); this.remove_button.moveTo(this.paper_coords); this.link_button.moveTo(this.paper_coords); @@ -330,6 +339,12 @@ this.node_image.remove(); delete this.node_image; } + + this.minimap_circle.fillColor = _color; + var minipos = this.renderer.toMinimapCoords(_model_coords), + miniradius = this.renderer.minimap.scale * _baseRadius, + minisize = new paper.Size([miniradius, miniradius]); + this.minimap_circle.fitBounds(minipos.subtract(minisize), minisize.multiply(2)); Rkns._.each(this.project.get("edges").filter(function (ed) { return ((ed.to === this.model) || (ed.from === this.model));}), function(edge, index, list){ var repr = this.renderer.getRepresentationByModel(edge); @@ -366,6 +381,7 @@ if (this.renderer.renkan.read_only) { this.openEditor(); } + this.minimap_circle.fillColor = "#ff00fc"; } Rkns.Renderer.Node.prototype.unselect = function(_newTarget) { @@ -375,6 +391,7 @@ this.link_button.hide(); this.circle.strokeWidth = 2; Rkns.$('.Rk-Bin-Item').removeClass("selected"); + this.minimap_circle.fillColor = this.circle.strokeColor; } } @@ -423,6 +440,7 @@ this.link_button.destroy(); this.circle.remove(); this.title.remove(); + this.minimap_circle.remove(); if (this.node_image) { this.node_image.remove(); } @@ -918,7 +936,6 @@ Rkns.Renderer.NodeEditButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); Rkns.Renderer.NodeEditButton.prototype._init = function() { - this.renderer.buttons_layer.activate(); this.type = "Node-edit-button"; this.lastSectorInner = 0; } @@ -972,7 +989,6 @@ Rkns.Renderer.NodeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); Rkns.Renderer.NodeRemoveButton.prototype._init = function() { - this.renderer.buttons_layer.activate(); this.type = "Node-remove-button"; this.lastSectorInner = 0; } @@ -1027,7 +1043,6 @@ Rkns.Renderer.NodeLinkButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); Rkns.Renderer.NodeLinkButton.prototype._init = function() { - this.renderer.buttons_layer.activate(); this.type = "Node-link-button"; this.lastSectorInner = 0; } @@ -1075,7 +1090,6 @@ Rkns.Renderer.EdgeEditButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); Rkns.Renderer.EdgeEditButton.prototype._init = function() { - this.renderer.buttons_layer.activate(); this.type = "Edge-edit-button"; this.sector = Rkns.Renderer.Utils.sector(this, Rkns.Renderer._EDGE_BUTTON_INNER, Rkns.Renderer._EDGE_BUTTON_OUTER, - 90, 90, 1, this.renderer.renkan.static_url+'img/edit.png', this.renderer.renkan.translate("Edit")); } @@ -1118,7 +1132,6 @@ Rkns.Renderer.EdgeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); Rkns.Renderer.EdgeRemoveButton.prototype._init = function() { - this.renderer.buttons_layer.activate(); this.type = "Edge-remove-button"; this.sector = Rkns.Renderer.Utils.sector(this, Rkns.Renderer._EDGE_BUTTON_INNER, Rkns.Renderer._EDGE_BUTTON_OUTER, - 270, -90, 1, this.renderer.renkan.static_url+'img/remove.png', this.renderer.renkan.translate("Remove")); } @@ -1175,6 +1188,33 @@ this.edge_layer = new paper.Layer(); this.node_layer = new paper.Layer(); this.buttons_layer = new paper.Layer(); + + this.minimap = { + background_layer: new paper.Layer(), + node_layer: new paper.Layer(), + node_group: new paper.Group(), + size: new paper.Size( Rkns.Renderer._MINIMAP_WIDTH, Rkns.Renderer._MINIMAP_HEIGHT ) + } + + this.minimap.background_layer.activate(); + this.minimap.topleft = paper.view.bounds.bottomRight.subtract(this.minimap.size); + this.minimap.rectangle = new paper.Path.Rectangle(this.minimap.topleft.subtract([2,2]), this.minimap.size.add([4,4])); + this.minimap.rectangle.fillColor = '#ffffff'; + this.minimap.rectangle.strokeColor = '#cccccc'; + this.minimap.rectangle.strokeWidth = 4; + this.minimap.offset = new paper.Point(this.minimap.size.divide(2)); + this.minimap.scale = .25; + + this.node_layer.activate(); + this.minimap.cliprectangle = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size); + this.minimap.node_group.addChild(this.minimap.cliprectangle); + this.minimap.node_group.clipped = true; + this.minimap.miniframe = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size); + this.minimap.node_group.addChild(this.minimap.miniframe); + this.minimap.miniframe.fillColor = '#f0f0ff'; + this.minimap.miniframe.strokeColor = '#8080ff'; + this.minimap.miniframe.strokeWidth = 2; + this.bundles = []; this.click_mode = false; var _tool = new paper.Tool(), @@ -1205,29 +1245,38 @@ this.canvas_$.on("drop", function(_event) { _event.stopPropagation(); _event.preventDefault(); + if (_this.renkan.read_only) { + return; + } var res = {} Rkns._(_event.originalEvent.dataTransfer.types).each(function(t) { return res[t] = _event.originalEvent.dataTransfer.getData(t); }); var newNode = {}; + if (res["text/x-iri-source-uri"]) { + newNode.uri = res["text/x-iri-source-uri"]; + } if (res["text/plain"]) { newNode.description = res["text/plain"].replace(/[\s\n]+/gm,' ').trim(); } if (res["text/html"]) { var snippet = Rkns.$('