zhao
2021-07-02 081df17b8cc4a6e7e4f4e1e1887f24810e3ec2f9
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
 
var history = new Array();
var cStep = -1;
var ctest = 0;
 
var x, y, endX, endY;
//所有对象集合
var TagActivities = [];
//当前要绘制的
var Cur_sTagActivitie = [];
//当前要绘制的
var Cur_eTagActivitie = [];
//所用线集合
var Tagtransitions = [];
//当前要绘制的
var Cur_Tagtransition = [];
 
var activities = [];
var transitions = [];
//增加标注函数
function AddTagActivitiesTag() {
    var sindex = ++cStep;
 
    //Cur_sTagActivitie[0] = new HH.Libra.StartActivity({ 'id': sindex, 'position': { x: ex + 60, y: ey + 200 }, 'title': '' })
    //TagActivities[sindex] = Cur_sTagActivitie;
 
    var eindex = ++cStep;
    //Cur_eTagActivitie[0] = new HH.Libra.Text({ 'id': eindex, 'position': { x: ex + 300, y: ex + 100 }, 'title': name });
    //TagActivities[eindex] = Cur_eTagActivitie;
 
    //Cur_Tagtransition[0] = new HH.Libra.Transition({ 'id': sindex + "-" + eindex, 'from': sindex, 'fromAngle': 0, 'to': eindex, 'toAngle': 0, 'title': '' });
    //Tagtransitions.push(Cur_Tagtransition);
 
    activities = [
       new HH.Libra.StartActivity({ 'id': sindex, 'position': { x: 188, y: 160 }, 'title': ' ' }),
       new HH.Libra.ManualActivity({ 'id': eindex, 'position': { x: 88, y: 66 }, 'title': '[请输入…]' })
    ];
 
    transitions = [
       new HH.Libra.Transition({ 'id': sindex + "-" + eindex, 'from': sindex, 'fromAngle': -5, 'to': eindex, 'toAngle': -1, 'title': '无条件' })
    ];
 
}
 
 
function GetRandomNum(Min, Max) {
    var Range = Max - Min;
    var Rand = Math.random();
    return (Min + Math.round(Rand * Range));
}
 
//增加文本函数
function AddTextActivitiesTag(ex, ey, name) {
    var eindex = ++cStep;
    var obj = new HH.Libra.Text({ 'id': eindex, 'position': { x: ex + 300, y: ex + 100 }, 'title': name });
    return obj;
 
}
 
var graph;
 
function requireInit() {
    require([
    'zrender',
    'zrender/tool/color',
    'zrender/Group',
    'zrender/shape/Circle',
    'zrender/shape/Rectangle',
    'zrender/shape/Polygon',
    'zrender/shape/Polyline',
    'zrender/shape/Text',
    'zrender/shape/Line',
    'zrender/shape/Image'
    ],
    function (zrender, color, Group, Circle, Rectangle, Polygon, Polyline, Text, Line, Image) {
        // 初始化画板    
        var canvas = $('preview');
        var createOptions = {
            canvas: {
                element: canvas
            }
        };
        var type = {
            zrender: zrender,
            tool: {
                color: color
            },
            Group: Group,
            Shape: {
                Rectangle: Rectangle,
                Circle: Circle,
                Polygon: Polygon,
                Polyline: Polyline,
                Text: Text,
                Line: Line,
                Image: Image
            }
        };
        graph = new HH.Libra.Graph(type, createOptions);
 
        LoadHotList();;//此处放置页面初始化时间实属无赖之举,因为必须在graph绘制后初始化,才能正常显示图片
        initHot();//此处放置页面初始化时间实属无赖之举,因为必须在graph绘制后初始化,才能正常显示图片
 
 
        //*********************
        // graph.init("500", ""); //此处画布初始化,放在HotPictureEdit.cshtml页面加载水印信息函数中,因为初始化需要先获取大图宽度尺寸来初始化画布
        //*********************
 
 
 
        //1.增加标注
        addTag = function () {
            //graph.addActivity(AddTagActivitiesTag(20 + cStep, 30 + cStep, "tag-" + cStep));
            //graph.init();
            //graph.render();
            //var activityObj = AddTagActivitiesTag(20 + cStep, 30 + cStep, "tag-" + cStep);
            //graph.addActivity(activityObj);
            //activityObj.addTo(graph);
            AddTagActivitiesTag();
            activities.each(function (activity) {
                graph.addActivity(activity);
                activity.addTo(graph);
            });
            transitions.each(function (transition) {
                graph.addTransition(transition);
                transition.addTo(graph);
            });
            ///graph.init();
            // graph.render();
 
 
 
        }
 
        //2.增加文本
        addText = function (zrenderX, zrenderY) {
            var img2 = document.getElementById('ImgPic2');
 
            if (img2.src == "") {
                parent.ShowMsg("请先上传热点图!");
                return false;
            }
 
            var tagActivities = graph.getAllActivity();
            //console.log(tagActivities);
            var havecount = 0;
            for (var key in tagActivities) {
                if (tagActivities[key].object != null) {
                    if (parseInt(key) > havecount)
                        havecount = parseInt(key);
                }
                // havecount++;
            }
            var titleindex = havecount + 1;
            var activityObj = new HH.Libra.Text({ 'id': titleindex, 'position': { x: zrenderX, y: zrenderY }, 'title': titleindex });
            graph.addActivity(activityObj);
            activityObj.addTo(graph);
            changeRowColor(titleindex, 1);
        }
 
        //修改时,重绘热点位置
        initText = function (id, posX, posY, note, desc) {
 
            var activityObj = new HH.Libra.Text({ 'id': id, 'position': { x: posX, y: posY }, 'title': note + "$" + desc });
            //var activityObj = new HH.Libra.Text({ 'id': id, 'position': { x: posX, y: posY }, 'title': note + "$" + desc, 'style': { color: colorFont, textFont: sizeFont + "px" + " " + nameFont + " ", brushType: "", textPosition: "", lineWidth: 0 } });
            graph.addActivity(activityObj);
            activityObj.addTo(graph);
 
            //changeRowColor();
            //ActivityObj.refresh(graph);
 
        }
 
 
        //3.增加图片
        addImg = function (imgSrc) {
 
            var img = new Image({
                zlevel: 0,
                style: {
                    x: 0,
                    y: 0,
                    image: imgSrc
                },
                draggable: false,
                hoverable: false
            });
            graph.addShape(img);
        }
 
        //合成图片,获取base64流
        getBase64 = function () {
            var composePic = graph.GetImgUrl();
            return composePic;
        }
    }
);
}
 
 
 
 
 
//function save() {
//    TagActivities = graph.getAllActivity();
//    for (var key in TagActivities) {
//        alert("id=" + TagActivities[key].object.id + ";title=" + TagActivities[key].object.title + ";x=" + TagActivities[key].object.position.x + ";y=" + TagActivities[key].object.position.y);
//    }
//}
 
//function showtoImage() {
//    alert(type.zrender)
//    type.zrender.ShowtoImage();
//}