relation colors fix

This commit is contained in:
loro2
2019-07-29 18:02:51 +02:00
parent 2f4251354a
commit 45a439d645
4 changed files with 26 additions and 49 deletions
+2 -1
View File
@@ -11,8 +11,9 @@ var CONFIG = {
RELATION_THICKNESS: 2, RELATION_THICKNESS: 2,
RELATION_SPACING: 15, RELATION_SPACING: 15,
RELATION_COLORS: ["#000", "#800", "#080", "#008", "#088", "#808", "#088"], RELATION_COLORS: ["#000", "#800", "#080", "#008", "#088", "#808", "#088"],
STYLES: ["material-inspired", "original"], STYLES: ["material-inspired", "original"],
MATERIAL_RELATION_COLORS: ["#323232", "#F44336", "#E91E63", "#9C27B0", "#3F51B5", "#673AB7", "#2196F3", "#03A9F4", "#00BCD4", "#009688", "#4CAF50", "#8BC34A", "#CDDC39", "#FFC107", "#FF5722", "#795548", "#607D8B"],
STATIC_PATH: "", STATIC_PATH: "",
XHR_PATH: "", XHR_PATH: "",
+14 -10
View File
@@ -4,20 +4,29 @@ SQL.Relation = function(owner, row1, row2) {
this.owner = owner; this.owner = owner;
this.row1 = row1; this.row1 = row1;
this.row2 = row2; this.row2 = row2;
this.colorIndex = 0;
this.color = "#000"; this.color = "#000";
this.hidden = false; this.hidden = false;
this.relationColors = CONFIG.RELATION_COLORS;
SQL.Visual.apply(this); 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 */ /* if one of the rows already has relations, inherit color */
var all = row1.relations.concat(row2.relations); var all = row1.relations.concat(row2.relations);
if (all.length) { /* inherit */ if (all.length) { /* inherit */
this.color = all[0].getColor(); this.color = all[0].getColor();
this.colorIndex = all[0].getColorIndex(); } else if (this.relationColors) { /* pick next */
} else if (CONFIG.RELATION_COLORS) { /* pick next */
SQL.Relation._counter++; SQL.Relation._counter++;
this.colorIndex = (SQL.Relation._counter - 1) % CONFIG.RELATION_COLORS.length; var colorIndex = (SQL.Relation._counter - 1) % this.relationColors.length;
this.color = CONFIG.RELATION_COLORS[this.colorIndex]; this.color = this.relationColors[colorIndex];
} }
this.row1.addRelation(this); this.row1.addRelation(this);
@@ -27,7 +36,6 @@ SQL.Relation = function(owner, row1, row2) {
if (this.owner.vector) { if (this.owner.vector) {
var path = document.createElementNS(this.owner.svgNS, "path"); var path = document.createElementNS(this.owner.svgNS, "path");
path.setAttribute("stroke", this.color); path.setAttribute("stroke", this.color);
path.setAttribute("class", "relation_" + this.colorIndex);
path.setAttribute("stroke-width", CONFIG.RELATION_THICKNESS); path.setAttribute("stroke-width", CONFIG.RELATION_THICKNESS);
path.setAttribute("fill", "none"); path.setAttribute("fill", "none");
this.owner.dom.svg.appendChild(path); this.owner.dom.svg.appendChild(path);
@@ -54,10 +62,6 @@ SQL.Relation.prototype.getColor = function() {
return this.color; return this.color;
} }
SQL.Relation.prototype.getColorIndex = function() {
return this.colorIndex;
}
SQL.Relation.prototype.show = function() { SQL.Relation.prototype.show = function() {
this.hidden = false; this.hidden = false;
for (var i=0;i<this.dom.length;i++) { for (var i=0;i<this.dom.length;i++) {
+10 -10
View File
@@ -29,7 +29,7 @@ SQL.Designer = function() {
this.flag = 2; this.flag = 2;
this.requestLanguage(); this.requestLanguage();
this.requestDB(); this.requestDB();
this.requestStyle(); this.setStyle();
} }
SQL.Designer.prototype = Object.create(SQL.Visual.prototype); SQL.Designer.prototype = Object.create(SQL.Visual.prototype);
@@ -80,7 +80,15 @@ SQL.Designer.prototype.requestDB = function() { /* get datatypes file */
OZ.Request(url, this.dbResponse.bind(this), {method:"get", xml:true}); OZ.Request(url, this.dbResponse.bind(this), {method:"get", xml:true});
} }
SQL.Designer.prototype.requestStyle = function() { /* set style */ SQL.Designer.prototype.dbResponse = function(xmlDoc) {
if (xmlDoc) {
window.DATATYPES = xmlDoc.documentElement;
}
this.flag--;
if (!this.flag) { this.init2(); }
}
SQL.Designer.prototype.setStyle = function() { /* set style */
var style = this.getOption("style"); var style = this.getOption("style");
var i, link_elms; var i, link_elms;
for (i=0; link_elms = document.getElementsByTagName("link"); i++) { for (i=0; link_elms = document.getElementsByTagName("link"); i++) {
@@ -91,14 +99,6 @@ SQL.Designer.prototype.requestStyle = function() { /* set style */
} }
} }
SQL.Designer.prototype.dbResponse = function(xmlDoc) {
if (xmlDoc) {
window.DATATYPES = xmlDoc.documentElement;
}
this.flag--;
if (!this.flag) { this.init2(); }
}
SQL.Designer.prototype.init2 = function() { /* secondary init, after locale & datatypes were retrieved */ SQL.Designer.prototype.init2 = function() { /* secondary init, after locale & datatypes were retrieved */
this.map = new SQL.Map(this); this.map = new SQL.Map(this);
this.rubberband = new SQL.Rubberband(this); this.rubberband = new SQL.Rubberband(this);
-28
View File
@@ -584,32 +584,4 @@ select optgroup {
background: rgba(255, 64, 129, 0.5); background: rgba(255, 64, 129, 0.5);
opacity: 0.5; opacity: 0.5;
visibility: hidden; visibility: hidden;
}
.relation_0 {
stroke: #673AB7;
}
.relation_1 {
stroke: #F44336;
}
.relation_2 {
stroke: #8BC34A;
}
.relation_3 {
stroke: #00BCD4;
}
.relation_4 {
stroke: #4CAF50;
}
.relation_5 {
stroke: #FF5722;
}
.relation_6 {
stroke: #FFC107;
} }