-
Notifications
You must be signed in to change notification settings - Fork 238
/
Copy pathinteractivity.html
699 lines (663 loc) · 23.8 KB
/
interactivity.html
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
<!DOCTYPE html>
<html lang="en">
<head>
<!-- AdThrive Head Tag Manual -->
<script data-no-optimize="1" data-cfasync="false">
(function (w, d) {
w.adthrive = w.adthrive || {};
w.adthrive.cmd = w.adthrive.cmd || [];
w.adthrive.plugin = "adthrive-ads-manual";
w.adthrive.host = "ads.adthrive.com";
var s = d.createElement("script");
s.async = true;
s.referrerpolicy = "no-referrer-when-downgrade";
s.src =
"https://" +
w.adthrive.host +
"/sites/643436a4e6d20859e40a446b/ads.min.js?referrer=" +
w.encodeURIComponent(w.location.href) +
"&cb=" +
(Math.floor(Math.random() * 100) + 1);
var n = d.getElementsByTagName("script")[0];
n.parentNode.insertBefore(s, n);
})(window, document);
</script>
<!-- End of AdThrive Head Tag -->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=UA-79254642-6"
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "UA-79254642-6");
</script>
<meta charset="utf-8" />
<title>Interactivity | the D3 Graph Gallery</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta
name="description"
content="General d3.js examples showing how to turn your chart interactive: animation, tooltip, zoom, hover effect and more."
/>
<meta
name="keywords"
content="Data,Dataviz,Datavisualization,Javascript,D3,D3.js,area chart"
/>
<meta name="author" content="Yan Holtz" />
<link rel="icon" href="img/logo/D3_single_small.png" />
<meta
property="og:title"
content="Customizing d3.js chart | the D3 Graph Gallery"
/>
<meta property="og:image" content="img/overview_RGG.png" />
<meta
property="og:description"
content="General d3.js examples showing how to turn your chart interactive: animation, tooltip, zoom, hover effect and more."
/>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<!-- Custom fonts for this template -->
<link
href="vendor/font-awesome/css/font-awesome.min.css"
rel="stylesheet"
type="text/css"
/>
<link
href="https://fonts.googleapis.com/css?family=Montserrat:400,700"
rel="stylesheet"
type="text/css"
/>
<link
href="https://fonts.googleapis.com/css?family=Kaushan+Script"
rel="stylesheet"
type="text/css"
/>
<link
href="https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic,700italic"
rel="stylesheet"
type="text/css"
/>
<link
href="https://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700"
rel="stylesheet"
type="text/css"
/>
<!-- Custom styles for this template -->
<link href="css/agency.css" rel="stylesheet" />
<!-- JQUERY -->
<script src="vendor/jquery/jquery.min.js"></script>
</head>
<body id="page-top">
<!-- THIS ALLOWS TO INSERT THE MENU THAT IS STORED IN A MENU.HTML FILE-->
<nav class="navbar navbar-expand-lg fixed-top" id="mainNav"></nav>
<script>
$(function () {
$("#mainNav").load("html_chunk/menu.html");
});
</script>
<!-- THIS ALLOWS TO INSERT THE MODAL OF THE MENU THAT IS STORED IN A MENU_MODAL.HTML FILE-->
<div id="modal_menu_insertion"></div>
<script>
$(function () {
$("#modal_menu_insertion").load("html_chunk/menu_modal.html");
});
</script>
<!-- Header -->
<header class="masthead" style="padding-top: 150px; padding-bottom: 80px">
<div class="textlanding">
<h1>Interactivity with d3.js</h1>
<hr class="short_hr" />
<br />
<ul class="list-inline social-buttons">
<li class="list-inline-item">
<a href="https://twitter.com/R_Graph_Gallery">
<i class="fa fa-twitter"></i>
</a>
</li>
<li class="list-inline-item social-buttons">
<a href="https://github.com/holtzy">
<i class="fa fa-github" style="color: white"></i>
</a>
</li>
<li class="list-inline-item social-buttons">
<a href="https://www.linkedin.com/in/yan-holtz-2477534a/">
<i class="fa fa-linkedin"></i>
</a>
</li>
<li class="list-inline-item social-buttons">
<a href="https://www.yan-holtz.com">
<i class="fa fa-home"></i>
</a>
</li>
</ul>
<br /><br />
<p style="max-width: 700px; margin: auto">
This section aims to describe how to turn your d3.js chart
interactive. It describe how to add <u>tooltips</u>,
<u>animations</u>, <u>hover</u> effects, <u>zoom</u> feature and more.
</p>
</div>
</header>
<!-- THIS ALLOWS TO INSERT THE ADVERTISEMENT BANNER THAT IS STORED IN A BANNER.HTML FILE-->
<div id="position_for_images"></div>
<script>
$(function () {
$("#position_for_images").load("html_chunk/images.html");
});
</script>
<!-- ======================== PORTFOLIO SECTION ============================ --><!-- Images must be 480 x 480, resize them with ./script_reformat_img.sh output_name.png -->
<section class="bg" id="portfolio" style="padding-top: 10px">
<div class="container">
<div class="mySeryTitle">Tooltip</div>
<hr />
<p>
D3.js allows to easily add a <u>tooltip</u> to any element of your
chart. The idea is always the same: triggering a function when the
user <code>mouseover</code>, <code>mousemove</code> or
<code>mouseleave</code> the element. See the 3 examples below showing
how to apply this technique to a
<a href="graph/interactivity_tooltip.html">single circle</a>, how to
customize the
<a href="graph/interactivity_tooltip.html">tooltip content</a>, and
how to apply it to <a href="graph/scatter_tooltip.html">data</a>.
</p>
<div id="portfolio-items" class="row">
<div class="col-md-4 col-sm-6 portfolio-item">
<a
class="portfolio-link"
href="graph/interactivity_tooltip.html#mostbasic"
>
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<p>Most basic</p>
<hr />
<p class="explanation_portfolio">
The most basic tooltip you can do in d3.js.<br />It just
create one tooltip for one circle
</p>
</div>
</div>
<img class="img-fluid" src="img/graph/tooltip_basic.png" alt="" />
</a>
</div>
<div class="col-md-4 col-sm-6 portfolio-item">
<a
class="portfolio-link"
href="graph/interactivity_tooltip.html#customContent"
>
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<p>HTML in tooltip</p>
<hr />
<p class="explanation_portfolio">
Learn how to customize your tooltip: you can apply any html
code to it!
</p>
</div>
</div>
<img class="img-fluid" src="img/graph/tooltip_html.png" alt="" />
</a>
</div>
<div class="col-md-4 col-sm-6 portfolio-item">
<a
class="portfolio-link"
href="graph/interactivity_tooltip.html#template"
>
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<p>Tooltip linked with data</p>
<hr />
<p class="explanation_portfolio">
Tooltip is different for each datapoint, customized, and
element style are modified when hovered.
</p>
</div>
</div>
<img
class="img-fluid"
src="img/graph/heatmap_tooltip.gif"
alt=""
/>
</a>
</div>
</div>
<br /><br />
<div class="mySeryTitle">Brushing</div>
<hr />
<p>
A post on the basic of <u>brushing</u> with d3.js. It starts by very
<a href="graph/interactivity_brush.html">basic use</a> of the
<code>d3.brush()</code> function: just initializing the functionality.
Then, it explains how to
<a href="graph/interactivity_brush.html#realgraph"
>trigger a function</a
>
to perform a change on the selected points. Lastly, it describes how
to
<a href="graph/interactivity_brush.html#brushingforzoom"
>smoothly zoom</a
>
on the selected area.
</p>
<div id="portfolio-items" class="row">
<div class="col-md-4 col-sm-6 portfolio-item">
<a class="portfolio-link" href="graph/interactivity_brush.html">
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<p>Create your first brush</p>
<hr />
<p class="explanation_portfolio">
A very basic example showing how to initialize a brush area
with d3.brush.
</p>
</div>
</div>
<img
class="img-fluid"
src="img/graph/interactivity_brushInitialize.png"
alt=""
/>
</a>
</div>
<div class="col-md-4 col-sm-6 portfolio-item">
<a
class="portfolio-link"
href="graph/interactivity_brush.html#realgraph"
>
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<p>Trigger a function</p>
<hr />
<p class="explanation_portfolio">
How to get the brush coordinates and apply a function to the
points in the area.
</p>
</div>
</div>
<img
class="img-fluid"
src="img/graph/interactivity_brushTrigger.gif"
alt=""
/>
</a>
</div>
<div class="col-md-4 col-sm-6 portfolio-item">
<a
class="portfolio-link"
href="graph/interactivity_brush.html#brushingforzoom"
>
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<p>Brushing for zooming</p>
<hr />
<p class="explanation_portfolio">
How to zoom on the brushed area with a smooth transition.
</p>
</div>
</div>
<img
class="img-fluid"
src="img/graph/interactivity_brushZoom.gif"
alt=""
/>
</a>
</div>
</div>
<br /><br />
<div class="mySeryTitle">Buttons</div>
<hr />
<p>
A post on buttons: what are the different types, how to add them using
html, and how to connect them with the chart to trigger transition and
animation.
</p>
<div id="portfolio-items" class="row">
<div class="col-md-4 col-sm-6 portfolio-item">
<a class="portfolio-link" href="graph/interactivity_button.html">
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<p>HTML button types</p>
<hr />
<p class="explanation_portfolio">
HTML natively offers different types of button: here is a
description of them with the associated code.
</p>
</div>
</div>
<img
class="img-fluid"
src="img/graph/interactivity_button.png"
alt=""
/>
</a>
</div>
</div>
<br /><br />
<div class="mySeryTitle">Zooming</div>
<hr />
<p>
A post on the basic of <u>zooming</u> with d3.js. It starts with a
very <a href="graph/interactivity_zoom.html">basic use</a> of the
<code>d3.zoom()</code> function: just applied on a single circle.
Then, it explains how to
<a href="graph/interactivity_zoom.html#axisZoom"
>trigger a function</a
>
that update axis. Lastly, it shows that
<a href="graph/interactivity_zoom.html#brushingforzoom">brushing</a>
can be used for zooming as well.
</p>
<div id="portfolio-items" class="row">
<div class="col-md-4 col-sm-6 portfolio-item">
<a class="portfolio-link" href="graph/interactivity_zoom.html">
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<p>Most basic zoom</p>
<hr />
<p class="explanation_portfolio">
A very basic example showing how to initialize a zoom area
with d3.zoom.
</p>
</div>
</div>
<img
class="img-fluid"
src="img/graph/interactivity_zoomBasic.gif"
alt=""
/>
</a>
</div>
<div class="col-md-4 col-sm-6 portfolio-item">
<a
class="portfolio-link"
href="graph/interactivity_zoom.html#axisZoom"
>
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<p>Update axis and element position</p>
<hr />
<p class="explanation_portfolio">
An example on a real scatterplot to show how to update axis
and elements.
</p>
</div>
</div>
<img
class="img-fluid"
src="img/graph/interactivity_zoomAxis.gif"
alt=""
/>
</a>
</div>
<div class="col-md-4 col-sm-6 portfolio-item">
<a
class="portfolio-link"
href="graph/interactivity_zoom.html#brushingforzoom"
>
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<p>Brushing for zooming</p>
<hr />
<p class="explanation_portfolio">
How to zoom on the brushed area with a smooth transition.
</p>
</div>
</div>
<img
class="img-fluid"
src="img/graph/interactivity_brushZoom.gif"
alt=""
/>
</a>
</div>
</div>
<br /><br />
<div class="mySeryTitle">Transition</div>
<hr />
<p>
<u>Transition</u> is where the magic of D3 takes place. Here you will
find a few examples based on a single element to understand the basic
mechanism. A few examples based on a real chart are then available to
illustrate the process.
</p>
<div id="portfolio-items" class="row">
<div class="col-md-4 col-sm-6 portfolio-item">
<a
class="portfolio-link"
href="graph/interactivity_transition.html"
>
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<p>Most basic</p>
<hr />
<p class="explanation_portfolio">
The most basic transition you can do in d3.js.<br />It just
modify the width attribute of a div using d3.js, keeping
only the core code.
</p>
</div>
</div>
<img
class="img-fluid"
src="img/graph/transition_basic.gif"
alt=""
/>
</a>
</div>
<div class="col-md-4 col-sm-6 portfolio-item">
<a
class="portfolio-link"
href="graph/interactivity_transition.html"
>
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<p>Pipe several transition</p>
<hr />
<p class="explanation_portfolio">
Run several transitions one after another. Involves
different attributes like color and width.
</p>
</div>
</div>
<img
class="img-fluid"
src="img/graph/transition_pipe.gif"
alt=""
/>
</a>
</div>
<div class="col-md-4 col-sm-6 portfolio-item">
<a
class="portfolio-link"
href="graph/interactivity_transition.html"
>
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<p>Progressive transition</p>
<hr />
<p class="explanation_portfolio">
This example applies a different <code>delay</code> to each
element. It gives a progressive transition where elements
start moving one by one.
</p>
</div>
</div>
<img
class="img-fluid"
src="img/graph/transition_delay.gif"
alt=""
/>
</a>
</div>
</div>
</div>
</section>
<!-- ======================================================================= -->
<!-- ============================ RELATED SECTION ============================ -->
<section
class="bg-light"
id="portfolio_landing"
style="padding-top: 30px; padding-bottom: 30px"
>
<div class="container">
<p class="mySeryTitle">Related chart types</p>
<hr />
<div class="row">
<div class="col-md-2 col-sm-4 portfolio-item">
<a
class="portfolio-link"
href="https://www.d3-graph-gallery.com/intro_d3js.html"
>
<img
class="img-fluid grey_on_hover"
src="img/section/Basic150.png"
alt=""
/>
</a>
<div class="captionPortfolio">Basics</div>
</div>
<div class="col-md-2 col-sm-4 portfolio-item">
<a class="portfolio-link" href="custom.html">
<img
class="img-fluid grey_on_hover"
src="img/section/Colours150.png"
alt=""
/>
</a>
<div class="captionPortfolio">Custom</div>
</div>
<div class="col-md-2 col-sm-4 portfolio-item">
<a class="portfolio-link" href="interactivity.html">
<img
class="img-fluid grey_on_hover"
src="img/section/anim150.gif"
alt=""
/>
</a>
<div class="captionPortfolio">Interactivity</div>
</div>
<div class="col-md-2 col-sm-4 portfolio-item">
<a class="portfolio-link" href="graph/shape.html">
<img
class="img-fluid grey_on_hover"
src="img/section/Shapehelper150.png"
alt=""
/>
</a>
<div class="captionPortfolio">Shape helpers</div>
</div>
<div class="col-md-2 col-sm-4 portfolio-item">
<a
class="portfolio-link"
href="https://www.data-to-viz.com/caveats.html"
>
<img
class="img-fluid grey_on_hover"
src="img/section/Bad150.png"
alt=""
/>
</a>
<div class="captionPortfolio">Caveats</div>
</div>
<div class="col-md-2 col-sm-4 portfolio-item">
<a
class="portfolio-link"
href="https://www.data-to-art.com"
>
<img
class="img-fluid grey_on_hover"
src="img/section/DataArt1150.png"
alt=""
/>
</a>
<div class="captionPortfolio">Data art</div>
</div>
</div>
</div>
</section>
<!-- ============================ CONTACT SECTION ============================ -->
<!-- ANCHOR -->
<a name="contactanchor"></a>
<section id="contact" class="bg" style="background-color: white"></section>
<!-- THIS ALLOWS TO INSERT THE CONTACT CHUNK THAT IS STORED IN A CONTACT.HTML FILE-->
<script>
$(function () {
$("#contact").load("html_chunk/contact.html");
});
</script>
<!-- ============================ FOOTER SECTION ============================ -->
<footer class="bg-light" id="myFooter"></footer>
<!-- Start Added by AdThrive -->
<script
type="text/javascript"
async
src="https://btloader.com/tag?o=5698917485248512&upapi=true&domain=d3-graph-gallery.com"
></script>
<script>
!(function () {
"use strict";
var e;
(e = document),
(function () {
var t, n;
function r() {
var t = e.createElement("script");
(t.src =
"https://cafemedia-com.videoplayerhub.com/galleryplayer.js"),
e.head.appendChild(t);
}
function a() {
var t = e.cookie.match("(^|[^;]+)\s*__adblocker\s*=\s*([^;]+)");
return t && t.pop();
}
function c() {
clearInterval(n);
}
return {
init: function () {
var e;
"true" === (t = a())
? r()
: ((e = 0),
(n = setInterval(function () {
(100 !== e && "false" !== t) || c(),
"true" === t && (r(), c()),
(t = a()),
e++;
}, 50)));
},
};
})().init();
})();
</script>
<!-- End Added by AdThrive -->
<!-- THIS ALLOWS TO INSERT THE FOOTER THAT IS STORED IN A FOOTER.HTML FILE-->
<script>
$(function () {
$("#myFooter").load("html_chunk/footer.html");
});
</script>
<!-- ============================ -->
<!-- =============== JAVASCRIPT SECTION =============== -->
<!-- Bootstrap core JavaScript -->
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Plugin JavaScript -->
<script src="vendor/jquery-easing/jquery.easing.min.js"></script>
<!-- Custom scripts for this template -->
<script src="js/agency.min.js"></script>
<!-- Activate the bootstrap tooltip, must be after jQuery load -->
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip();
});
</script>
<!--============================== -->
</body>
</html>