-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_popup.js
105 lines (84 loc) · 2.05 KB
/
my_popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
function create_popup(svg,w,h,x,y,opacity,id)
{
svg.append('rect')
.attr("id","rect_info"+id)
.attr("x",x)
.attr("y",y)
.attr("width", 0)
.attr("height", 0)
.attr("opacity", opacity)
.attr("fill","white")
.attr("stroke","black")
.attr("stroke-width","3")
}
function show_popup(w,h,title,lines,svg,id,off_x,off_y,title_size,font_size)
{
d3.select("#rect_info"+id).attr("width",w).attr("height",h)
var text=svg.append("text")
.attr("x", 30+off_x)
.attr("y", 40+off_y)
.attr("id","text_pop"+id)
.attr("text-anchor", "left")
.style("font-size", title_size)
//.style("font-style", "italic")
.attr("font-weight", "bold")
.attr("fill", "black")
.attr("opacity",1)
.text(title)
for(var i=0;i<lines.length;i++)
{
var text=svg.append("text")
.attr("x", 30+off_x)
.attr("y", off_y+60+15*i)
.attr("id","text_pop"+id)
.attr("text-anchor", "left")
.style("font-size", font_size)
.attr("fill", "black")
.attr("opacity",1)
.text(lines[i])
}
}
function create_text(w,txt,lines,svg,id,font_size)
{
//the idea is: i split word by word the "txt", adding the word to the current line if it is contained in the svg, otherwise i change line
words=txt.split(" ")
var line_w=0
lines[0]=""
var j=0
for(var i=0;i<words.length;i++)
{
var text=svg.append("text")
.attr("x", 0)
.attr("y", 0)
.attr("text-anchor", "left")
.style("font-size", font_size)
.attr("fill", "black")
.attr("opacity",0)
.text("")
text.text(words[i]+" ")
bbox = text.node().getBBox().width
if((line_w+bbox)<=w)
{
lines[j]=lines[j]+words[i]+" "
line_w=line_w+bbox
if((words[i][words[i].length-1])==".")
{
j++;
lines[j]=""
line_w=0
}
}
else
{
j++;
lines[j]=""
lines[j]=words[i]+" "
line_w=bbox
}
}
}
function hide_popup(id)
{
d3.select("#rect_info"+id).attr("width",0).attr("height",0)
d3.selectAll("#text_pop"+id).remove()
}