From 89ad08191964c0f7fcf12829d8b6d936d6538769 Mon Sep 17 00:00:00 2001 From: Oleg Sh Date: Tue, 4 May 2021 12:13:27 +0200 Subject: [PATCH] Add presets for color Add select style for all selected styles. --- lang/de/home.php | 2 + lang/el/home.php | 2 + lang/en/home.php | 2 + lang/es/home.php | 2 + lang/fr/home.php | 4 +- lang/nl/home.php | 4 +- lang/pt/home.php | 2 + lang/ru/home.php | 2 + lang/sv/home.php | 2 + script/Appilcation.js | 14 ++- script/BaseBackgroundDrawer.js | 6 + script/BaseEdgeDrawer.js | 14 ++- script/BaseVertexDrawer.js | 12 ++ script/EventHandlers.js | 197 +++++++++++++++++++++++++++++---- tpl/home.php | 34 ++++-- 15 files changed, 264 insertions(+), 35 deletions(-) diff --git a/lang/de/home.php b/lang/de/home.php index ccffd65..34ab632 100644 --- a/lang/de/home.php +++ b/lang/de/home.php @@ -202,4 +202,6 @@ $g_lang['line_style'] = "Edge style"; $g_lang['edge_width'] = "Edge width"; $g_lang['selected_index'] = "Selection group"; + + $g_lang['all'] = "All"; ?> diff --git a/lang/el/home.php b/lang/el/home.php index e7bf391..041c814 100644 --- a/lang/el/home.php +++ b/lang/el/home.php @@ -240,4 +240,6 @@ $g_lang['line_style'] = "Edge style"; $g_lang['edge_width'] = "Edge width"; $g_lang['selected_index'] = "Selection group"; + + $g_lang['all'] = "All"; ?> diff --git a/lang/en/home.php b/lang/en/home.php index 01d9d9e..c9c2065 100755 --- a/lang/en/home.php +++ b/lang/en/home.php @@ -239,4 +239,6 @@ We have added Dutch translation 🇳🇱. Thank you Willie de Wit"; $g_lang['line_style'] = "Edge style"; $g_lang['edge_width'] = "Edge width"; $g_lang['selected_index'] = "Selection group"; + + $g_lang['all'] = "All"; ?> diff --git a/lang/es/home.php b/lang/es/home.php index fee4f0a..8672aca 100755 --- a/lang/es/home.php +++ b/lang/es/home.php @@ -239,4 +239,6 @@ Tenemos traducciones en griego 🇬🇷. diff --git a/lang/fr/home.php b/lang/fr/home.php index 1870c3f..bfdb410 100644 --- a/lang/fr/home.php +++ b/lang/fr/home.php @@ -206,5 +206,7 @@ $g_lang['text_position'] = "Text position"; $g_lang['line_style'] = "Edge style"; $g_lang['edge_width'] = "Edge width"; - $g_lang['selected_index'] = "Selection group"; + $g_lang['selected_index'] = "Selection group"; + + $g_lang['all'] = "All"; ?> \ No newline at end of file diff --git a/lang/nl/home.php b/lang/nl/home.php index fc0aea0..83ddbba 100644 --- a/lang/nl/home.php +++ b/lang/nl/home.php @@ -203,5 +203,7 @@ $g_lang['text_position'] = "Text position"; $g_lang['line_style'] = "Edge style"; $g_lang['edge_width'] = "Edge width"; - $g_lang['selected_index'] = "Selection group"; + $g_lang['selected_index'] = "Selection group"; + + $g_lang['all'] = "All"; ?> diff --git a/lang/pt/home.php b/lang/pt/home.php index 4f1bbde..bc3146d 100644 --- a/lang/pt/home.php +++ b/lang/pt/home.php @@ -205,4 +205,6 @@ $g_lang['line_style'] = "Edge style"; $g_lang['edge_width'] = "Edge width"; $g_lang['selected_index'] = "Selection group"; + + $g_lang['all'] = "All"; ?> diff --git a/lang/ru/home.php b/lang/ru/home.php index ba1e24b..74c0aed 100755 --- a/lang/ru/home.php +++ b/lang/ru/home.php @@ -240,4 +240,6 @@ $g_lang['line_style'] = "Стиль дуги"; $g_lang['edge_width'] = "Толщина дуги"; $g_lang['selected_index'] = "Группа выделения"; + + $g_lang['all'] = "Все"; ?> diff --git a/lang/sv/home.php b/lang/sv/home.php index 00c6467..9f49b9d 100644 --- a/lang/sv/home.php +++ b/lang/sv/home.php @@ -201,4 +201,6 @@ $g_lang['line_style'] = "Edge style"; $g_lang['edge_width'] = "Edge width"; $g_lang['selected_index'] = "Selection group"; + + $g_lang['all'] = "All"; ?> diff --git a/script/Appilcation.js b/script/Appilcation.js index b189f63..701b916 100644 --- a/script/Appilcation.js +++ b/script/Appilcation.js @@ -1501,15 +1501,25 @@ Application.prototype.LoadUserSettings = function(json) } else { + if (!entry.deep) + entry.value.Clear(); + for(var k in parsedSave[entry.field]) { if (!entry.deep) { if (entry.value.ShouldLoad(k)) + { entry.value[k] = parsedSave[entry.field][k]; + } } else { + // Check is number or not + if (k % 1 != 0) + continue; + + entry.value[k].Clear(); for(var deepK in parsedSave[entry.field][k]) { if (k < entry.value.length && entry.value[k].ShouldLoad(deepK)) @@ -1659,7 +1669,7 @@ Application.prototype.GetStyle = function(type, styleName, object, index) } else if (styleName == "selected") { - return object !== undefined && index == 0 ? object.getStyleFor(1) : this.vertexSelectedVertexStyles[correctIndex]; + return object !== undefined && object.hasOwnStyleFor(correctIndex + 1) ? object.getStyleFor(correctIndex + 1) : this.vertexSelectedVertexStyles[correctIndex]; } else if (styleName == "printed") { @@ -1680,7 +1690,7 @@ Application.prototype.GetStyle = function(type, styleName, object, index) } else if (styleName == "selected") { - return object !== undefined && index == 0 ? object.getStyleFor(1) : this.edgeSelectedStyles[correctIndex]; + return object !== undefined && object.hasOwnStyleFor(correctIndex + 1) ? object.getStyleFor(correctIndex + 1) : this.edgeSelectedStyles[correctIndex]; } else if (styleName == "printed") { diff --git a/script/BaseBackgroundDrawer.js b/script/BaseBackgroundDrawer.js index 68decd4..e72ab9b 100644 --- a/script/BaseBackgroundDrawer.js +++ b/script/BaseBackgroundDrawer.js @@ -9,6 +9,12 @@ function CommonBackgroundStyle() this.commonOpacity = 1.0; } +CommonBackgroundStyle.prototype.Clear = function () +{ + delete this.commonColor; + delete this.commonOpacity; +} + CommonBackgroundStyle.prototype.ShouldLoad = function (field) { return true; diff --git a/script/BaseEdgeDrawer.js b/script/BaseEdgeDrawer.js index 154ce2e..ddeabff 100644 --- a/script/BaseEdgeDrawer.js +++ b/script/BaseEdgeDrawer.js @@ -45,7 +45,19 @@ const WeightTextCenter = 0, return baseStyle; } - + + BaseEdgeStyle.prototype.Clear = function () + { + delete this.weightText; + delete this.strokeStyle; + delete this.fillStyle; + delete this.textPadding; + delete this.textStrockeWidth; + delete this.lineDash; + delete this.additionalTextColor; + delete this.weightPosition; + } + BaseEdgeStyle.prototype.ShouldLoad = function (field) { return field != "baseStyles"; diff --git a/script/BaseVertexDrawer.js b/script/BaseVertexDrawer.js index b869252..6c0a888 100644 --- a/script/BaseVertexDrawer.js +++ b/script/BaseVertexDrawer.js @@ -115,6 +115,18 @@ BaseVertexStyle.prototype.GetStyle = function (baseStyle, object) return baseStyle; } +BaseVertexStyle.prototype.Clear = function () +{ + delete this.lineWidth; + delete this.strokeStyle; + delete this.fillStyle; + delete this.mainTextColor; + delete this.shape; + delete this.upTextColor; + delete this.commonTextPosition; + delete this.lineWidth; +} + BaseVertexStyle.prototype.ShouldLoad = function (field) { return field != "baseStyles"; diff --git a/script/EventHandlers.js b/script/EventHandlers.js index f6efc8f..d09269e 100644 --- a/script/EventHandlers.js +++ b/script/EventHandlers.js @@ -1418,7 +1418,7 @@ SetupVertexStyle.prototype.show = function(index, selectedVertexes) $( "#vertexSize" ).val(forAll ? app.GetDefaultVertexSize() : selectedVertexes[0].model.diameter); $( "#commonTextPosition" ).val(fullStyle.commonTextPosition); - if (self.index > 0) + if (self.index > 0 || self.index == "all") { $( "#VertexSelectedIndexForm" ).show(); $( "#vertexSelectedIndex" ).val(self.index); @@ -1426,7 +1426,40 @@ SetupVertexStyle.prototype.show = function(index, selectedVertexes) else { $( "#VertexSelectedIndexForm" ).hide(); - } + } + + // Fill color presets. + var stylesArray = []; + stylesArray.push(app.vertexCommonStyle); + + for (i = 0; i < app.vertexSelectedVertexStyles.length; i ++) + stylesArray.push(app.vertexSelectedVertexStyles[i]); + + var colorSet = {}; + for (i = 0; i < stylesArray.length; i ++) + { + var style = stylesArray[i]; + if (style.hasOwnProperty('strokeStyle')) + colorSet[style.strokeStyle] = 1; + if (style.hasOwnProperty('fillStyle')) + colorSet[style.fillStyle] = 1; + if (style.hasOwnProperty('mainTextColor')) + colorSet[style.mainTextColor] = 1; + if (style.hasOwnProperty('upTextColor')) + colorSet[style.upTextColor] = 1; + } + + $("#vertexFillColorPreset").find('option').remove(); + $("#upVertexTextColorPreset").find('option').remove(); + $("#vertexTextColorPreset").find('option').remove(); + $("#vertexStrokeColorPreset").find('option').remove(); + for (const property in colorSet) + { + $("#vertexFillColorPreset").append(new Option(property)); + $("#upVertexTextColorPreset").append(new Option(property)); + $("#vertexTextColorPreset").append(new Option(property)); + $("#vertexStrokeColorPreset").append(new Option(property)); + } } var redrawVertex = function() @@ -1480,10 +1513,20 @@ SetupVertexStyle.prototype.show = function(index, selectedVertexes) var changeIndex = function() { - var index = parseInt($( "#vertexSelectedIndex" ).val()); - this.index = index; - applyIndex(index); - fillFields(); + var val = $( "#vertexSelectedIndex" ).val(); + if (val == "all") + { + applyIndex(1); + self.index = "all"; + fillFields(); + } + else + { + var index = parseInt(val); + self.index = index; + applyIndex(index); + fillFields(); + } redrawVertex(); } @@ -1509,14 +1552,28 @@ SetupVertexStyle.prototype.show = function(index, selectedVertexes) applyDiameter(forAll ? (new VertexModel()).diameter : app.GetDefaultVertexSize()); + var indexes = []; + if (self.index == "all") + { + for (i = 0; i < app.vertexSelectedVertexStyles.length; i ++) + indexes.push(i + 1); + } + else + indexes.push(self.index); + + if (forAll) { - app.ResetVertexStyle(self.index); + indexes.forEach(function(index) { + app.ResetVertexStyle(index); + }); } else { selectedVertexes.forEach(function(vertex) { - vertex.resetOwnStyle(self.index); + indexes.forEach(function(index) { + vertex.resetOwnStyle(index); + }); }); } app.redrawGraph(); @@ -1528,16 +1585,37 @@ SetupVertexStyle.prototype.show = function(index, selectedVertexes) applyDiameter(parseInt($( "#vertexSize" ).val())); + var indexes = []; + if (self.index == "all") + { + indexes.push({index : 1, style : self.style}); + for (i = 1; i < app.vertexSelectedVertexStyles.length; i ++) + { + var style = (new BaseVertexStyle()); + style.baseStyles.push("selected"); + indexes.push({index : i + 1, style : style}); + } + + self.style.baseStyles = []; + self.style.baseStyles = self.style.baseStyles.concat((new SelectedVertexStyle0()).baseStyles); + } + else + indexes.push({index : self.index, style : self.style}); + if (forAll) { - app.SetVertexStyle(self.index, self.style); + indexes.forEach(function(index) { + app.SetVertexStyle(index.index, index.style); + }); } else { if (JSON.stringify(self.originStyle) !== JSON.stringify(self.style)) { selectedVertexes.forEach(function(vertex) { - vertex.setOwnStyle(self.index, self.style); + indexes.forEach(function(index) { + vertex.setOwnStyle(index.index, index.style); + }); }); } } @@ -1633,7 +1711,7 @@ SetupEdgeStyle.prototype.show = function(index, selectedEdges) $( "#weightEdgeTextColor" ).val(fullStyle.additionalTextColor); $( "#weightTextPosition" ).val(fullStyle.weightPosition); - if (self.index > 0) + if (self.index > 0 || self.index == "all") { $( "#EdgeSelectedIndexForm" ).show(); $( "#edgeSelectedIndex" ).val(self.index); @@ -1642,6 +1720,37 @@ SetupEdgeStyle.prototype.show = function(index, selectedEdges) { $( "#EdgeSelectedIndexForm" ).hide(); } + + // Fill color presets. + var stylesArray = []; + stylesArray.push(app.edgeCommonStyle); + + for (i = 0; i < app.edgeSelectedStyles.length; i ++) + stylesArray.push(app.edgeSelectedStyles[i]); + + var colorSet = {}; + for (i = 0; i < stylesArray.length; i ++) + { + var style = stylesArray[i]; + if (style.hasOwnProperty('strokeStyle')) + colorSet[style.strokeStyle] = 1; + if (style.hasOwnProperty('fillStyle')) + colorSet[style.fillStyle] = 1; + if (style.hasOwnProperty('additionalTextColor')) + colorSet[style.additionalTextColor] = 1; + } + + $("#edgeFillColorPreset").find('option').remove(); + $("#weightEdgeTextColorPreset").find('option').remove(); + $("#edgeTextColorPreset").find('option').remove(); + $("#edgeStrokeColorPreset").find('option').remove(); + for (const property in colorSet) + { + $("#edgeFillColorPreset").append(new Option(property)); + $("#weightEdgeTextColorPreset").append(new Option(property)); + $("#edgeTextColorPreset").append(new Option(property)); + $("#edgeStrokeColorPreset").append(new Option(property)); + } } var redrawVertex = function() @@ -1697,10 +1806,21 @@ SetupEdgeStyle.prototype.show = function(index, selectedEdges) var changeIndex = function() { - var index = parseInt($( "#edgeSelectedIndex" ).val()); - this.index = index; - applyIndex(index); - fillFields(); + var val = $( "#edgeSelectedIndex" ).val(); + if (val == "all") + { + applyIndex(1); + self.index = "all"; + fillFields(); + } + else + { + var index = parseInt(val); + self.index = index; + applyIndex(index); + fillFields(); + } + redrawVertex(); } @@ -1723,17 +1843,28 @@ SetupEdgeStyle.prototype.show = function(index, selectedEdges) text : g_default, class : "MarginLeft", click : function() { - applyWidth(forAll ? (new EdgeModel()).width : app.GetDefaultEdgeWidth()); + var indexes = []; + if (self.index == "all") + { + for (i = 0; i < app.edgeSelectedStyles.length; i ++) + indexes.push(i + 1); + } + else + indexes.push(self.index); if (forAll) - { - app.ResetEdgeStyle(self.index); + { + indexes.forEach(function(index) { + app.ResetEdgeStyle(index); + }); } else { selectedEdges.forEach(function(edge) { - edge.resetOwnStyle(self.index); + indexes.forEach(function(index) { + edge.resetOwnStyle(index); + }); }); } @@ -1746,15 +1877,37 @@ SetupEdgeStyle.prototype.show = function(index, selectedEdges) applyWidth(parseInt($( "#edgeWidth" ).val())); + var indexes = []; + if (self.index == "all") + { + indexes.push({index : 1, style : self.style}); + + for (i = 1; i < app.edgeSelectedStyles.length; i ++) + { + var style = (new BaseEdgeStyle()); + style.baseStyles.push("selected"); + indexes.push({index : i + 1, style : style}); + } + + self.style.baseStyles = []; + self.style.baseStyles = self.style.baseStyles.concat((new SelectedEdgeStyle0()).baseStyles); + } + else + indexes.push({index : self.index, style : self.style}); + if (forAll) { - app.SetEdgeStyle(self.index, self.style); + indexes.forEach(function(index) { + app.SetEdgeStyle(index.index, index.style); + }); } else { selectedEdges.forEach(function(edge) { - edge.setOwnStyle(self.index, self.style); - }); + indexes.forEach(function(index) { + edge.setOwnStyle(index.index, index.style); + }); + }); } app.redrawGraph(); $( this ).dialog( "close" ); diff --git a/tpl/home.php b/tpl/home.php index 3fec00f..a1011fb 100755 --- a/tpl/home.php +++ b/tpl/home.php @@ -399,13 +399,17 @@
- + + +
- + + +
@@ -417,13 +421,17 @@
- + + +
- + + +
@@ -461,6 +469,7 @@ +
@@ -476,19 +485,25 @@
- + + +
- + + +
- + + +
@@ -503,7 +518,9 @@
- + + +
@@ -532,6 +549,7 @@ +