/* --------------------------- relation (connector) ----------- */ SQL.Relation = function(owner, row1, row2) { this.owner = owner; this.row1 = row1; this.row2 = row2; this.color = "#000"; this.hidden = false; this.relationColors = CONFIG.RELATION_COLORS; this.highlighted = null; SQL.Visual.apply(this); this.style = SQL.Designer.getOption("style"); switch (this.style) { case "material-inspired": this.relationColors = CONFIG.MATERIAL_RELATION_COLORS; break; case "original": default: this.relationColors = CONFIG.RELATION_COLORS; } /* if one of the rows already has relations, inherit color */ var all = row1.relations.concat(row2.relations); if (all.length) { /* inherit */ this.color = all[0].getColor(); } else if (this.relationColors) { /* pick next */ SQL.Relation._counter++; var colorIndex = (SQL.Relation._counter - 1) % this.relationColors.length; this.color = this.relationColors[colorIndex]; } this.row1.addRelation(this); this.row2.addRelation(this); this.dom = []; if (this.owner.vector) { var path = document.createElementNS(this.owner.svgNS, "path"); path.setAttribute("stroke", this.color); path.setAttribute("stroke-width", CONFIG.RELATION_THICKNESS); path.setAttribute("fill", "none"); this.owner.dom.svg.appendChild(path); this.dom.push(path); } else { for (var i=0;i<3;i++) { var div = OZ.DOM.elm("div",{position:"absolute",className:"relation",backgroundColor:this.color}); this.dom.push(div); if (i & 1) { /* middle */ OZ.Style.set(div, {width:CONFIG.RELATION_THICKNESS+"px"}); } else { /* first & last */ OZ.Style.set(div, {height:CONFIG.RELATION_THICKNESS+"px"}); } this.owner.dom.container.appendChild(div); } } this.redraw(); } SQL.Relation._counter = 0; SQL.Relation.prototype = Object.create(SQL.Visual.prototype); SQL.Relation.prototype.getColor = function() { return this.color; } SQL.Relation.prototype.highlight = function() { if (this.highlighted) { return; } this.highlighted = true; this.dom[0].setAttribute("stroke", CONFIG.RELATION_HIGHLIGHTED_COLOR); this.dom[0].setAttribute("stroke-width", CONFIG.RELATION_HIGHLIGHTED_THICKNESS); this.redraw(); } SQL.Relation.prototype.dehighlight = function() { if (!this.highlighted) { return; } this.highlighted = false; this.dom[0].setAttribute("stroke", this.color); this.dom[0].setAttribute("stroke-width", CONFIG.RELATION_THICKNESS); this.redraw(); } SQL.Relation.prototype.show = function() { this.hidden = false; for (var i=0;i