TiledViz
Loading...
Searching...
No Matches
Stickers.js
1
4$(document).ready( function (){
5
6 ListSymbols=["&#x2295","&#x2296","&#x2297","&#x2298","&#x2299","&#x229a","&#x229b","&#x229c","&#x229d",
7 "&#x2460","&#x2460","&#x2461","&#x2462","&#x2463","&#x2464","&#x2465","&#x2466","&#x2467","&#x2468","&#x2469",
8 "&#x2660","&#x2660","&#x2661","&#x2662","&#x2663","&#x2664","&#x2665","&#x2666","&#x2667"]
9
10 rgbFromStr = function (rgbStr) {
11 return Array.from(rgbStr.replace("rgb(","").replace(")","").split(','), x => parseInt(x))
12 }
13
14 ColorSticker = function(k, floatingTag) {
15 if ( typeof(floatingTag) != "undefined" ) {
16 var val=parseFloat(floatingTag["val"]);
17 var m = parseFloat(floatingTag["m"]);
18 var M = parseFloat(floatingTag["M"]);
19 if ( k < ListSymbols.length ) {
20 var symb=ListSymbols[k]
21 } else {
22 var symb=""
23 }
24
25 if ( k<colorTagStickersTab.length-1 ) {
26 var cm=getRGBColor(colorTagStickersTab[k]);
27 var cM=getRGBColor(colorTagStickersTab[colorTagStickersTab.length-k+1]);
28
29 cval=InterpolColor(m,val,M,cm,cM)
30 } else if (k<(colorTagStickersTab.length + colorFilterStickersTab.length - 1 )) {
31 var cm=getRGBColor(colorFilterStickersTab[k -colorTagStickersTab.length]);
32 var cM=getRGBColor(colorFilterStickersTab[colorTagStickersTab.length + colorFilterStickersTab.length - k+1]);
33
34 cval=InterpolColor(m,val,M,cm,cM)
35 }
36 return {"cm":"rgb("+cm[0]+","+cm[1]+","+cm[2]+")",
37 "cval":"rgb("+cval[0]+","+cval[1]+","+cval[2]+")",
38 "cM":"rgb("+cM[0]+","+cM[1]+","+cM[2]+")",
39 "symb": symb}
40 } else if (k<colorTagStickersTab.length) {
41 return colorTagStickersTab[k];
42 } else if (k<(colorTagStickersTab.length + colorFilterStickersTab.length)) {
43 return colorFilterStickersTab[k-colorTagStickersTab.length];
44 } else {
45 return "rgb("+Math.floor(Math.random()*255) + ", " + Math.floor(Math.random()*255)+ ", " + Math.floor(Math.random()*255)+")";
46 }
47 };
48
49 newTag_conformance = function(tmpNewTag) {
50 tmpNewTag = tmpNewTag.replace(/\s[+]\s/g, "_and_");
51 var forbiddenCharacters = ["'", "(", ")", " + ", " ", ".", ",", '"', "@", "+", "/", "*", "=", "%", ":", "__"]; // TO DO: create a function, to also use with the filters?
52 var replacementCharacters = ["", "", "", "_and_","_", "_", "_", "", "_at_", "_", "_", "_", "_", "_", "", "_"];
53
54 for(var i=0; i<forbiddenCharacters.length; i++) {
55 while($.inArray(forbiddenCharacters[i], tmpNewTag)!=-1) {
56 tmpNewTag = tmpNewTag.replace(forbiddenCharacters[i],replacementCharacters[i]);
57 }
58 }
59 tmpNewTag = tmpNewTag.replace(/_+$/g, ""); // Trailing underscores
60 tmpNewTag = tmpNewTag.replace(/_+/g, "_"); // Multiple underscores
61 return tmpNewTag;
62 };
63
64 Stickers = function(id, htmlSupport) {
65
66 var numOfTags = 0;
67 var nodeId=id;
68
69 $('#'+id).append("<div id=stickers_"+ id +" class=stickers_zone></div>");
70
71 $('#stickers_'+id).css({
72 position : "absolute",
73 //position : "fixed",
74 top : 0,
75 left : parseInt($('#'+id).css("width")),
76 width : 50,
77 height : parseInt($('#'+id).css("height")),
78 zIndex : 110,
79
80 });
81
82 getStickers = function() {
83 return this;
84 }
85
86 this.getNodeId = function() {
87 return nodeId;
88 }
89
90 var stickerTab = [];
91 this.getStickerTab = function() {
92 return stickerTab.toString();
93 }
94 this.resetStickerTab = function() {
95 $('#stickers_'+id).children(".sticker").remove();
96 return stickerTab = [];
97 }
98
99 this.updateStickers = function(reset) {
100 if (typeof(reset) != "undefined")
101 $('#stickers_'+id).children(".sticker").remove();
102
103 //console.log("updating stickers");
104 var it = $('#stickers_'+id).children(".sticker").length;
105 while (it < stickerTab.length) {
106 var thisstickerTab=stickerTab[it];
107
108 var text_ = thisstickerTab[0];
109 var color = thisstickerTab[1];
110 //console.log(text_, color);
111
112 var idSticker = text_ + "_" + id;
113
114 $('#stickers_'+id).append("<div id='" +idSticker +"' title='"+text_ +"' class='"+text_+ " sticker' " + "name='"+idSticker+"_"+it+"' ></div>");
115 $('#'+idSticker).css({
116 classN : "sticker",
117 backgroundColor : color,
118 top : 50*it+"px",
119 });
120 $('#stickers_'+id).off('mouseover').on('mouseover',function() {
121 if (configBehaviour.tooltip) {
122 $(this).append('<div id=tooltip class="tooltipfrom'+id
123 +' fg-tooltip ui-widget ui-widget-content ui-corner-all" style="font-size: 40px"></div>');
124 var tooltip=$('#tooltip');
125 tooltip.html($(this).attr("title"));
126 $(this).attr("title","");
127 tooltip.append('<div class="fg-tooltip-pointer-down ui-widget-content"><div class="fg-tooltip-pointer-down-inner"></div></div></div>');
128 tooltip.css("top","-180px");
129
130 tooltip.fadeIn('500');
131 tooltip.fadeTo('10',10);
132 }
133 }).off('mouseout').on('mouseout',function() {
134 if (configBehaviour.tooltip) {
135 $(this).attr("title",$(this).children('div#tooltip').text());
136 $(this).children('div#tooltip').remove();
137 }
138 })
139
140 if ( thisstickerTab.length > 2 ) {
141
142 $('#'+idSticker).html(thisstickerTab[2]);
143 var val=thisstickerTab[5];
144 $('#'+idSticker).attr('title',val);
145
146 $('#'+idSticker).on({
147 mouseenter: function() {
148 var idSticker=this.id;
149 var id=idSticker.replace(/.*_(\D*)/,"$1");
150 var it=$('#'+idSticker).attr("name").replace(/.*_(\D*)/,"$1");
151 var thisstickerTab=stickerTab[it];
152 var color = thisstickerTab[1];
153 var cval=rgbFromStr(color);
154 var cm=thisstickerTab[3];
155 var cM=thisstickerTab[4];
156 // $('#'+idSticker).removeClass("sticker");
157 var stickerscale=2;
158 $('#'+idSticker).css({
159 width : 100,
160 zIndex : 999,
161 background : 'linear-gradient(to right,'+cm+','+cM+')'
162 });
163 $('#'+idSticker).css('-webkit-transform','scale('+stickerscale+')').css('-moz-transform','scale('+stickerscale+')');
164 $('#'+idSticker).append("<div id='stick"+idSticker+"' style='color:white' >|</div>");
165 cm=rgbFromStr(cm);
166 cM=rgbFromStr(cM);
167 var s=0;
168 var n=0;
169 if (cM[0] - cm[0] != 0) {
170 s= s+(cval[0] -cm[0]) / (cM[0] - cm[0]);
171 n=n+1;
172 }
173 if (cM[1] - cm[1] != 0) {
174 s= s+(cval[1] -cm[1]) / (cM[1] - cm[1]);
175 n=n+1;
176 }
177 if (cM[2] - cm[2] != 0) {
178 s= s+(cval[2] -cm[2]) / (cM[2] - cm[2]);
179 n=n+1;
180 }
181 s=s/n * parseInt($('#'+idSticker).css("width"))
182 $('#stick'+idSticker).css({
183 position: "absolute",
184 top :-10,
185 left : parseInt(s)
186 })
187 },
188
189 mouseleave: function() {
190 var idSticker=this.id;
191 var id=idSticker.replace(/.*_(\D*)/,"$1");
192 var it=$('#'+idSticker).attr("name").replace(/.*_(\D*)/,"$1");
193 var thisstickerTab=stickerTab[it];
194 var color = thisstickerTab[1];
195 $('#'+idSticker).css('-webkit-transform','scale('+1.+')').css('-moz-transform','scale('+1.+')');
196 $('#'+idSticker).css({
197 width : 50,
198 background : color
199 });
200 $('#'+idSticker).children().remove();
201 }
202 });
203 }
204
205 $('#'+idSticker).off("click").on({
206 click : clickSticker
207 });
208 it++;
209 }
210 }
211
212 /* addSticker tests if the sticker is already present, if not, add it to the stickerTab and updates the stickers to make the new one appear */
213
214 this.addSticker = function(text_, color, updateAll, outColors, val) {
215 var found =0;
216 for (var i=0;i<stickerTab.length;i++) {
217
218 if (stickerTab[i][0]==text_ && stickerTab[i][1] == color) {
219 found = 1;
220 break;
221 }
222 }
223 if (found==0) {
224 if (typeof(outColors) != "undefined") {
225 stickerTab.push([text_, outColors["cval"], outColors["symb"], outColors["cm"], outColors["cM"], val]);
226 } else {
227 stickerTab.push([text_, color]);
228 }
229 }
230 if (updateAll)
231 this.updateStickers(true);
232 }
233
234 this.removeSticker = function(text_,updateAll) {
235 var color = attributedTagsColorsArray[text_];
236 var found = false;
237 var index = -1;
238 for (var i=0;i<stickerTab.length;i++) {
239
240 if (stickerTab[i][0]==text_ && stickerTab[i][1] == color) {
241 found = true;
242 index = i;
243 break;
244 }
245 }
246 if (found) {
247 stickerTab.splice(index, 1);
248 }
249 if (updateAll)
250 this.updateStickers(true);
251 }
252
253 this.colorSticker = function(text_, color) {
254 if($('#stickers_'+id).children("."+text_).length != 0) {
255 var it = 0;
256 while (it < stickerTab.length) {
257 if ( text_ == stickerTab[it][0] ) {
258 stickerTab[it][1] = color;
259 break;
260 }
261 it++;
262 }
263
264 $('#'+ text_ + "_" +id).css({
265 backgroundColor : color,
266 });
267 }
268 }
269 }
270 })