-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1033 lines (952 loc) · 336 KB
/
index.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
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>d3jsTutorial</title>
<script src="https://d3js.org/d3.v5.min.js"></script>
<style>
strong code {
color:#c7254e !important
}
body svg {
text-align: center;
}
.bar {
fill: steelblue;
}
.highlight {
fill: orange;
}
.val {
font-weight: bold;
fill: green;
}
.arc text {
font: 10px sans-serif;
text-anchor: middle;
}
.arc path {
stroke: #fff;
}
.title {
fill: teal;
font-weight: bold;
}
.markdown-preview:not([data-use-github-style]) { padding: 2em; font-size: 1.2em; color: rgb(171, 178, 191); background-color: rgb(40, 44, 52); overflow: auto; }
.markdown-preview:not([data-use-github-style]) > :first-child { margin-top: 0px; }
.markdown-preview:not([data-use-github-style]) h1, .markdown-preview:not([data-use-github-style]) h2, .markdown-preview:not([data-use-github-style]) h3, .markdown-preview:not([data-use-github-style]) h4, .markdown-preview:not([data-use-github-style]) h5, .markdown-preview:not([data-use-github-style]) h6 { line-height: 1.2; margin-top: 1.5em; margin-bottom: 0.5em; color: rgb(255, 255, 255); }
.markdown-preview:not([data-use-github-style]) h1 { font-size: 2.4em; font-weight: 300; }
.markdown-preview:not([data-use-github-style]) h2 { font-size: 1.8em; font-weight: 400; }
.markdown-preview:not([data-use-github-style]) h3 { font-size: 1.5em; font-weight: 500; }
.markdown-preview:not([data-use-github-style]) h4 { font-size: 1.2em; font-weight: 600; }
.markdown-preview:not([data-use-github-style]) h5 { font-size: 1.1em; font-weight: 600; }
.markdown-preview:not([data-use-github-style]) h6 { font-size: 1em; font-weight: 600; }
.markdown-preview:not([data-use-github-style]) strong { color: rgb(255, 255, 255); }
.markdown-preview:not([data-use-github-style]) del { color: rgb(124, 135, 156); }
.markdown-preview:not([data-use-github-style]) a, .markdown-preview:not([data-use-github-style]) a code { color: rgb(82, 139, 255); }
.markdown-preview:not([data-use-github-style]) img { max-width: 100%; }
.markdown-preview:not([data-use-github-style]) > p { margin-top: 0px; margin-bottom: 1.5em; }
.markdown-preview:not([data-use-github-style]) > ul, .markdown-preview:not([data-use-github-style]) > ol { margin-bottom: 1.5em; }
.markdown-preview:not([data-use-github-style]) blockquote { margin: 1.5em 0px; font-size: inherit; color: rgb(124, 135, 156); border-color: rgb(75, 83, 98); border-width: 4px; }
.markdown-preview:not([data-use-github-style]) hr { margin: 3em 0px; border-top: 2px dashed rgb(75, 83, 98); background: none; }
.markdown-preview:not([data-use-github-style]) table { margin: 1.5em 0px; }
.markdown-preview:not([data-use-github-style]) th { color: rgb(255, 255, 255); }
.markdown-preview:not([data-use-github-style]) th, .markdown-preview:not([data-use-github-style]) td { padding: 0.66em 1em; border: 1px solid rgb(75, 83, 98); }
.markdown-preview:not([data-use-github-style]) code { color: rgb(255, 255, 255); background-color: rgb(58, 63, 75); }
.markdown-preview:not([data-use-github-style]) pre.editor-colors { margin: 1.5em 0px; padding: 1em; font-size: 0.92em; border-radius: 3px; background-color: rgb(49, 54, 63); }
.markdown-preview:not([data-use-github-style]) kbd { color: rgb(255, 255, 255); border-width: 1px 1px 2px; border-style: solid; border-color: rgb(75, 83, 98) rgb(75, 83, 98) rgb(62, 68, 81); border-image: initial; background-color: rgb(58, 63, 75); }
.markdown-preview[data-use-github-style] { font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif; line-height: 1.6; word-wrap: break-word; padding: 30px; font-size: 16px; color: rgb(51, 51, 51); background-color: rgb(255, 255, 255); overflow: scroll; }
.markdown-preview[data-use-github-style] > :first-child { margin-top: 0px !important; }
.markdown-preview[data-use-github-style] > :last-child { margin-bottom: 0px !important; }
.markdown-preview[data-use-github-style] a:not([href]) { color: inherit; text-decoration: none; }
.markdown-preview[data-use-github-style] .absent { color: rgb(204, 0, 0); }
.markdown-preview[data-use-github-style] .anchor { position: absolute; top: 0px; left: 0px; display: block; padding-right: 6px; padding-left: 30px; margin-left: -30px; }
.markdown-preview[data-use-github-style] .anchor:focus { outline: none; }
.markdown-preview[data-use-github-style] h1, .markdown-preview[data-use-github-style] h2, .markdown-preview[data-use-github-style] h3, .markdown-preview[data-use-github-style] h4, .markdown-preview[data-use-github-style] h5, .markdown-preview[data-use-github-style] h6 { position: relative; margin-top: 1em; margin-bottom: 16px; font-weight: bold; line-height: 1.4; }
.markdown-preview[data-use-github-style] h1 .octicon-link, .markdown-preview[data-use-github-style] h2 .octicon-link, .markdown-preview[data-use-github-style] h3 .octicon-link, .markdown-preview[data-use-github-style] h4 .octicon-link, .markdown-preview[data-use-github-style] h5 .octicon-link, .markdown-preview[data-use-github-style] h6 .octicon-link { display: none; color: rgb(0, 0, 0); vertical-align: middle; }
.markdown-preview[data-use-github-style] h1:hover .anchor, .markdown-preview[data-use-github-style] h2:hover .anchor, .markdown-preview[data-use-github-style] h3:hover .anchor, .markdown-preview[data-use-github-style] h4:hover .anchor, .markdown-preview[data-use-github-style] h5:hover .anchor, .markdown-preview[data-use-github-style] h6:hover .anchor { padding-left: 8px; margin-left: -30px; text-decoration: none; }
.markdown-preview[data-use-github-style] h1:hover .anchor .octicon-link, .markdown-preview[data-use-github-style] h2:hover .anchor .octicon-link, .markdown-preview[data-use-github-style] h3:hover .anchor .octicon-link, .markdown-preview[data-use-github-style] h4:hover .anchor .octicon-link, .markdown-preview[data-use-github-style] h5:hover .anchor .octicon-link, .markdown-preview[data-use-github-style] h6:hover .anchor .octicon-link { display: inline-block; }
.markdown-preview[data-use-github-style] h1 tt, .markdown-preview[data-use-github-style] h2 tt, .markdown-preview[data-use-github-style] h3 tt, .markdown-preview[data-use-github-style] h4 tt, .markdown-preview[data-use-github-style] h5 tt, .markdown-preview[data-use-github-style] h6 tt, .markdown-preview[data-use-github-style] h1 code, .markdown-preview[data-use-github-style] h2 code, .markdown-preview[data-use-github-style] h3 code, .markdown-preview[data-use-github-style] h4 code, .markdown-preview[data-use-github-style] h5 code, .markdown-preview[data-use-github-style] h6 code { font-size: inherit; }
.markdown-preview[data-use-github-style] h1 { padding-bottom: 0.3em; font-size: 2.25em; line-height: 1.2; border-bottom: 1px solid rgb(238, 238, 238); }
.markdown-preview[data-use-github-style] h1 .anchor { line-height: 1; }
.markdown-preview[data-use-github-style] h2 { padding-bottom: 0.3em; font-size: 1.75em; line-height: 1.225; border-bottom: 1px solid rgb(238, 238, 238); }
.markdown-preview[data-use-github-style] h2 .anchor { line-height: 1; }
.markdown-preview[data-use-github-style] h3 { font-size: 1.5em; line-height: 1.43; }
.markdown-preview[data-use-github-style] h3 .anchor { line-height: 1.2; }
.markdown-preview[data-use-github-style] h4 { font-size: 1.25em; }
.markdown-preview[data-use-github-style] h4 .anchor { line-height: 1.2; }
.markdown-preview[data-use-github-style] h5 { font-size: 1em; }
.markdown-preview[data-use-github-style] h5 .anchor { line-height: 1.1; }
.markdown-preview[data-use-github-style] h6 { font-size: 1em; color: rgb(119, 119, 119); }
.markdown-preview[data-use-github-style] h6 .anchor { line-height: 1.1; }
.markdown-preview[data-use-github-style] p, .markdown-preview[data-use-github-style] blockquote, .markdown-preview[data-use-github-style] ul, .markdown-preview[data-use-github-style] ol, .markdown-preview[data-use-github-style] dl, .markdown-preview[data-use-github-style] table, .markdown-preview[data-use-github-style] pre { margin-top: 0px; margin-bottom: 16px; }
.markdown-preview[data-use-github-style] hr { height: 4px; padding: 0px; margin: 16px 0px; background-color: rgb(231, 231, 231); border: 0px none; }
.markdown-preview[data-use-github-style] ul, .markdown-preview[data-use-github-style] ol { padding-left: 2em; }
.markdown-preview[data-use-github-style] ul.no-list, .markdown-preview[data-use-github-style] ol.no-list { padding: 0px; list-style-type: none; }
.markdown-preview[data-use-github-style] ul ul, .markdown-preview[data-use-github-style] ul ol, .markdown-preview[data-use-github-style] ol ol, .markdown-preview[data-use-github-style] ol ul { margin-top: 0px; margin-bottom: 0px; }
.markdown-preview[data-use-github-style] li > p { margin-top: 16px; }
.markdown-preview[data-use-github-style] dl { padding: 0px; }
.markdown-preview[data-use-github-style] dl dt { padding: 0px; margin-top: 16px; font-size: 1em; font-style: italic; font-weight: bold; }
.markdown-preview[data-use-github-style] dl dd { padding: 0px 16px; margin-bottom: 16px; }
.markdown-preview[data-use-github-style] blockquote { padding: 0px 15px; color: rgb(119, 119, 119); border-left: 4px solid rgb(221, 221, 221); }
.markdown-preview[data-use-github-style] blockquote > :first-child { margin-top: 0px; }
.markdown-preview[data-use-github-style] blockquote > :last-child { margin-bottom: 0px; }
.markdown-preview[data-use-github-style] table { display: block; width: 100%; overflow: auto; word-break: keep-all; }
.markdown-preview[data-use-github-style] table th { font-weight: bold; }
.markdown-preview[data-use-github-style] table th, .markdown-preview[data-use-github-style] table td { padding: 6px 13px; border: 1px solid rgb(221, 221, 221); }
.markdown-preview[data-use-github-style] table tr { background-color: rgb(255, 255, 255); border-top: 1px solid rgb(204, 204, 204); }
.markdown-preview[data-use-github-style] table tr:nth-child(2n) { background-color: rgb(248, 248, 248); }
.markdown-preview[data-use-github-style] img { max-width: 100%; box-sizing: border-box; }
.markdown-preview[data-use-github-style] .emoji { max-width: none; }
.markdown-preview[data-use-github-style] span.frame { display: block; overflow: hidden; }
.markdown-preview[data-use-github-style] span.frame > span { display: block; float: left; width: auto; padding: 7px; margin: 13px 0px 0px; overflow: hidden; border: 1px solid rgb(221, 221, 221); }
.markdown-preview[data-use-github-style] span.frame span img { display: block; float: left; }
.markdown-preview[data-use-github-style] span.frame span span { display: block; padding: 5px 0px 0px; clear: both; color: rgb(51, 51, 51); }
.markdown-preview[data-use-github-style] span.align-center { display: block; overflow: hidden; clear: both; }
.markdown-preview[data-use-github-style] span.align-center > span { display: block; margin: 13px auto 0px; overflow: hidden; text-align: center; }
.markdown-preview[data-use-github-style] span.align-center span img { margin: 0px auto; text-align: center; }
.markdown-preview[data-use-github-style] span.align-right { display: block; overflow: hidden; clear: both; }
.markdown-preview[data-use-github-style] span.align-right > span { display: block; margin: 13px 0px 0px; overflow: hidden; text-align: right; }
.markdown-preview[data-use-github-style] span.align-right span img { margin: 0px; text-align: right; }
.markdown-preview[data-use-github-style] span.float-left { display: block; float: left; margin-right: 13px; overflow: hidden; }
.markdown-preview[data-use-github-style] span.float-left span { margin: 13px 0px 0px; }
.markdown-preview[data-use-github-style] span.float-right { display: block; float: right; margin-left: 13px; overflow: hidden; }
.markdown-preview[data-use-github-style] span.float-right > span { display: block; margin: 13px auto 0px; overflow: hidden; text-align: right; }
.markdown-preview[data-use-github-style] code, .markdown-preview[data-use-github-style] tt { padding: 0.2em 0px; margin: 0px; font-size: 85%; background-color: rgba(0, 0, 0, 0.04); border-radius: 3px; }
.markdown-preview[data-use-github-style] code::before, .markdown-preview[data-use-github-style] tt::before, .markdown-preview[data-use-github-style] code::after, .markdown-preview[data-use-github-style] tt::after { letter-spacing: -0.2em; content: " "; }
.markdown-preview[data-use-github-style] code br, .markdown-preview[data-use-github-style] tt br { display: none; }
.markdown-preview[data-use-github-style] del code { text-decoration: inherit; }
.markdown-preview[data-use-github-style] pre > code { padding: 0px; margin: 0px; font-size: 100%; word-break: normal; white-space: pre; background: transparent; border: 0px; }
.markdown-preview[data-use-github-style] .highlight { margin-bottom: 16px; }
.markdown-preview[data-use-github-style] .highlight pre, .markdown-preview[data-use-github-style] pre { padding: 16px; overflow: auto; font-size: 85%; line-height: 1.45; background-color: rgb(247, 247, 247); border-radius: 3px; }
.markdown-preview[data-use-github-style] .highlight pre { margin-bottom: 0px; word-break: normal; }
.markdown-preview[data-use-github-style] pre { word-wrap: normal; }
.markdown-preview[data-use-github-style] pre code, .markdown-preview[data-use-github-style] pre tt { display: inline; max-width: initial; padding: 0px; margin: 0px; overflow: initial; line-height: inherit; word-wrap: normal; background-color: transparent; border: 0px; }
.markdown-preview[data-use-github-style] pre code::before, .markdown-preview[data-use-github-style] pre tt::before, .markdown-preview[data-use-github-style] pre code::after, .markdown-preview[data-use-github-style] pre tt::after { content: normal; }
.markdown-preview[data-use-github-style] kbd { display: inline-block; padding: 3px 5px; font-size: 11px; line-height: 10px; color: rgb(85, 85, 85); vertical-align: middle; background-color: rgb(252, 252, 252); border-width: 1px; border-style: solid; border-color: rgb(204, 204, 204) rgb(204, 204, 204) rgb(187, 187, 187); border-image: initial; border-radius: 3px; box-shadow: rgb(187, 187, 187) 0px -1px 0px inset; }
.markdown-preview[data-use-github-style] a { color: rgb(51, 122, 183); }
.markdown-preview[data-use-github-style] code { color: inherit; }
.markdown-preview[data-use-github-style] pre.editor-colors { padding: 0.8em 1em; margin-bottom: 1em; font-size: 0.85em; border-radius: 4px; overflow: auto; }
.markdown-preview pre.editor-colors { user-select: auto; }
.scrollbars-visible-always .markdown-preview pre.editor-colors .vertical-scrollbar, .scrollbars-visible-always .markdown-preview pre.editor-colors .horizontal-scrollbar { visibility: hidden; }
.scrollbars-visible-always .markdown-preview pre.editor-colors:hover .vertical-scrollbar, .scrollbars-visible-always .markdown-preview pre.editor-colors:hover .horizontal-scrollbar { visibility: visible; }
.markdown-preview .task-list-item-checkbox { position: absolute; margin: 0.25em 0px 0px -1.4em; }
.markdown-preview ul label { vertical-align: top; }
.bracket-matcher .region {
border-bottom: 1px dotted lime;
position: absolute;
}
.line-number.bracket-matcher.bracket-matcher {
color: #abb2bf;
background-color: #3a3f4b;
}
.spell-check-misspelling .region {
border-bottom: 2px dotted rgba(255, 51, 51, 0.75);
}
.spell-check-corrections {
width: 25em !important;
}
pre.editor-colors {
background-color: #282c34;
color: #abb2bf;
}
pre.editor-colors .line.cursor-line {
background-color: rgba(153, 187, 255, 0.04);
}
pre.editor-colors .invisible {
color: #abb2bf;
}
pre.editor-colors .cursor {
border-left: 2px solid #528bff;
}
pre.editor-colors .selection .region {
background-color: #3e4451;
}
pre.editor-colors .bracket-matcher .region {
border-bottom: 1px solid #528bff;
box-sizing: border-box;
}
pre.editor-colors .invisible-character {
color: rgba(171, 178, 191, 0.15);
}
pre.editor-colors .indent-guide {
color: rgba(171, 178, 191, 0.15);
}
pre.editor-colors .wrap-guide {
background-color: rgba(171, 178, 191, 0.15);
}
pre.editor-colors .find-result .region.region.region,
pre.editor-colors .current-result .region.region.region {
border-radius: 2px;
background-color: rgba(82, 139, 255, 0.24);
transition: border-color 0.4s;
}
pre.editor-colors .find-result .region.region.region {
border: 2px solid transparent;
}
pre.editor-colors .current-result .region.region.region {
border: 2px solid #528bff;
transition-duration: .1s;
}
pre.editor-colors .gutter .line-number {
color: #636d83;
-webkit-font-smoothing: antialiased;
}
pre.editor-colors .gutter .line-number.cursor-line {
color: #abb2bf;
background-color: #3a3f4b;
}
pre.editor-colors .gutter .line-number.cursor-line-no-selection {
background-color: transparent;
}
pre.editor-colors .gutter .line-number .icon-right {
color: #abb2bf;
}
pre.editor-colors .gutter:not(.git-diff-icon) .line-number.git-line-removed.git-line-removed::before {
bottom: -3px;
}
pre.editor-colors .gutter:not(.git-diff-icon) .line-number.git-line-removed::after {
content: "";
position: absolute;
left: 0px;
bottom: 0px;
width: 25px;
border-bottom: 1px dotted rgba(224, 82, 82, 0.5);
pointer-events: none;
}
pre.editor-colors .gutter .line-number.folded,
pre.editor-colors .gutter .line-number:after,
pre.editor-colors .fold-marker:after {
color: #abb2bf;
}
.syntax--comment {
color: #5c6370;
font-style: italic;
}
.syntax--comment .syntax--markup.syntax--link {
color: #5c6370;
}
.syntax--entity.syntax--name.syntax--type {
color: #e5c07b;
}
.syntax--entity.syntax--other.syntax--inherited-class {
color: #98c379;
}
.syntax--keyword {
color: #c678dd;
}
.syntax--keyword.syntax--control {
color: #c678dd;
}
.syntax--keyword.syntax--operator {
color: #abb2bf;
}
.syntax--keyword.syntax--other.syntax--special-method {
color: #61afef;
}
.syntax--keyword.syntax--other.syntax--unit {
color: #d19a66;
}
.syntax--storage {
color: #c678dd;
}
.syntax--storage.syntax--type.syntax--annotation,
.syntax--storage.syntax--type.syntax--primitive {
color: #c678dd;
}
.syntax--storage.syntax--modifier.syntax--package,
.syntax--storage.syntax--modifier.syntax--import {
color: #abb2bf;
}
.syntax--constant {
color: #d19a66;
}
.syntax--constant.syntax--variable {
color: #d19a66;
}
.syntax--constant.syntax--character.syntax--escape {
color: #56b6c2;
}
.syntax--constant.syntax--numeric {
color: #d19a66;
}
.syntax--constant.syntax--other.syntax--color {
color: #56b6c2;
}
.syntax--constant.syntax--other.syntax--symbol {
color: #56b6c2;
}
.syntax--variable {
color: #e06c75;
}
.syntax--variable.syntax--interpolation {
color: #be5046;
}
.syntax--variable.syntax--parameter {
color: #abb2bf;
}
.syntax--string {
color: #98c379;
}
.syntax--string > .syntax--source,
.syntax--string .syntax--embedded {
color: #abb2bf;
}
.syntax--string.syntax--regexp {
color: #56b6c2;
}
.syntax--string.syntax--regexp .syntax--source.syntax--ruby.syntax--embedded {
color: #e5c07b;
}
.syntax--string.syntax--other.syntax--link {
color: #e06c75;
}
.syntax--punctuation.syntax--definition.syntax--comment {
color: #5c6370;
}
.syntax--punctuation.syntax--definition.syntax--method-parameters,
.syntax--punctuation.syntax--definition.syntax--function-parameters,
.syntax--punctuation.syntax--definition.syntax--parameters,
.syntax--punctuation.syntax--definition.syntax--separator,
.syntax--punctuation.syntax--definition.syntax--seperator,
.syntax--punctuation.syntax--definition.syntax--array {
color: #abb2bf;
}
.syntax--punctuation.syntax--definition.syntax--heading,
.syntax--punctuation.syntax--definition.syntax--identity {
color: #61afef;
}
.syntax--punctuation.syntax--definition.syntax--bold {
color: #e5c07b;
font-weight: bold;
}
.syntax--punctuation.syntax--definition.syntax--italic {
color: #c678dd;
font-style: italic;
}
.syntax--punctuation.syntax--section.syntax--embedded {
color: #be5046;
}
.syntax--punctuation.syntax--section.syntax--method,
.syntax--punctuation.syntax--section.syntax--class,
.syntax--punctuation.syntax--section.syntax--inner-class {
color: #abb2bf;
}
.syntax--support.syntax--class {
color: #e5c07b;
}
.syntax--support.syntax--type {
color: #56b6c2;
}
.syntax--support.syntax--function {
color: #56b6c2;
}
.syntax--support.syntax--function.syntax--any-method {
color: #61afef;
}
.syntax--entity.syntax--name.syntax--function {
color: #61afef;
}
.syntax--entity.syntax--name.syntax--class,
.syntax--entity.syntax--name.syntax--type.syntax--class {
color: #e5c07b;
}
.syntax--entity.syntax--name.syntax--section {
color: #61afef;
}
.syntax--entity.syntax--name.syntax--tag {
color: #e06c75;
}
.syntax--entity.syntax--other.syntax--attribute-name {
color: #d19a66;
}
.syntax--entity.syntax--other.syntax--attribute-name.syntax--id {
color: #61afef;
}
.syntax--meta.syntax--class {
color: #e5c07b;
}
.syntax--meta.syntax--class.syntax--body {
color: #abb2bf;
}
.syntax--meta.syntax--method-call,
.syntax--meta.syntax--method {
color: #abb2bf;
}
.syntax--meta.syntax--definition.syntax--variable {
color: #e06c75;
}
.syntax--meta.syntax--link {
color: #d19a66;
}
.syntax--meta.syntax--require {
color: #61afef;
}
.syntax--meta.syntax--selector {
color: #c678dd;
}
.syntax--meta.syntax--separator {
color: #abb2bf;
}
.syntax--meta.syntax--tag {
color: #abb2bf;
}
.syntax--underline {
text-decoration: underline;
}
.syntax--none {
color: #abb2bf;
}
.syntax--invalid.syntax--deprecated {
color: #523d14 !important;
background-color: #e0c285 !important;
}
.syntax--invalid.syntax--illegal {
color: white !important;
background-color: #e05252 !important;
}
.syntax--markup.syntax--bold {
color: #d19a66;
font-weight: bold;
}
.syntax--markup.syntax--changed {
color: #c678dd;
}
.syntax--markup.syntax--deleted {
color: #e06c75;
}
.syntax--markup.syntax--italic {
color: #c678dd;
font-style: italic;
}
.syntax--markup.syntax--heading {
color: #e06c75;
}
.syntax--markup.syntax--heading .syntax--punctuation.syntax--definition.syntax--heading {
color: #61afef;
}
.syntax--markup.syntax--link {
color: #56b6c2;
}
.syntax--markup.syntax--inserted {
color: #98c379;
}
.syntax--markup.syntax--quote {
color: #d19a66;
}
.syntax--markup.syntax--raw {
color: #98c379;
}
.syntax--source.syntax--c .syntax--keyword.syntax--operator {
color: #c678dd;
}
.syntax--source.syntax--cpp .syntax--keyword.syntax--operator {
color: #c678dd;
}
.syntax--source.syntax--cs .syntax--keyword.syntax--operator {
color: #c678dd;
}
.syntax--source.syntax--css .syntax--property-name,
.syntax--source.syntax--css .syntax--property-value {
color: #828997;
}
.syntax--source.syntax--css .syntax--property-name.syntax--support,
.syntax--source.syntax--css .syntax--property-value.syntax--support {
color: #abb2bf;
}
.syntax--source.syntax--elixir .syntax--source.syntax--embedded.syntax--source {
color: #abb2bf;
}
.syntax--source.syntax--elixir .syntax--constant.syntax--language,
.syntax--source.syntax--elixir .syntax--constant.syntax--numeric,
.syntax--source.syntax--elixir .syntax--constant.syntax--definition {
color: #61afef;
}
.syntax--source.syntax--elixir .syntax--variable.syntax--definition,
.syntax--source.syntax--elixir .syntax--variable.syntax--anonymous {
color: #c678dd;
}
.syntax--source.syntax--elixir .syntax--parameter.syntax--variable.syntax--function {
color: #d19a66;
font-style: italic;
}
.syntax--source.syntax--elixir .syntax--quoted {
color: #98c379;
}
.syntax--source.syntax--elixir .syntax--keyword.syntax--special-method,
.syntax--source.syntax--elixir .syntax--embedded.syntax--section,
.syntax--source.syntax--elixir .syntax--embedded.syntax--source.syntax--empty {
color: #e06c75;
}
.syntax--source.syntax--elixir .syntax--readwrite.syntax--module .syntax--punctuation {
color: #e06c75;
}
.syntax--source.syntax--elixir .syntax--regexp.syntax--section,
.syntax--source.syntax--elixir .syntax--regexp.syntax--string {
color: #be5046;
}
.syntax--source.syntax--elixir .syntax--separator,
.syntax--source.syntax--elixir .syntax--keyword.syntax--operator {
color: #d19a66;
}
.syntax--source.syntax--elixir .syntax--variable.syntax--constant {
color: #e5c07b;
}
.syntax--source.syntax--elixir .syntax--array,
.syntax--source.syntax--elixir .syntax--scope,
.syntax--source.syntax--elixir .syntax--section {
color: #828997;
}
.syntax--source.syntax--gfm .syntax--markup {
-webkit-font-smoothing: auto;
}
.syntax--source.syntax--gfm .syntax--link .syntax--entity {
color: #61afef;
}
.syntax--source.syntax--go .syntax--storage.syntax--type.syntax--string {
color: #c678dd;
}
.syntax--source.syntax--ini .syntax--keyword.syntax--other.syntax--definition.syntax--ini {
color: #e06c75;
}
.syntax--source.syntax--java .syntax--storage.syntax--modifier.syntax--import {
color: #e5c07b;
}
.syntax--source.syntax--java .syntax--storage.syntax--type {
color: #e5c07b;
}
.syntax--source.syntax--java .syntax--keyword.syntax--operator.syntax--instanceof {
color: #c678dd;
}
.syntax--source.syntax--java-properties .syntax--meta.syntax--key-pair {
color: #e06c75;
}
.syntax--source.syntax--java-properties .syntax--meta.syntax--key-pair > .syntax--punctuation {
color: #abb2bf;
}
.syntax--source.syntax--js .syntax--keyword.syntax--operator {
color: #56b6c2;
}
.syntax--source.syntax--js .syntax--keyword.syntax--operator.syntax--delete,
.syntax--source.syntax--js .syntax--keyword.syntax--operator.syntax--in,
.syntax--source.syntax--js .syntax--keyword.syntax--operator.syntax--of,
.syntax--source.syntax--js .syntax--keyword.syntax--operator.syntax--instanceof,
.syntax--source.syntax--js .syntax--keyword.syntax--operator.syntax--new,
.syntax--source.syntax--js .syntax--keyword.syntax--operator.syntax--typeof,
.syntax--source.syntax--js .syntax--keyword.syntax--operator.syntax--void {
color: #c678dd;
}
.syntax--source.syntax--ts .syntax--keyword.syntax--operator {
color: #56b6c2;
}
.syntax--source.syntax--flow .syntax--keyword.syntax--operator {
color: #56b6c2;
}
.syntax--source.syntax--json .syntax--meta.syntax--structure.syntax--dictionary.syntax--json > .syntax--string.syntax--quoted.syntax--json {
color: #e06c75;
}
.syntax--source.syntax--json .syntax--meta.syntax--structure.syntax--dictionary.syntax--json > .syntax--string.syntax--quoted.syntax--json > .syntax--punctuation.syntax--string {
color: #e06c75;
}
.syntax--source.syntax--json .syntax--meta.syntax--structure.syntax--dictionary.syntax--json > .syntax--value.syntax--json > .syntax--string.syntax--quoted.syntax--json,
.syntax--source.syntax--json .syntax--meta.syntax--structure.syntax--array.syntax--json > .syntax--value.syntax--json > .syntax--string.syntax--quoted.syntax--json,
.syntax--source.syntax--json .syntax--meta.syntax--structure.syntax--dictionary.syntax--json > .syntax--value.syntax--json > .syntax--string.syntax--quoted.syntax--json > .syntax--punctuation,
.syntax--source.syntax--json .syntax--meta.syntax--structure.syntax--array.syntax--json > .syntax--value.syntax--json > .syntax--string.syntax--quoted.syntax--json > .syntax--punctuation {
color: #98c379;
}
.syntax--source.syntax--json .syntax--meta.syntax--structure.syntax--dictionary.syntax--json > .syntax--constant.syntax--language.syntax--json,
.syntax--source.syntax--json .syntax--meta.syntax--structure.syntax--array.syntax--json > .syntax--constant.syntax--language.syntax--json {
color: #56b6c2;
}
.syntax--ng.syntax--interpolation {
color: #e06c75;
}
.syntax--ng.syntax--interpolation.syntax--begin,
.syntax--ng.syntax--interpolation.syntax--end {
color: #61afef;
}
.syntax--ng.syntax--interpolation .syntax--function {
color: #e06c75;
}
.syntax--ng.syntax--interpolation .syntax--function.syntax--begin,
.syntax--ng.syntax--interpolation .syntax--function.syntax--end {
color: #61afef;
}
.syntax--ng.syntax--interpolation .syntax--bool {
color: #d19a66;
}
.syntax--ng.syntax--interpolation .syntax--bracket {
color: #abb2bf;
}
.syntax--ng.syntax--pipe,
.syntax--ng.syntax--operator {
color: #abb2bf;
}
.syntax--ng.syntax--tag {
color: #56b6c2;
}
.syntax--ng.syntax--attribute-with-value .syntax--attribute-name {
color: #e5c07b;
}
.syntax--ng.syntax--attribute-with-value .syntax--string {
color: #c678dd;
}
.syntax--ng.syntax--attribute-with-value .syntax--string.syntax--begin,
.syntax--ng.syntax--attribute-with-value .syntax--string.syntax--end {
color: #abb2bf;
}
.syntax--source.syntax--ruby .syntax--constant.syntax--other.syntax--symbol > .syntax--punctuation {
color: inherit;
}
.syntax--source.syntax--php .syntax--class.syntax--bracket {
color: #abb2bf;
}
.syntax--source.syntax--python .syntax--keyword.syntax--operator.syntax--logical.syntax--python {
color: #c678dd;
}
.syntax--source.syntax--python .syntax--variable.syntax--parameter {
color: #d19a66;
}
</style>
</head>
<body class='markdown-preview' data-use-github-style><h1 id="d3-js-data-driven-documents"><a href="https://github.com/d3/d3">D3.js Data-Driven Documents</a></h1>
<p>JavaScript biblioteka za vizualizaciju podataka pomoću web standarda. D3 oživljava podatke pomoću SVG-a, Canvas-a i HTML-a. D3 kombinira moćne tehnike vizualizacije i interakcije s pristupom koji se temelji na podacima i manipulaciji DOM-om, pružajući pune mogućnosti modernih preglednika i slobodu dizajniranja pravog vizualnog sučelja za podatke. Prikladan za kreiranje grafova, mapa, ili bilo koje druge reprezentacije podataka.</p>
<p>Za bolje praćenje ovog tutorijala, poželjno je bazično znanje HTML-a, CSS-a, JavaScript-a</p>
<p>Za početak potrebno je uključiti D3.js biblioteku u HTML stranicu</p>
<pre class="editor-colors lang-html"><div class="line"><span class="syntax--source syntax--html"><<span class="syntax--entity syntax--name syntax--tag">script</span> <span class="syntax--entity syntax--other syntax--attribute-name">src</span>="<span class="syntax--string syntax--html">https://d3js.org/d3.v5.min.js</span>"></<span class="syntax--entity syntax--name syntax--tag">script</span>></span></div></pre>
<p>Nakon uključivanja bibiloteke dobiva se pristup globalnom <a href="https://github.com/d3/d3/blob/master/API.md">d3</a> objeku u JavaScript kodu.</p>
<p>Najčešće korišten koncept su <a href="https://github.com/d3/d3-selection/blob/master/README.md#selecting-elements">Selektori</a>. Slično kao i kod JQuery i AngularJs bibiloteka, bazirani su na <a href="https://www.w3.org/TR/selectors-api/">W3C selectors API</a>.</p>
<p>D3 ima dvije metode selekcije: <strong><code style="font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;">select</code></strong> za selekciju jednog <a href="https://www.w3schools.com/jsref/dom_obj_all.asp">DOM elementa</a> i <strong><code style="font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;">selectAll</code></strong> za višestruku selekciju.</p>
<blockquote>
<p>Selektori se mogu ulančavati. Na primjer, može se selektirati svu djecu <em>div</em> elementa čiji je <strong>id</strong> <strong><code style="font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;">container</code></strong></p>
</blockquote>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// selektiraj dom element sa id-jem container</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// te zatim selektiraj svu div djecu tog elementa</span></span></div><div class="line"><span class="syntax--source syntax--js">d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">select</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"#container"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">selectAll</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"div"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div></pre>
<p>Neki od jednostavnih selektora su sljedeći</p>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js">d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">select</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"tag"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--comment syntax--block">// gdje je tag ime tag-a DOM elementa, kao što su bodi ili div</span></span></div><div class="line"><span class="syntax--source syntax--js">d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">select</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"#id"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--comment syntax--block">// gdje id reprezentira točno odreženi DOM element</span></span></div><div class="line"><span class="syntax--source syntax--js">d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">select</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">".class"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--comment syntax--block">// gdje je class CSS klasa DOM elementa</span></span></div></pre>
<p>Nakon selekcije elemenata, na njima se obavljaju razne operacije kao što su mijenjanje svojstava (CSS klasa i stilova, textova, itd.).</p>
<h3 id="primjer-kori-tenja-selektora-select">Primjer korištenja selektora select</h3>
<p>Uzmimo da imamo sljedeći DOM element u HTML stranici</p>
<pre class="editor-colors lang-html"><div class="line"><span class="syntax--source syntax--html"><<span class="syntax--entity syntax--name syntax--tag">div</span> <span class="syntax--entity syntax--other syntax--attribute-name">id</span>="<span class="syntax--string syntax--html">select-div</span>"></span></div><div class="line"><span class="syntax--source syntax--html"></<span class="syntax--entity syntax--name syntax--tag">div</span>></span></div></pre>
<p>naredni kod tada selektira <em>div</em> prema id-u, te mijenja njegovu pozadinu u plavu boju</p>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js">d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">select</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"#select-div"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">style</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"background-color"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"#039BE5"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div></pre>
<h3 id="primjer-kori-tenja-selektora-selectall">Primjer korištenja selektora selectAll</h3>
<p>Uzmimo da imamo sljedeće DOM elemente u HTML stranici</p>
<pre class="editor-colors lang-html"><div class="line"><span class="syntax--source syntax--html"><<span class="syntax--entity syntax--name syntax--tag">div</span> <span class="syntax--entity syntax--other syntax--attribute-name">class</span>="<span class="syntax--string syntax--html">select-all-div</span>"> Div #1 </<span class="syntax--entity syntax--name syntax--tag">div</span>></span></div><div class="line"><span class="syntax--source syntax--html"><<span class="syntax--entity syntax--name syntax--tag">div</span> <span class="syntax--entity syntax--other syntax--attribute-name">class</span>="<span class="syntax--string syntax--html">select-all-div</span>"> Div #2 </<span class="syntax--entity syntax--name syntax--tag">div</span>></span></div><div class="line"><span class="syntax--source syntax--html"><<span class="syntax--entity syntax--name syntax--tag">div</span> <span class="syntax--entity syntax--other syntax--attribute-name">class</span>="<span class="syntax--string syntax--html">select-all-div</span>"> Div #3 </<span class="syntax--entity syntax--name syntax--tag">div</span>></span></div></pre>
<p>naredni kod tada mijenja pozadinu elementi u nasumičnu boju, na način da dohvati sve elemente sa CSS klasom <strong><code style="font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;">select-all-div</code></strong> te za svaku od njih poziva funkciju koja dinamički nasumično računa pozadinsku boju</p>
<p>Parametri za funkciju su sljedeći:</p>
<blockquote>
<p><strong><code style="font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;">d</code></strong> - podaci (eng. data) - koji se mogu predati selekciji - više u nastavku</p>
</blockquote>
<blockquote>
<p><strong><code style="font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;">i</code></strong> - index trenutnog elementa, počevši od nule</p>
</blockquote>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js">d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">selectAll</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">".select-all-div"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">style</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"background-color"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span> <span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--comma">,</span> i<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--keyword syntax--control">return</span> <span class="syntax--string syntax--quoted">"hsl("</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--meta syntax--class">Math</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">random</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--keyword syntax--operator syntax--js">*</span> <span class="syntax--constant syntax--numeric">360</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--string syntax--quoted">","</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--constant syntax--numeric">10</span> <span class="syntax--keyword syntax--operator syntax--js">*</span> <span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>i <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--constant syntax--numeric">1</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--string syntax--quoted">"%,50%)"</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div></pre>
<h3 id="koncept-ulaz-a-uriranje-izlaz">Koncept Ulaz/Ažuriranje/Izlaz</h3>
<p>D3.js omogućuje povezivanje podataka s selekcijom pomoću funkcije podataka i dinamičkih vrijednosti.</p>
<p>U sljedećem primjeru ažuriraju se svi elementi sa klasom <strong><code style="font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;">.item</code></strong> <em>DIV</em>-ovi sadržani u roditelju sa klasom <strong><code style="font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;">.selection</code></strong>.</p>
<p>Primjer html-a</p>
<pre class="editor-colors lang-html"><div class="line"><span class="syntax--source syntax--html"><<span class="syntax--entity syntax--name syntax--tag">div</span> <span class="syntax--entity syntax--other syntax--attribute-name">class</span>="<span class="syntax--string syntax--html">selection</span>"></span></div><div class="line"><span class="syntax--source syntax--html"><span class="leading-whitespace"> </span><<span class="syntax--entity syntax--name syntax--tag">div</span> <span class="syntax--entity syntax--other syntax--attribute-name">class</span>="<span class="syntax--string syntax--html">item</span>">1</<span class="syntax--entity syntax--name syntax--tag">div</span>></span></div><div class="line"><span class="syntax--source syntax--html"><span class="leading-whitespace"> </span><<span class="syntax--entity syntax--name syntax--tag">div</span> <span class="syntax--entity syntax--other syntax--attribute-name">class</span>="<span class="syntax--string syntax--html">item</span>">2</<span class="syntax--entity syntax--name syntax--tag">div</span>></span></div><div class="line"><span class="syntax--source syntax--html"><span class="leading-whitespace"> </span><<span class="syntax--entity syntax--name syntax--tag">div</span> <span class="syntax--entity syntax--other syntax--attribute-name">class</span>="<span class="syntax--string syntax--html">item</span>">3</<span class="syntax--entity syntax--name syntax--tag">div</span>></span></div><div class="line"><span class="syntax--source syntax--html"></<span class="syntax--entity syntax--name syntax--tag">div</span>></span></div></pre>
<p>Prilikom selekcije elemenata postavljaju se predefinirane vrijednosti pomoću funkcije <strong><code style="font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;">data</code></strong>. Prilikom postavljanja pozadinske boje za trenutni element u funkciji se dobiva jedan od elemenata predanih <strong><code style="font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;">data</code></strong> funkciji, ovisno o poziciji trenutnog elementa.</p>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js">d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">select</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">".selection"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">selectAll</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">".item"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">data</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--array syntax--begin syntax--bracket syntax--square">[</span><span class="syntax--string syntax--quoted">"#039BE5"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"#00897B"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"#00ACC1"</span><span class="syntax--punctuation syntax--definition syntax--array syntax--end syntax--bracket syntax--square">]</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">style</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"background-color"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span> <span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--keyword syntax--control">return</span> d<span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div></pre>
<blockquote>
<p>Ukoliko je predano više podataka nego što ima elemenata, ti su podaci jednostavno zanemareni. Isto vrijedi i u suprotnom. Ako ima manje podataka nego elemenata u selekciji, višak selekcije je zanemaren.</p>
</blockquote>
<p>Ako imamo slučaj nejednakog broja podataka i selektiranih elemenata onda u tom slučaju možemo dodavati/brisati elemente.</p>
<p>Dodavanje elemenata:</p>
<p>Za kreiranje novog DOM elementa koristi se <strong><code style="font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;">enter()</code></strong> funkcija koja manipulira sa podacima koji ulaze u selekciju.</p>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// selekcija spremljena u div variablu</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> div <span class="syntax--keyword syntax--operator syntax--js">=</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">select</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">".selection"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">selectAll</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">".item"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">data</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--array syntax--begin syntax--bracket syntax--square">[</span><span class="syntax--string syntax--quoted">"#039BE5"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"#00897B"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"#00ACC1"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span><span class="syntax--string syntax--quoted">"#C7254E"</span><span class="syntax--punctuation syntax--definition syntax--array syntax--end syntax--bracket syntax--square">]</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// za elemente koji ulaze</span></span></div><div class="line"><span class="syntax--source syntax--js">div<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">enter</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// dodaj div element u selekciju</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"div"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// postavi njegovu CSS klasu na item</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">classed</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"item"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--constant syntax--language syntax--boolean syntax--true">true</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// postavi text novog elementa na index + 1</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">text</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span> <span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--comma">,</span> i<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--keyword syntax--control">return</span> i <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--constant syntax--numeric">1</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// animarija tranzicije</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">transition</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// koja traje 0.5 sekunde</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">duration</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--constant syntax--numeric">500</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// ažuriraj svaki novi element sa novom pozadinskom bojom</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">style</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"background-color"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span> <span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--keyword syntax--control">return</span> d<span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// također potrebno je ažurirati i sve postojeće elemente</span></span></div><div class="line"><span class="syntax--source syntax--js">div<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">transition</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">duration</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--constant syntax--numeric">500</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">style</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"background-color"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span> <span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--keyword syntax--control">return</span> d<span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div></pre>
<p>Brisanje elemenata:</p>
<p>Za brisanje viška DOM elementa koristi se <strong><code style="font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;">exit()</code></strong> funkcija koja manipulira sa podacima koji izlaze iz selekcije.</p>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// selekcija spremljena u div variablu</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> div <span class="syntax--keyword syntax--operator syntax--js">=</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">select</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">".selection"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">selectAll</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">".item"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">data</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--array syntax--begin syntax--bracket syntax--square">[</span><span class="syntax--string syntax--quoted">"#039BE5"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"#00897B"</span><span class="syntax--punctuation syntax--definition syntax--array syntax--end syntax--bracket syntax--square">]</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// izbrisi sve elemente koji izlaze iz selekcije</span></span></div><div class="line"><span class="syntax--source syntax--js">div<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">exit</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">remove</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// i naravno potrebno je ažurirati postojeće elemente</span></span></div><div class="line"><span class="syntax--source syntax--js">div<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">transition</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">duration</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--constant syntax--numeric">500</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">style</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"background-color"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span> <span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--keyword syntax--control">return</span> d<span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div></pre>
<h4 id="primjer">Primjer</h4>
<p>U sljedećem primjeru prikazano dodavanje novog svg elementa u body element, te generiranje i dodavanje krugova u taj svg</p>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// dimenzije prikaza</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> width <span class="syntax--keyword syntax--operator syntax--js">=</span> <span class="syntax--constant syntax--numeric">960</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>height <span class="syntax--keyword syntax--operator syntax--js">=</span> <span class="syntax--constant syntax--numeric">400</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// selekcijom dohvati element body</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> svg <span class="syntax--keyword syntax--operator syntax--js">=</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">select</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"body"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// na njega dodaj novi element svg</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"svg"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// te postavi dimenzije tog svg elementa</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"width"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> width<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"height"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> height<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// generiraj raspon od 200 brojeva</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> nodes <span class="syntax--keyword syntax--operator syntax--js">=</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">range</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--constant syntax--numeric">200</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// mapiraj svaki broj kao element sa poljem radius koji se računa nasumično</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">map</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--keyword syntax--control">return</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span><span class="syntax--variable syntax--other syntax--object syntax--property">radius</span><span class="syntax--keyword syntax--operator syntax--js">:</span> <span class="syntax--meta syntax--class">Math</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">random</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--keyword syntax--operator syntax--js">*</span> <span class="syntax--constant syntax--numeric">12</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--constant syntax--numeric">4</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// prvvi čvor je korijen čija će pozicija odgovarati poziciji kurzora na ekranu</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>root <span class="syntax--keyword syntax--operator syntax--js">=</span> nodes<span class="syntax--punctuation syntax--definition syntax--array syntax--begin syntax--bracket syntax--square">[</span><span class="syntax--constant syntax--numeric">0</span><span class="syntax--punctuation syntax--definition syntax--array syntax--end syntax--bracket syntax--square">]</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// skala boja</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>color <span class="syntax--keyword syntax--operator syntax--js">=</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">scaleOrdinal</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">schemeCategory10</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// korijen nema radius te na njega ne djeluju nikakve sile</span></span></div><div class="line"><span class="syntax--source syntax--js">root<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">radius</span> <span class="syntax--keyword syntax--operator syntax--js">=</span> <span class="syntax--constant syntax--numeric">0</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js">root<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">fixed</span> <span class="syntax--keyword syntax--operator syntax--js">=</span> <span class="syntax--constant syntax--language syntax--boolean syntax--true">true</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// napravi selekciju na sve elemente circle</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// naravno elemenata još nema</span></span></div><div class="line"><span class="syntax--source syntax--js">svg<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">selectAll</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"circle"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// podaci su svi čvorovi osim prvog(korijena)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">data</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>nodes<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">slice</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--constant syntax--numeric">1</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// za sve elemente koji ulaze</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">enter</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// dodaj novi element cricle</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"circle"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// postavi atribut r na radius čvora iz kolekcije predane data funkciji</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"r"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">radius</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// ispuni krug sa jednom od prvih 3 boje iz prije definirane palete boja</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">style</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"fill"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--comma">,</span> i<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> <span class="syntax--entity syntax--name syntax--function">color</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>i <span class="syntax--keyword syntax--operator syntax--js">%</span> <span class="syntax--constant syntax--numeric">3</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// kreiranje nove simulacije generiranih čvorova</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> force <span class="syntax--keyword syntax--operator syntax--js">=</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">forceSimulation</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>nodes<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// vrijednost između 0 i 1 koja reprezentira preostalo vrijeme izvođenja simulacije</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">alpha</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--constant syntax--numeric">0.3</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// za svaki čvor postavi naboj - svi čvorovi imaj naboj -15 osim nultog čvora, odnosno korijena koji ima naboj -2000</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// negativan naboj znači da će se čvorovi odbijati, što je veća vrijednost veće je odbijanje</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// cilj je da se svi čvorovi jako odbijaju od korijena</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">force</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"charge"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">forceManyBody</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">strength</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--comma">,</span> i<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span><span class="syntax--keyword syntax--control">return</span> i <span class="syntax--keyword syntax--operator syntax--js">?</span> <span class="syntax--keyword syntax--operator syntax--js">-</span><span class="syntax--constant syntax--numeric">15</span> <span class="syntax--keyword syntax--operator syntax--js">:</span> <span class="syntax--keyword syntax--operator syntax--js">-</span><span class="syntax--constant syntax--numeric">2000</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// forsiraj sve čvorove prema sredini svg elementa</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">force</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">'center'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">forceCenter</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>width <span class="syntax--keyword syntax--operator syntax--js">/</span> <span class="syntax--constant syntax--numeric">2</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> height <span class="syntax--keyword syntax--operator syntax--js">/</span> <span class="syntax--constant syntax--numeric">2</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// nemoj primjenjivati sile ni po x ni po y osim</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">force</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"x"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">forceX</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span><span class="syntax--keyword syntax--control">return</span> <span class="syntax--constant syntax--numeric">0</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">force</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"y"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">forceY</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span><span class="syntax--keyword syntax--control">return</span> <span class="syntax--constant syntax--numeric">0</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// svi čvorovi se mogu sudarati jedni s drugima te je radius u kojem se čvorovi sudaraju zaparavo radius čvora</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">force</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">'collision'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">forceCollide</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">radius</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--keyword syntax--control">return</span> d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">radius</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// registriraj slušač na svaku iteraciju tajmera simulacije</span></span></div><div class="line"><span class="syntax--source syntax--js">force<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">on</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"tick"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>e<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// zato što je pri definiranju simulacije definirano</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// kako se čvorovi grupiraju u sredini te</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// kako se odbijaju jedan od drugog za -15 te svi od korijena za -2000</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// i kako se čvorovi sudaraju međusobno (nemogu pregaziti jedan drugog)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// dovoljno je samo ažurirati pozicije svih krugova u svg elementu</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// zato što se sve operacije računanja koordinata izvšavaju u samoj simulaciji prema zadanim parametrima</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>svg<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">selectAll</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"circle"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"cx"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">x</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"cy"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">y</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// regist slušač na pokrete kurzora unutar svg elementa</span></span></div><div class="line"><span class="syntax--source syntax--js">svg<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">on</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"mousemove"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// dohvati trenutnu poziciju kurzora</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--storage syntax--type">var</span> p1 <span class="syntax--keyword syntax--operator syntax--js">=</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">mouse</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>this<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// postavi korijen na trenutnu poziciju kurzora</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// zato što korijen ima jako velik negativan naboj i nalazi se na istoj pozziciji kao i kurzor</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// stvara se osjećaj kako se svi čvorovi odbijaju od kurzora</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>root<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">x</span> <span class="syntax--keyword syntax--operator syntax--js">=</span> p1<span class="syntax--punctuation syntax--definition syntax--array syntax--begin syntax--bracket syntax--square">[</span><span class="syntax--constant syntax--numeric">0</span><span class="syntax--punctuation syntax--definition syntax--array syntax--end syntax--bracket syntax--square">]</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>root<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">y</span> <span class="syntax--keyword syntax--operator syntax--js">=</span> p1<span class="syntax--punctuation syntax--definition syntax--array syntax--begin syntax--bracket syntax--square">[</span><span class="syntax--constant syntax--numeric">1</span><span class="syntax--punctuation syntax--definition syntax--array syntax--end syntax--bracket syntax--square">]</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// simulacija po default-u završava za 300 iteracija</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// zato je potrebno "resetirati" preostali broj iteracija simulacije</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>force<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">alpha</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--constant syntax--numeric">0.3</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div></pre>
<div id="circle_container">
<script>
document.addEventListener("DOMContentLoaded", function(e) {
var width = 960,
height = 400;
var svg = d3.select("#circle_container")
.append("svg")
.attr("width", width)
.attr("height", height);
var nodes = d3.range(200)
.map(function() {
return {radius: Math.random() * 12 + 4};
}),
root = nodes[0],
color = d3.scaleOrdinal(d3.schemeCategory10);
root.radius = 0;
root.fixed = true;
svg.selectAll("circle")
.data(nodes.slice(1))
.enter().append("circle")
.attr("r", function(d) { return d.radius; })
.style("fill", function(d, i) { return color(i % 3); });
var force = d3.forceSimulation(nodes)
.alpha(0.3)
.force("charge", d3.forceManyBody().strength(function(d, i){return i ? -15 : -2000}))
.force('center', d3.forceCenter(width / 2, height / 2))
.force("x", d3.forceX(function(){return 0}))
.force("y", d3.forceY(function(){return 0}))
.force('collision', d3.forceCollide().radius(function(d) {
return d.radius
}));
force.on("tick", function(e) {
svg.selectAll("circle")
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; });
});
svg.on("mousemove", function() {
var p1 = d3.mouse(this);
root.x = p1[0];
root.y = p1[1];
force.alpha(0.3);
});
svg.on("mouseover", function(){
force.restart();
})
});
</script>
</div>
<h3 id="grafovi">Grafovi</h3>
<h4 id="stup-asti-graf">Stupčasti graf</h4>
<p>Pretpostavimo da imamo sljedeće podatke zapisane u csv datoteci</p>
<table>
<thead>
<tr>
<th>year</th>
<th>value</th>
</tr>
</thead>
<tbody>
<tr>
<td>2011</td>
<td>45</td>
</tr>
<tr>
<td>2012</td>
<td>47</td>
</tr>
<tr>
<td>2013</td>
<td>52</td>
</tr>
<tr>
<td>2014</td>
<td>70</td>
</tr>
<tr>
<td>2016</td>
<td>78</td>
</tr>
<tr>
<td>2015</td>
<td>75</td>
</tr>
</tbody>
</table>
<p>Kao i uvijek potrebno je dodati novi svg element ili selektirati postojeći</p>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// dimenzije prikaza</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> width <span class="syntax--keyword syntax--operator syntax--js">=</span> <span class="syntax--constant syntax--numeric">960</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>height <span class="syntax--keyword syntax--operator syntax--js">=</span> <span class="syntax--constant syntax--numeric">400</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">//margina oko grafa</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>margin <span class="syntax--keyword syntax--operator syntax--js">=</span> <span class="syntax--constant syntax--numeric">200</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// selekcijom dohvati element body</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> svg <span class="syntax--keyword syntax--operator syntax--js">=</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">select</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"body"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// na njega dodaj novi element svg</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"svg"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// te postavi dimenzije tog svg elementa</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"width"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> width<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"height"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> height<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// smanji visinu i širinu za iznos margine</span></span></div><div class="line"><span class="syntax--source syntax--js">width <span class="syntax--keyword syntax--operator syntax--js">-=</span> margin<span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js">height <span class="syntax--keyword syntax--operator syntax--js">-=</span> margin<span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div></pre>
<p>Nakon toga potrebno je kreirati skale za x i y os. Sljedeći kod prikazuje način kreiranja raspona vrijednosti za svaku od osi.</p>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// kreira se diskretna skala sa rasponom od 0 do duljine grafa</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// sa funkcijom padding dodaje se razmak između stupaca</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> xScale <span class="syntax--keyword syntax--operator syntax--js">=</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">scaleBand</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">range</span> <span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--array syntax--begin syntax--bracket syntax--square">[</span><span class="syntax--constant syntax--numeric">0</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> width<span class="syntax--punctuation syntax--definition syntax--array syntax--end syntax--bracket syntax--square">]</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">padding</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--constant syntax--numeric">0.4</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// kreira se linearna skala koja će prikazivati cijene</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// u rasponu visine grafa</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>yScale <span class="syntax--keyword syntax--operator syntax--js">=</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">scaleLinear</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">range</span> <span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--array syntax--begin syntax--bracket syntax--square">[</span>height<span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--constant syntax--numeric">0</span><span class="syntax--punctuation syntax--definition syntax--array syntax--end syntax--bracket syntax--square">]</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div></pre>
<p>Na svg element dodaje se element g u koji će se dodati x i y osi i stupci grafa</p>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// na svg element dodaj novi element g (group)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> g <span class="syntax--keyword syntax--operator syntax--js">=</span> svg<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"g"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">//CSS attribut kako bi se graf pozicionirao sa marginom</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"transform"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"translate("</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--constant syntax--numeric">100</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--string syntax--quoted">","</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--constant syntax--numeric">100</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--string syntax--quoted">")"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div></pre>
<p>Sljedeći korak je učitavanje podataka sa servera (u ovom primjeru iz csv datoteke)</p>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// čitaj csv datoteku "data.csv"</span></span></div><div class="line"><span class="syntax--source syntax--js">d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">csv</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"data.csv"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// ako je pronađena i uspješno pročitana</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">then</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>data<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// radi sa podacima</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// uhvati i obradi grešku</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">catch</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>error<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">throw</span> error<span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div></pre>
<p>Dohvaćeni podaci koriste se za izgradnju grafa. Variabla <strong><code style="font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;">data</code></strong> predstavlja referencu na kolekciju podataka pročitanih iz csv datoteke.</p>
<p>Nakon što su podaci učitani, na x i y osi postavljamo vrijednosti domena.</p>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// na skalu x osi postavi sve godine</span></span></div><div class="line"><span class="syntax--source syntax--js">xScale<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">domain</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>data<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">map</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">year</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// na skalu y osi postavi raspon od 0 do maximalne vrijednosti u podacima</span></span></div><div class="line"><span class="syntax--source syntax--js">yScale<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">domain</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--array syntax--begin syntax--bracket syntax--square">[</span><span class="syntax--constant syntax--numeric">0</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">max</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>data<span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--array syntax--end syntax--bracket syntax--square">]</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div></pre>
<p>Nakon postavljanja vrijednosti skala, dodaj ih u graf.
Najprije se u prethodno kreirani element g dodaj novi element g koji će sadržavati x i y osi.</p>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// dodaj novi element g</span></span></div><div class="line"><span class="syntax--source syntax--js">g<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"g"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// koristi CSS svojstvo kako bi pozicionirao x os prema dnu svg-a</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"transform"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"translate(0,"</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> height <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--string syntax--quoted">")"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// dodaj skalu u novi g element</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">call</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">axisBottom</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>xScale<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// dodaj novi element g</span></span></div><div class="line"><span class="syntax--source syntax--js">g<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"g"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// dodaj skalu u novi g element</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">call</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">axisLeft</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>y<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// zato što y os prikazuje vrijednost onda definiraj vlastiti format labela prikazanih na y osi</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">tickFormat</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> <span class="syntax--string syntax--quoted">"$"</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> d<span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// ograniči broj prikazanih vrijednosti labela y osi</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">ticks</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--constant syntax--numeric">10</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"></div></pre>
<p>Sljedeći korak je dodavanje podataka u graf.
Sljedeći isječak prikazuje prikaz podataka dohvaćenih prije prikazanom metodom čitanja csv datoteke.</p>
<pre class="editor-colors lang-js"><div class="line"><span class="leading-whitespace"> </span><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// napravi selekciju na sve elemente sa style klasom bar</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>g<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">selectAll</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">".bar"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// kao podatke prenesi podatke pročitane iz csv datoteke</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">data</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>data<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// za sve podakte koji ne postoje (za sve nove elemente)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">enter</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// dodaj novi element rect(pravokutnik)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"rect"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// postavi style klasu novog rect elementa na bar</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"class"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"bar"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// svaki bar postavlja na pripadajuću x i y poziciju</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"x"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> <span class="syntax--entity syntax--name syntax--function">xScale</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">year</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"y"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> <span class="syntax--entity syntax--name syntax--function">yScale</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// širina stupaca određena je scaleBand() funkciom.</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// Stoga, x skala vraća izračunatu širinu iz raspona(range) i paddinga predanih x skali</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"width"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> xScale<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">bandwidth</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// visina stupaca je izračunata kao visina yScale(d.value).</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// To jest visina svg-a minus trenutna y vrijednost stupca sa y skale.</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// Napomena: y vrijednost je vrh stupca</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"height"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> height <span class="syntax--keyword syntax--operator syntax--js">-</span> <span class="syntax--entity syntax--name syntax--function">yScale</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div></pre>
<p>Nakon što su podaci dodani u graf potrebno je te podatke označiti labelama.
Labele se u graf dodaje dodavanjem text elemenata u svg.</p>
<p>Sljedeći isječak prikazuje dodavanje naslova, te labela za x i y os</p>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// Naslov</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// dodaj novi text element u svg</span></span></div><div class="line"><span class="syntax--source syntax--js">svg<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"text"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// postavi css svojstvo transform</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"transform"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"translate(100,0)"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// postavi ga na poziciju 50, 50</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"x"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--constant syntax--numeric">50</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"y"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--constant syntax--numeric">50</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// povećaj veličinu fonta</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"font-size"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"24px"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// postavi stvarni tekst koji će element prikazivati</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">text</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"CSV Foods Stock Price"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// x-os</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// nadovezujemo se na prije objašnjen kod za dodavanje x skale</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>g<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"g"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"transform"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"translate(0,"</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> height <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--string syntax--quoted">")"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">call</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">axisBottom</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>xScale<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// na postojeću x skalu dodaj novi text element</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"text"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// postavi x i y poziciju</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"y"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> height <span class="syntax--keyword syntax--operator syntax--js">-</span> <span class="syntax--constant syntax--numeric">250</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"x"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> width <span class="syntax--keyword syntax--operator syntax--js">-</span> <span class="syntax--constant syntax--numeric">100</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// postavi css svojstva</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"text-anchor"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"end"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"stroke"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"black"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// postavi tekst koji će se prikazivati</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">text</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"Year"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// y-os</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// nadovezujemo se na prije objašnjen kod za dodavanje y skale</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>g<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"g"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">call</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">axisLeft</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>yScale<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">tickFormat</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--keyword syntax--control">return</span> <span class="syntax--string syntax--quoted">"$"</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> d<span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">ticks</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--constant syntax--numeric">10</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">//na postojeću y skalu dodaj novi text element</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"text"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// rotiraj text za 90 stupnjeva obrnuto smjera kazaljke</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"transform"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"rotate(-90)"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// postavi y poziciju</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"y"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--constant syntax--numeric">6</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// postavi css svojstva</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"dy"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"-5.1em"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"text-anchor"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"end"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"stroke"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"black"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// postavi tekst koji će se prikazivati</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">text</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"Stock Price"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div></pre>
<p>Statički graf u današnje vrijeme je dosta dosadan. Potrebno je napraviti različite animacije kako bi korisniku bio zanimljviji.</p>
<p>Sljedeći isječak prikazuje dodavanje animacija na prethodno kreiran graf. Konkretno, registriraju se slušači za pokrete miša preko stupaca grafa.</p>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// kod za kreiranje grafa prije objašnjen</span></span></div><div class="line"><span class="syntax--source syntax--js">g<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">selectAll</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">".bar"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">data</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>data<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">enter</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"rect"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"class"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"bar"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"x"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> <span class="syntax--entity syntax--name syntax--function">x</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">year</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"y"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> <span class="syntax--entity syntax--name syntax--function">y</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"width"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> x<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">bandwidth</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"height"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> height <span class="syntax--keyword syntax--operator syntax--js">-</span> <span class="syntax--entity syntax--name syntax--function">y</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// kada korisnik mišem uđe unutar granica novog elementa rect pozovi funkciju onMouseOver</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">on</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"mouseover"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> onMouseOver<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// kada korisnik mišem iziđe izvan granica novog elementa rect pozovi funkciju onMouseOut</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">on</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"mouseout"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> onMouseOut<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// animiraj dodavanje novih elemenata tranzicijom</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">transition</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// linearno pojavljivanje novih elemenata</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">ease</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">easeLinear</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// u trajanju od 400 milisekundi</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">duration</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--constant syntax--numeric">400</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// odgodi svako sljedeće dodavanje novog elementa za 50 milisekundi</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">delay</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span> <span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--comma">,</span> i<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--keyword syntax--control">return</span> i <span class="syntax--keyword syntax--operator syntax--js">*</span> <span class="syntax--constant syntax--numeric">50</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div></pre>
<p>Slušač <strong><code style="font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;">onMouseOver</code></strong> povećava širinu i visinu stupca te mijenja boju stupca u narančastu. Također se prikazuje i y vrijednost stupca kao tekst.</p>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// funkcija prima parametre</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// @d = podaci vezani za element</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// @i = index elementa</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type syntax--function">function</span> <span class="syntax--entity syntax--name syntax--function">onMouseOver</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--comma">,</span> i<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// odaberi trenutni element za koji je pozvan ovaj slušač</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">select</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>this<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// postavi mu style klasu highlight</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">'class'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">'highlight'</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// animacija tranzicije</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">transition</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// u trajanju od 400 milisekundi</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">duration</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--constant syntax--numeric">400</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// povećaj širinu za 5 pixela</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">'width'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> xScale<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">bandwidth</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--constant syntax--numeric">5</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// povećaj visinu za 10 pixela</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"height"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> height <span class="syntax--keyword syntax--operator syntax--js">-</span> <span class="syntax--entity syntax--name syntax--function">yScale</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--constant syntax--numeric">10</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// pomakni y poziciju grafa 10 prema dolje</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"y"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> <span class="syntax--entity syntax--name syntax--function">yScale</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--keyword syntax--operator syntax--js">-</span> <span class="syntax--constant syntax--numeric">10</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// na g element dodaj novi text element</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>g<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"text"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// dodaj style klasu val</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">'class'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">'val'</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// x pozicija je ista kao i kod stupca</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">'x'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--keyword syntax--control">return</span> <span class="syntax--entity syntax--name syntax--function">xScale</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">year</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// y pozicija elementa je za 15 pixela manja od vrha</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">'y'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--keyword syntax--control">return</span> <span class="syntax--entity syntax--name syntax--function">yScale</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--keyword syntax--operator syntax--js">-</span> <span class="syntax--constant syntax--numeric">15</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// u tekst postavi vrijednost</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">text</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--keyword syntax--control">return</span> <span class="syntax--punctuation syntax--definition syntax--array syntax--begin syntax--bracket syntax--square">[</span> <span class="syntax--string syntax--quoted">'$'</span> <span class="syntax--keyword syntax--operator syntax--js">+</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--definition syntax--array syntax--end syntax--bracket syntax--square">]</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span></span></div></pre>
<p>Slušač <strong><code style="font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;">onMouseOut</code></strong> poništava sve napravljene promjene.</p>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// funkcija prima parametre</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// @d = podaci vezani za element</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// @i = index elementa</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type syntax--function">function</span> <span class="syntax--entity syntax--name syntax--function">onMouseOut</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--comma">,</span> i<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// odaberi trenutni element za koji je pozvan ovaj slušač</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">select</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>this<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// vrati natrag style klasu bar</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">'class'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">'bar'</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// animacija tranzicije</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">transition</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// u trajanju od 400 milisekundi</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">duration</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--constant syntax--numeric">400</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// postavi širinu na početnu širinu</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">'width'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> xScale<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">bandwidth</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// postavi visinu na početnu vrijednost</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"height"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> height <span class="syntax--keyword syntax--operator syntax--js">-</span> <span class="syntax--entity syntax--name syntax--function">yScale</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// vrati y poziciju na početnu vrijednost</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"y"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> <span class="syntax--entity syntax--name syntax--function">yScale</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// odaberi text element koji je prikazivao vrijednost stupaca</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">selectAll</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">'.val'</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// izbrisi sve odabrane elemente</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">remove</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span></span></div></pre>
<p>Konačni kod za primjer stupčastog grafa je sljedeći:</p>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> width <span class="syntax--keyword syntax--operator syntax--js">=</span> <span class="syntax--constant syntax--numeric">960</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>height <span class="syntax--keyword syntax--operator syntax--js">=</span> <span class="syntax--constant syntax--numeric">400</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>margin <span class="syntax--keyword syntax--operator syntax--js">=</span> <span class="syntax--constant syntax--numeric">200</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> svg <span class="syntax--keyword syntax--operator syntax--js">=</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">select</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"body"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"svg"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"width"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> width<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"height"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> height<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js">width <span class="syntax--keyword syntax--operator syntax--js">-=</span> margin<span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js">height <span class="syntax--keyword syntax--operator syntax--js">-=</span> margin<span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> xScale <span class="syntax--keyword syntax--operator syntax--js">=</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">scaleBand</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">range</span> <span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--array syntax--begin syntax--bracket syntax--square">[</span><span class="syntax--constant syntax--numeric">0</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> width<span class="syntax--punctuation syntax--definition syntax--array syntax--end syntax--bracket syntax--square">]</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">padding</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--constant syntax--numeric">0.4</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>yScale <span class="syntax--keyword syntax--operator syntax--js">=</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">scaleLinear</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">range</span> <span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--array syntax--begin syntax--bracket syntax--square">[</span>height<span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--constant syntax--numeric">0</span><span class="syntax--punctuation syntax--definition syntax--array syntax--end syntax--bracket syntax--square">]</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> g <span class="syntax--keyword syntax--operator syntax--js">=</span> svg<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"g"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"transform"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"translate("</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--constant syntax--numeric">100</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--string syntax--quoted">","</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--constant syntax--numeric">100</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--string syntax--quoted">")"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js">d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">csv</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"data.csv"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">then</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>data<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>xScale<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">domain</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>data<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">map</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">year</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>yScale<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">domain</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--array syntax--begin syntax--bracket syntax--square">[</span><span class="syntax--constant syntax--numeric">0</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">max</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>data<span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--array syntax--end syntax--bracket syntax--square">]</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>g<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"g"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"transform"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"translate(0,"</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> height <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--string syntax--quoted">")"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">call</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">axisBottom</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>xScale<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"text"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"y"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> height <span class="syntax--keyword syntax--operator syntax--js">-</span> <span class="syntax--constant syntax--numeric">250</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"x"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> width <span class="syntax--keyword syntax--operator syntax--js">-</span> <span class="syntax--constant syntax--numeric">100</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"text-anchor"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"end"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"stroke"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"black"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">text</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"Year"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>g<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"g"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">call</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">axisLeft</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>yScale<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">tickFormat</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> <span class="syntax--string syntax--quoted">"$"</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> d<span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">ticks</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--constant syntax--numeric">10</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"text"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"transform"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"rotate(-90)"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"y"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--constant syntax--numeric">6</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"dy"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"-5.1em"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"text-anchor"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"end"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"stroke"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"black"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">text</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"Stock Price"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>g<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">selectAll</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">".bar"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">data</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>data<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">enter</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"rect"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"class"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"bar"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"x"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> <span class="syntax--entity syntax--name syntax--function">xScale</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">year</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"y"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> <span class="syntax--entity syntax--name syntax--function">yScale</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"width"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> xScale<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">bandwidth</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"height"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> height <span class="syntax--keyword syntax--operator syntax--js">-</span> <span class="syntax--entity syntax--name syntax--function">yScale</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">on</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"mouseover"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> onMouseOver<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">on</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"mouseout"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> onMouseOut<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">transition</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">ease</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">easeLinear</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">duration</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--constant syntax--numeric">400</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">delay</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span> <span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--comma">,</span> i<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--keyword syntax--control">return</span> i <span class="syntax--keyword syntax--operator syntax--js">*</span> <span class="syntax--constant syntax--numeric">50</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>svg<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"text"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"transform"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"translate(100,0)"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"x"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--constant syntax--numeric">50</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"y"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--constant syntax--numeric">50</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"font-size"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"24px"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">text</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"CSV Foods Stock Price"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">catch</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>error<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">throw</span> error<span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--storage syntax--type syntax--function">function</span> <span class="syntax--entity syntax--name syntax--function">onMouseOver</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--comma">,</span> i<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">select</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>this<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">'class'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">'highlight'</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">transition</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">duration</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--constant syntax--numeric">400</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">'width'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> xScale<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">bandwidth</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--constant syntax--numeric">5</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"height"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> height <span class="syntax--keyword syntax--operator syntax--js">-</span> <span class="syntax--entity syntax--name syntax--function">yScale</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--constant syntax--numeric">10</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"y"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> <span class="syntax--entity syntax--name syntax--function">yScale</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--keyword syntax--operator syntax--js">-</span> <span class="syntax--constant syntax--numeric">10</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>g<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"text"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">'class'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">'val'</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">'x'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--keyword syntax--control">return</span> <span class="syntax--entity syntax--name syntax--function">xScale</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">year</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">'y'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--keyword syntax--control">return</span> <span class="syntax--entity syntax--name syntax--function">yScale</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--keyword syntax--operator syntax--js">-</span> <span class="syntax--constant syntax--numeric">15</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">text</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--keyword syntax--control">return</span> <span class="syntax--punctuation syntax--definition syntax--array syntax--begin syntax--bracket syntax--square">[</span> <span class="syntax--string syntax--quoted">'$'</span> <span class="syntax--keyword syntax--operator syntax--js">+</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--definition syntax--array syntax--end syntax--bracket syntax--square">]</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--storage syntax--type syntax--function">function</span> <span class="syntax--entity syntax--name syntax--function">onMouseOut</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--comma">,</span> i<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">select</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>this<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">'class'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">'bar'</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">transition</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">duration</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--constant syntax--numeric">400</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">'width'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> xScale<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">bandwidth</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"height"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> height <span class="syntax--keyword syntax--operator syntax--js">-</span> <span class="syntax--entity syntax--name syntax--function">yScale</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"y"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> <span class="syntax--entity syntax--name syntax--function">yScale</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">value</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">selectAll</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">'.val'</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">remove</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span></span></div><div class="line"></div></pre>
<div id="bar_container">
<script>
var widthb = 960,
heightb = 400,
marginb = 200;
var svgb = d3.select("#bar_container")
.append("svg")
.attr("width", widthb)
.attr("height", heightb);
widthb -= marginb;
heightb -= marginb;
var xScale = d3.scaleBand().range ([0, widthb]).padding(0.4),
yScale = d3.scaleLinear().range ([heightb, 0]);
var gb = svgb.append("g")
.attr("transform", "translate(" + 100 + "," + 100 + ")");
datab = [{year: "2011", value: "45"}, {year: "2012", value: "47"}, {year: "2013", value: "52"}, {year: "2014", value: "70"}, {year: "2015", value: "75"}, {year: "2016", value: "78"} ];
xScale.domain(datab.map(function(d) { return d.year; }));
yScale.domain([0, d3.max(datab, function(d) { return d.value; })]);
gb.append("g")
.attr("transform", "translate(0," + heightb + ")")
.call(d3.axisBottom(xScale))
.append("text")
.attr("y", heightb - 250)
.attr("x", widthb - 100)
.attr("text-anchor", "end")
.attr("stroke", "black")
.text("Year");
gb.append("g")
.call(d3.axisLeft(yScale)
.tickFormat(function(d){ return "$" + d; })
.ticks(10))
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", "-5.1em")
.attr("text-anchor", "end")
.attr("stroke", "black")
.text("Stock Price");
gb.selectAll(".bar")
.data(datab)
.enter()
.append("rect")
.attr("class", "bar")
.attr("x", function(d) { return xScale(d.year); })
.attr("y", function(d) { return yScale(d.value); })
.attr("width", xScale.bandwidth())
.attr("height", function(d) { return heightb - yScale(d.value); })
.on("mouseover", onMouseOver)
.on("mouseout", onMouseOut)
.transition()
.ease(d3.easeLinear)
.duration(400)
.delay(function (d, i) {
return i * 50;
});
svgb.append("text")
.attr("transform", "translate(100,0)")
.attr("x", 50)
.attr("y", 50)
.attr("font-size", "24px")
.text("CSV Foods Stock Price")
function onMouseOver(d, i) {
d3.select(this)
.attr('class', 'highlight')
.transition()
.duration(400)
.attr('width', xScale.bandwidth() + 5)
.attr("height", function(d) { return heightb - yScale(d.value) + 10; })
.attr("y", function(d) { return yScale(d.value) - 10; });
gb.append("text")
.attr('class', 'val')
.attr('x', function() {
return xScale(d.year);
})
.attr('y', function() {
return yScale(d.value) - 15;
})
.text(function() {
return [ '$' +d.value];
});
}
function onMouseOut(d, i) {
d3.select(this)
.attr('class', 'bar')
.transition()
.duration(400)
.attr('width', xScale.bandwidth())
.attr("height", function(d) { return heightb - yScale(d.value); })
.attr("y", function(d) { return yScale(d.value); });
d3.selectAll('.val')
.remove()
}
</script>
</div>
<h4 id="pita-graf">Pita graf</h4>
<p>Pretpostavimo da imamo sljedeće podatke zapisane u csv datoteci</p>
<table>
<thead>
<tr>
<th>browser</th>
<th>percent</th>
</tr>
</thead>
<tbody>
<tr>
<td>Chrome</td>
<td>73.70</td>
</tr>
<tr>
<td>IE/Edge</td>
<td>4.90</td>
</tr>
<tr>
<td>Firefox</td>
<td>15.40</td>
</tr>
<tr>
<td>Safari</td>
<td>,3.60</td>
</tr>
<tr>
<td>Opera</td>
<td>1.00</td>
</tr>
</tbody>
</table>
<p>Pita graf gradimo na sličan način kao i prethodni graf.</p>
<pre class="editor-colors lang-js"><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> width <span class="syntax--keyword syntax--operator syntax--js">=</span> <span class="syntax--constant syntax--numeric">500</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>height <span class="syntax--keyword syntax--operator syntax--js">=</span> <span class="syntax--constant syntax--numeric">400</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>radius <span class="syntax--keyword syntax--operator syntax--js">=</span> <span class="syntax--meta syntax--class">Math</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">min</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>width<span class="syntax--meta syntax--delimiter syntax--comma">,</span> height<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--keyword syntax--operator syntax--js">/</span> <span class="syntax--constant syntax--numeric">2</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> svg <span class="syntax--keyword syntax--operator syntax--js">=</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">select</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"body"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"svg"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"width"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> width<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"height"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> height<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> g <span class="syntax--keyword syntax--operator syntax--js">=</span> svg<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"g"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"transform"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"translate("</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> width <span class="syntax--keyword syntax--operator syntax--js">/</span> <span class="syntax--constant syntax--numeric">2</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--string syntax--quoted">","</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> height <span class="syntax--keyword syntax--operator syntax--js">/</span> <span class="syntax--constant syntax--numeric">2</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--string syntax--quoted">")"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// kreiranje skale boja za vrijednosti</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> color <span class="syntax--keyword syntax--operator syntax--js">=</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">scaleOrdinal</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--array syntax--begin syntax--bracket syntax--square">[</span><span class="syntax--string syntax--quoted">'#4daf4a'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span><span class="syntax--string syntax--quoted">'#377eb8'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span><span class="syntax--string syntax--quoted">'#ff7f00'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span><span class="syntax--string syntax--quoted">'#984ea3'</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span><span class="syntax--string syntax--quoted">'#e41a1c'</span><span class="syntax--punctuation syntax--definition syntax--array syntax--end syntax--bracket syntax--square">]</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// funkcija koja će vraćat vrijednost (percent) podatka d</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> pie <span class="syntax--keyword syntax--operator syntax--js">=</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">pie</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">value</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--keyword syntax--control">return</span> d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">percent</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--comment syntax--block">// kreiraj novi luk</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> path <span class="syntax--keyword syntax--operator syntax--js">=</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">arc</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// sa vanjskim radiusom za 10 manjim od stvarnog</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">outerRadius</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>radius <span class="syntax--keyword syntax--operator syntax--js">-</span> <span class="syntax--constant syntax--numeric">10</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// i unutarnjim radiusom od 0</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">innerRadius</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--constant syntax--numeric">0</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// kreiraj novi luk</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--storage syntax--type">var</span> label <span class="syntax--keyword syntax--operator syntax--js">=</span> d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">arc</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// sa vanjskim radiusom radius</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">outerRadius</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>radius<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// i unutarnjim radiusom za 80 manjim od stvarnog</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">innerRadius</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>radius <span class="syntax--keyword syntax--operator syntax--js">-</span> <span class="syntax--constant syntax--numeric">80</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">//ovime se postiglo pozicioniraje labela blizu ruba grafa</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js">d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">csv</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"browseruse.csv"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">then</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>data<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// dodaj sve podatke</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--storage syntax--type">var</span> arc <span class="syntax--keyword syntax--operator syntax--js">=</span> g<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">selectAll</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">".arc"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">data</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--entity syntax--name syntax--function">pie</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>data<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">enter</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"g"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"class"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--string syntax--quoted">"arc"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// na svaki element dodaj element path</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>arc<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"path"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// postavi postavke radiusa kao attribut d</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"d"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> path<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// popuni sa bojom iz skale</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"fill"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> <span class="syntax--entity syntax--name syntax--function">color</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">data</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">browser</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// kada korisnik prijeđe mišom dodaj style klasu highlight</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">on</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"mouseover"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--comma">,</span>i<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">select</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>this<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"class"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span><span class="syntax--string syntax--quoted">"highlight"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// kada korisnik pomakne miš iz elementa postavi style klasu na null, čime se automatski čita fill svojstvo</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">on</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"mouseout"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--meta syntax--delimiter syntax--comma">,</span>i<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>d3<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">select</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>this<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"class"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span><span class="syntax--constant syntax--language syntax--null">null</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// dodaj labele u svaki luk</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span>arc<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">append</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"text"</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// translatiraj labelu na odgovarajuću poziciju</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">attr</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--string syntax--quoted">"transform"</span><span class="syntax--meta syntax--delimiter syntax--comma">,</span> <span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--keyword syntax--control">return</span> <span class="syntax--string syntax--quoted">"translate("</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> label<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">centroid</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--keyword syntax--operator syntax--js">+</span> <span class="syntax--string syntax--quoted">")"</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--comment syntax--block">// postavi tekst labele</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">text</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>d<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span> <span class="syntax--keyword syntax--control">return</span> d<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">data</span><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--variable syntax--other syntax--object syntax--property">browser</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span> <span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="leading-whitespace"> </span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span></span></div><div class="line"><span class="syntax--source syntax--js"><span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">catch</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span><span class="syntax--storage syntax--type syntax--function">function</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>error<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--begin syntax--bracket syntax--curly">{</span>console<span class="syntax--meta syntax--delimiter syntax--period">.</span><span class="syntax--entity syntax--name syntax--function">log</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--begin syntax--bracket syntax--round">(</span>error<span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--definition syntax--function syntax--body syntax--end syntax--bracket syntax--curly">}</span><span class="syntax--punctuation syntax--definition syntax--parameters syntax--end syntax--bracket syntax--round">)</span><span class="syntax--punctuation syntax--terminator syntax--statement syntax--semicolon">;</span></span></div><div class="line"></div><div class="line"></div></pre>
<script>
var width = 500,
height = 400,
radius = Math.min(width, height) / 2;
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
var g = svg.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
var color = d3.scaleOrdinal(['#4daf4a','#377eb8','#ff7f00','#984ea3','#e41a1c']);
var pie = d3.pie().value(function(d) {
return d.percent;
});
var path = d3.arc()
.outerRadius(radius - 10)
.innerRadius(0);
var label = d3.arc()
.outerRadius(radius)
.innerRadius(radius - 80);
data = [ {browser: "Chrome", percent: "73.70"}, {browser: "IE/Edge", percent: "4.90"},{browser: "Firefox", percent: "15.40"}, {browser: "Safari", percent: "3.60"}, {browser: "Opera", percent: "1.00"} ]
var arc = g.selectAll(".arc")