forked from greghub/funnel-graph-js
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample.html
More file actions
executable file
·263 lines (230 loc) · 8.4 KB
/
example.html
File metadata and controls
executable file
·263 lines (230 loc) · 8.4 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<!DOCTYPE html>
<html lang="en">
<!-- TODO: Refactor Just to make it Clean -->
<head>
<meta charset="UTF-8">
<title>SVG Funnel</title>
<link rel="stylesheet" type="text/css" href="../dist/css/funnel-graph.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" type="image/png" href="favicon.png" />
<style>
html,
body {
min-height: 100%;
}
body {
margin: 0;
background: #393862;
}
.funnel {
height: 100%;
height: 100%;
}
.flex {
display: flex;
}
.row {
flex-direction: row;
}
.col {
flex-direction: column;
}
.method-buttons {
align-items: center;
justify-content: start;
padding: 8px;
}
button {
width: 100px;
margin: 4px;
padding: 4px;
}
.funnel-wrapper {
align-items: center;
justify-content: start;
width: 100%;
height: 100%;
}
.main-wrapper {
height: 100vh;
}
button {
display: flex;
justify-content: center;
align-items: center;
height: auto;
background-color: #f0f0f0;
margin: 0;
background-color: white;
/* White background */
border: none;
/* Remove borders */
color: navy;
/* Green text */
text-align: center;
/* Centered text */
text-decoration: none;
/* Remove underline */
display: inline-block;
/* Get the element to line up horizontally */
font-size: 12px;
/* Increase font size */
margin: 4px 2px;
/* Add some margin */
cursor: pointer;
/* Pointer/hand icon */
border-radius: 12px;
/* Rounded corners */
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
/* Subtle shadow */
transition: background-color 0.3s, box-shadow 0.3s;
/* Smooth transitions */
}
</style>
</head>
<body>
<div class="main-wrapper flex row" style="position: relative">
<div class="flex method-buttons col">
<button id="makeVertical">Vertical</button>
<button id="makeHorizontal">Horizontal</button>
<button id="toggleDirection">Toggle Direction</button>
<button id="gradientMakeVertical">Vertical Gradient</button>
<button id="gradientMakeHorizontal">Horizontal Gradient </button>
<button id="gradientToggleDirection">Gradient Toggle Direction</button>
<button id="useData1">DataSet 1</button>
<button id="useData2">DataSet 2</button>
<button id="useData3">DataSet 3</button>
<button id="useData4">DataSet 4 (empty array [])</button>
<button id="useData5">DataSet 5 (empty zeros [0, 0...])</button>
<button id="hideTooltip">Hide Tooltip</button>
<button id="hideDetails">Hide Details</button>
<button id="showTooltip">Show Tooltip</button>
<button id="showDetails">Show Details</button>
<button id="setResponsive">Toggle Responsive</button>
</div>
<div style="width: 100%">
<div class="flex funnel-wrapper col">
<div class="funnel"></div>
</div>
</div>
</div>
<script src="../dist/js/funnel-graph.js"></script>
<script>
const emptyExample = {
values: []
};
const emptyZerosExample = {
values: [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
],
};
const dataExample1 = {
colors: ['#FFB178', '#FF3C8E'],
values: [11000, 3000, 240]
};
const dataExample2 = {
labels: ['Impressions 2', 'Add To Cart 2', 'Buy 2'],
colors: ['#FFB178', '#FF3C8E'],
values: [12000, 5700, 360]
};
const dataExample3 = {
labels: ['Impressions', 'Add To Cart', 'Buy'],
subLabels: ['Direct', 'Social Media', 'Ads'],
colors: [
['#FFB178', '#FF78B1', '#FF3C8E'],
['#A0BBFF', '#EC77FF'],
['#A0F9FF', '#7795FF']
],
values: [
[3000, 2500, 6500],
[3000, 1700, 1000],
[600, 200, 130]
],
};
let responsive = false;
const graph = new FunnelGraph({
container: '.funnel',
gradientDirection: 'horizontal',
data: dataExample3,
displayPercent: true,
direction: 'horizontal',
width: 800,
height: 300,
subLabelValue: 'raw',
callbacks: {
click: (event, metadata) => {
console.log("click handler", metadata);
},
// adding a tooltip handler instead of the ootb tooltip display
// tooltip: (event, metadata) => {
// console.log("tooltip handler", metadata);
// }
},
margin: { top: 120, right: 60, bottom: 60, left: 60, text: 10 },
responsive
});
graph.draw();
window.addEventListener('beforeunload', () => {
graph?.destroy();
});
// direction methods
document.querySelector('#makeVertical').addEventListener('click', function () {
graph.setWidth(300);
graph.setHeight(400);
graph.makeVertical();
});
document.querySelector('#makeHorizontal').addEventListener('click', function () {
graph.setWidth(800);
graph.setHeight(300);
graph.makeHorizontal();
});
document.querySelector('#toggleDirection').addEventListener('click', function () {
graph.direction === 'horizontal' ? document.querySelector('#makeVertical').click() :
document.querySelector('#makeHorizontal').click();
});
// gradient methods
document.querySelector('#gradientMakeVertical').addEventListener('click', function () {
graph.gradientMakeVertical();
});
document.querySelector('#gradientMakeHorizontal').addEventListener('click', function () {
graph.gradientMakeHorizontal();
});
document.querySelector('#gradientToggleDirection').addEventListener('click', function () {
graph.gradientToggleDirection();
});
document.querySelector('#useData1').addEventListener('click', function () {
graph.updateData(dataExample1);
});
document.querySelector('#useData2').addEventListener('click', function () {
graph.updateData(dataExample2);
});
document.querySelector('#useData3').addEventListener('click', function () {
graph.updateData(dataExample3);
});
document.querySelector('#useData4').addEventListener('click', function () {
graph.updateData(emptyExample);
});
document.querySelector('#useData5').addEventListener('click', function () {
graph.updateData(emptyZerosExample);
});
document.querySelector('#hideTooltip').addEventListener('click', function () {
graph.updateData({ tooltip: false });
});
document.querySelector('#hideDetails').addEventListener('click', function () {
graph.updateData({ width: 200, height: 200, details: false, margin: { top: 0, right: 0, bottom: 0, left: 0, text: 0 } });
});
document.querySelector('#showTooltip').addEventListener('click', function () {
graph.updateData({ tooltip: true });
});
document.querySelector('#showDetails').addEventListener('click', function () {
graph.updateData({ width: 600, height: 400, details: true, margin: { top: 100, right: 80, bottom: 80, left: 80, text: 20 } });
});
document.querySelector('#setResponsive').addEventListener('click', function () {
responsive = !responsive;
graph.updateData({ responsive });
});
</script>
</body>
</html>