-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathc3-angular.js
2961 lines (2751 loc) · 89.9 KB
/
c3-angular.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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
/*! c3-angular - v1.3.1 - 2017-10-16
* https://github.com/jettro/c3-angular-directive
* Copyright (c) 2017 ; Licensed */
angular.module('gridshore.c3js.chart', []);
angular.module('gridshore.c3js.chart')
.directive('chartAxes', ChartAxes);
/**
* @ngdoc directive
* @name chartAxes
* @description
* `chart-axes` is used to customize the axes properties. Using this directive you can select the propertie(s) to use for the different categories or for the time field. You can also configure for the different columns to use y or y2.
*
* Restrict To:
* Element
*
* Parent Element:
* c3chart
*
* @param {String} valuesX Specify the key in the data object to use for the x value
*
* {@link http://c3js.org/reference.html#data-x}
* @param {String} valuesXs Specify the different keys for different data columns in format
* columnId:key,columnId:key
*
* {@link http://c3js.org/reference.html#data-xs}
* @param {String} y Set the id(s) of columns to use the first y value (y). Format is comma separated.
*
* {@link http://c3js.org/reference.html#data-axes}
* @param {String} y2 Set the id(s) of columns to use the second y value (y2) Format is comma separated.
*
* {@link http://c3js.org/reference.html#data-axes}
*
* @example
* Usage:
* <chart-axes values-x="..." values-Xs="..." y="..." y2="..."/>
* Example:
* {@link http://jettro.github.io/c3-angular-directive/#examples}
*/
function ChartAxes () {
var axesLinker = function (scope, element, attrs, chartCtrl) {
var x = attrs.valuesX;
if (x) {
chartCtrl.addXAxisValues(x);
}
var xs = attrs.valuesXs;
var xsValues = {};
if (xs) {
xsItems = xs.split(",");
for (var xsI in xsItems) {
xsItem = xsItems[xsI].split(":");
xsValues[xsItem[0]] = xsItem[1];
}
chartCtrl.addXSValues(xsValues);
}
var y = attrs.y;
var y2 = attrs.y2;
var yAxis = {};
if (y2) {
var items = y2.split(",");
for (var item in items) {
yAxis[items[item]] = "y2";
}
if (y) {
var yItems = y.split(",");
for (var yItem in yItems) {
yAxis[yItems[yItem]] = "y";
}
}
chartCtrl.addYAxis(yAxis);
}
};
return {
"require": "^c3chart",
"restrict": "E",
"scope": {},
"replace": true,
"link": axesLinker
};
};
angular.module('gridshore.c3js.chart')
.directive('chartAxis', ChartAxis);
/**
* @ngdoc directive
* @name chartAxis
* @description
* `chart-axis` is used to customize the axis properties. Can be used to change the orientation of the axis.
*
* Restrict To:
* Element
*
* Parent element:
* c3chart
*
* @param {Boolean} axisRotate Configure to rotate the axis, javascript true means we rotate the axis.
*
* {@link http://c3js.org/reference.html#axis-rotated}
*
* @example
* Usage:
* <chart-axis axis-rotate="true"/>
* Example:
* {@link http://jettro.github.io/c3-angular-directive/#examples}
*/
function ChartAxis () {
var axisLinker = function (scope, element, attrs, chartCtrl) {
var rotate = attrs.axisRotate;
if (rotate) {
chartCtrl.rotateAxis();
}
};
return {
"require": "^c3chart",
"restrict": "E",
"scope": {},
"transclude": true,
"template": "<div ng-transclude></div>",
"replace": true,
"link": axisLinker
};
};
angular.module('gridshore.c3js.chart')
.directive('chartAxisX', ChartAxisX);
/**
* @ngdoc directive
* @name chartAxisX
* @description
* `chart-axis-x` is used to customize the x axis properties. Using this directive you can padding, size, visibility of the axis.
*
* Restrict To:
* Element
*
* Parent Element:
* chart-axis
*
* @param {String} axis-position Location of the label. Can have following values:
*
* - Horizontal: inner-right (default), inner-center, inner-left, outer-right, outer-center, outer-left
* - Vertical: inner-top (default), inner-middle, inner-bottom, outer-top, outer-middle, outer-bottom
*
* {@link http://c3js.org/reference.html#data-x| c3js doc}
* @param {String} axis-label Set the text for the label of the x axis.
*
* {@link http://c3js.org/reference.html#axis-x-label| c3js doc}
* @param {Number} padding-left Set padding on the left side of the x axis.
*
* {@link http://c3js.org/reference.html#axis-x-padding| c3js doc}
* @param {Number} padding-right Set padding on the right side of the x axis.
*
* {@link http://c3js.org/reference.html#axis-x-padding| c3js doc}
* @param {Number} axis-height Set the overall height of the x axis, unit in pixels.
*
* {@link http://c3js.org/reference.html#axis-x-height| c3js doc}
* @param {Boolean} show Show or hide the x axis.
*
* {@link http://c3js.org/reference.html#axis-x-show| c3js doc}
* @param {String} axis-localtime Default is to use localtime, but can be set to false to use UTC.
*
* {@link http://c3js.org/reference.html#axis-x-localtime| c3js doc}
* @param {String} axis-min Min value of the x axis.
*
* {@link http://c3js.org/reference.html#axis-x-min| c3js doc}
*
* @param {String} axis-max Max value of the x axis.
*
* {@link http://c3js.org/reference.html#axis-x-max | c3js doc}
*
* @param {String} axis-type The type of the x-axis can be one of the following three: timeseries, category or indexed (default).
*
* {@link http://c3js.org/reference.html#axis-x-type | c3js doc}
*
* @param {String} axis-x-format Specify format of x axis data, usefull when using timeseries.
*
* {@link http://c3js.org/reference.html#data-xFormat | c3js doc}
*
* @example
* Usage:
* <chart-axis-x axis-position="..." axis-label="..." padding-left="..." padding-right="..." .../>
* Example:
* {@link http://jettro.github.io/c3-angular-directive/#examples}
*
* <chart-axis axis-rotate="true">
* <chart-axis-x axis-position="outer-center"
* axis-label="The periods"
* axis-type="category"/>
* </chart-axis>
*/
function ChartAxisX () {
var axisLinker = function (scope, element, attrs, chartCtrl) {
var position = attrs.axisPosition;
var label = attrs.axisLabel;
var axis = {"label": {"text": label, "position": position}};
var paddingLeft = attrs.paddingLeft;
var paddingRight = attrs.paddingRight;
if (paddingLeft || paddingRight) {
paddingLeft = (paddingLeft) ? paddingLeft : 0;
paddingRight = (paddingRight) ? paddingRight : 0;
axis.padding = {"left": parseInt(paddingLeft), "right": parseInt(paddingRight)};
}
var height=attrs.axisHeight;
if (height) {
axis.height = parseInt(height);
}
if (attrs.show === 'false') {
axis.show = false;
}
if (attrs.axisLocaltime === 'true') {
axis.localtime=true;
}
var max=attrs.axisMax;
if (max) {
axis.max=max;
}
var min=attrs.axisMin;
if (min) {
axis.min=min;
}
var type=attrs.axisType;
if (type) {
axis.type=type;
}
chartCtrl.addAxisProperties('x', axis);
var xFormat = attrs.axisXFormat;
if (xFormat) {
chartCtrl.setXFormat(xFormat);
}
};
return {
"require": "^c3chart",
"restrict": "E",
"scope": {},
"transclude": true,
"template": "<div ng-transclude></div>",
"replace": true,
"link": axisLinker
};
}
angular.module('gridshore.c3js.chart')
.directive('chartAxisXTick', ChartAxisXTick);
/**
* @ngdoc directive
* @name chartAxisXTick
* @description
* `chart-axis-x-tick` is used to customize the x axis tick properties. You can change the amount of ticks, the format of the tick, culling, rotating.
*
* Restrict To:
* Element
*
* Parent Element:
* chart-axis-x
*
* @param {Number} tick-count Specify the number of ticks on the x axis.
*
* {@link http://c3js.org/reference.html#axis-x-tick-count| c3js doc}
* @param {Boolean} tick-culling Culling means not all ticks will be shown, for category data this is by default false, for other data true.
*
* {@link http://c3js.org/reference.html#axis-x-tick-culling| c3js doc}
* @param {Number} tick-culling-max Set the maximum number of ticks, if specified culling is by default true.
*
* {@link http://c3js.org/reference.html#axis-x-tick-culling-max| c3js doc}
* @param {Boolean} tick-multiline Break the line if the tick length doesn't fit in space, default true.
*
* {@link http://c3js.org/reference.html#axis-x-tick-multiline| c3js doc}
* @param {Boolean} tick-centered Centers the tick on the x axis
*
* {@link http://c3js.org/reference.html#axis-x-tick-centered| c3js doc}
* @param {Number} tick-rotate Number of degrees to rotate the tick, can also be a negative number.
*
* {@link http://c3js.org/reference.html#axis-x-tick-rotate| c3js doc}
* @param {Boolean} tick-fit Default is to make the tick fit the chart, if false it will be at the exact position of the x value.
*
* {@link http://c3js.org/reference.html#axis-x-tick-fit| c3js doc}
*
* @param {Boolean} tick-outer Default is not to show the outer tick, setting this to true will show the outer tick.
*
* {@link http://c3js.org/reference.html#axis-x-tick-outer| c3js doc}
*
* @param {Array} tick-values An array containing the exact values to present a tick for.
*
* {@link http://c3js.org/reference.html#axis-x-tick-values| c3js doc}
*
* @param {String} tick-format Provide a d3 based format for the tick value.
* format: '$,'
*
* @param {String} tick-format-time Provide a d3 based format for the tick value in case of timeseries data.
* format: '%Y-%m-%d %H:%M:%S'
*
* {@link http://c3js.org/reference.html#data-xFormat| c3js doc}
*
* @param {Function} tick-format-function Provide a function to format the tick value.
* format: function (d) { return '$' + d; }
*
* {@link http://c3js.org/reference.html#axis-x-tick-format| c3js doc}
*
* @example
* Usage:
* <chart-axis-x-tick tick-rotate="..." tick-count="..."/>
*
* Example:
* {@link http://jettro.github.io/c3-angular-directive/#examples}
*
* <chart-axis>
* <chart-axis-x axis-position="outer-center" axis-label="Number by 10"
* axis-type="category">
* <chart-axis-x-tick tick-rotate="50"/>
* </chart-axis-x>
* </chart-axis>
*/
function ChartAxisXTick() {
var tickLinker = function (scope, element, attrs, chartCtrl) {
var tick = {};
var count = attrs.tickCount;
if (count) {
tick.count = count;
}
var culling = attrs.tickCulling;
if (culling) {
culling = angular.lowercase(culling);
if (culling === 'true') {
tick.culling = true;
}
else if (culling === 'false') {
tick.culling = false;
}
}
var cullingMax = attrs.tickCullingMax;
if (cullingMax) {
tick.culling = { max: parseInt(cullingMax) }
}
var multiline = attrs.tickMultiline;
if (multiline) {
multiline = angular.lowercase(multiline);
if (multiline === 'true') {
tick.multiline = true;
}
else if (multiline === 'false') {
tick.multiline = false;
}
}
var centered = attrs.tickCentered;
if (centered) {
centered = angular.lowercase(centered);
if (centered === 'true') {
tick.centered = true;
}
else if (centered === 'false') {
tick.centered = false;
}
}
var rotate = attrs.tickRotate;
if (rotate) {
tick.rotate = rotate;
}
var fit = attrs.tickFit;
if (fit) {
fit = angular.lowercase(fit);
if (fit === 'true') {
tick.fit = true;
}
else if (fit === 'false') {
tick.fit = false;
}
}
var tickValues = attrs.tickValues;
if (tickValues) {
if (tickValues) {
if (tickValues.indexOf(',') > -1) {
tick.values = tickValues.split(',');
} else {
tick.values = tickValues;
}
}
}
var outer = attrs.tickOuter;
if (outer) {
outer = angular.lowercase(outer);
if (outer === 'true') {
tick.outer = true;
}
else if (outer === 'false') {
tick.outer = false;
}
}
var format = attrs.tickFormat;
if (format) {
tick.format = d3.format(format);
}
var formatTime = attrs.tickFormatTime;
if (formatTime) {
tick.format = d3.time.format(formatTime);
}
chartCtrl.addXTick(tick);
if (attrs.tickFormatFunction) {
chartCtrl.addXTickFormatFunction(scope.tickFormatFunction());
}
};
return {
"require": "^c3chart",
"restrict": "E",
"scope": {
"tickFormatFunction": "&"
},
"replace": true,
"link": tickLinker
};
}
angular.module('gridshore.c3js.chart')
.directive('chartAxisY', ChartAxisY);
/**
* @ngdoc directive
* @name chartAxisY
* @description
* `chart-axis-y` is used to customize the y and y2 axis properties. Using this directive you can padding, size, visibility of the axis.
*
* Restrict To:
* Element
*
* Parent Element:
* chart-axis
*
* @param {String} axis-id Default value is 'y' but you can also provide 'y2'
*
* @param {String} axis-position Location of the label. Can have following values:
*
* - Horizontal: inner-right (default), inner-center, inner-left, outer-right, outer-center, outer-left
* - Vertical: inner-top (default), inner-middle, inner-bottom, outer-top, outer-middle, outer-bottom
*
* {@link http://c3js.org/reference.html#data-y| c3js doc}
* @param {String} axis-label Set the text for the label of the y or y2 axis.
*
* {@link http://c3js.org/reference.html#axis-y-label| c3js doc}
* @param {Number} padding-top Set padding on the top side of the y or y2 axis.
*
* {@link http://c3js.org/reference.html#axis-y-padding| c3js doc}
* @param {Number} padding-bottom Set padding on the bottom side of the y or y2 axis.
*
* {@link http://c3js.org/reference.html#axis-y-padding| c3js doc}
* @param {Boolean} show Configure if the y or y2 axis should be shown.
*
* {@link http://c3js.org/reference.html#axis-y-show| c3js doc}
* @param {Number} axis-min Min value of the y our y2 axis in pixels.
*
* {@link http://c3js.org/reference.html#axis-y-min| c3js doc}
*
* @param {Number} axis-max Max value of the y or y2 axis in pixels.
*
* {@link http://c3js.org/reference.html#axis-y-max| c3js doc}
*
* @param {Boolean} axis-inner Position the y or y2 axis within the chart.
*
* {@link http://c3js.org/reference.html#axis-y-inner| c3js doc}
*
* @param {Boolean} axis-inverted Invert the y or y2 axis, the default is true, from top to bottom.
*
* {@link http://c3js.org/reference.html#axis-y-inverted| c3js doc}
*
* @param {Number} axis-center Set the center of the y or y2 axis, is a numeric value.
*
* {@link http://c3js.org/reference.html#axis-y-center| c3js doc}
*
* @example
* Usage:
* <chart-axis-y axis-position="..." axis-label="..." padding-top="..." padding-bottom="..." .../>
* Example:
* {@link http://jettro.github.io/c3-angular-directive/#examples}
*
* <chart-axis>
* <chart-axis-y axis-id="y"
* axis-position="outer-right"
* axis-label="Higher numbers"
* padding-top="100"
* padding-bottom="0"
* axis-min="0"/>
* <chart-axis-y axis-id="y2"
* axis-position="outer-right"
* axis-label="Lower numbers"
* padding-top="10"
* padding-bottom="0"
* axis-max="100"
* axis-min="0"/>
* </chart-axis>
*/
function ChartAxisY() {
var axisLinker = function (scope, element, attrs, chartCtrl) {
var id = attrs.axisId;
var position = attrs.axisPosition;
var label = attrs.axisLabel;
id = ( id == undefined ? 'y' : id );
var axis = {"label": {"text": label, "position": position}};
if (attrs.show === 'false') {
axis.show = false;
} else if (id === 'y2') {
axis.show = true;
}
var paddingTop = attrs.paddingTop;
var paddingBottom = attrs.paddingBottom;
if (paddingTop || paddingBottom) {
paddingTop = (paddingTop) ? paddingTop : 0;
paddingBottom = (paddingBottom) ? paddingBottom : 0;
axis.padding = {"top": parseInt(paddingTop), "bottom": parseInt(paddingBottom)};
}
var axisMax = attrs.axisMax;
var axisMin = attrs.axisMin;
if (axisMax) {
axis.max = parseInt(axisMax);
}
if (axisMin) {
axis.min = parseInt(axisMin);
}
if (attrs.axisInverted === 'true') {
axis.inverted=true;
}
if (attrs.axisInner === 'true') {
axis.inner=true;
}
var axisCenter = attrs.axisCenter;
if (axisCenter) {
axis.center = parseInt(axisCenter);
}
chartCtrl.addAxisProperties(id, axis);
};
return {
"require": "^c3chart",
"restrict": "E",
"scope": {},
"replace": true,
"link": axisLinker
};
}
angular.module('gridshore.c3js.chart')
.directive('chartAxisYTick', ChartAxisYTick);
/**
* @ngdoc directive
* @name chartAxisYTick
* @description
* `chart-axis-y-tick` is used to customize the y or y2 axis tick properties. You can change the amount of ticks, the format of the tick, culling, rotating.
*
* Restrict To:
* Element
*
* Parent Element:
* chart-axis-y
*
* @param {Number} tick-count Specify the number of ticks on the x axis.
*
* {@link http://c3js.org/reference.html#axis-y-tick-count| c3js doc}
*
* @param {Boolean} tick-outer Default is not to show the outer tick, setting this to true will show the outer tick.
*
* {@link http://c3js.org/reference.html#axis-y-tick-outer| c3js doc}
*
* @param {Array} tick-values An array containing the exact values to present a tick for.
*
* {@link http://c3js.org/reference.html#axis-y-tick-values| c3js doc}
*
* @param {Function} tick-format Provide a d3 based format for the tick value.
* format: '$,'
*
* {@link http://c3js.org/reference.html#axis-x-tick-format| c3js doc}
*
* @param {Function} tick-format-function Provide a function to format the tick value.
*
* {@link http://c3js.org/reference.html#axis-y-tick-format| c3js doc}
*
* @example
* Usage:
* <chart-axis-y-tick tick-outer="..." tick-count="..."/>
*
* Example:
* {@link http://jettro.github.io/c3-angular-directive/#examples}
*
*/
function ChartAxisYTick() {
var tickLinker = function (scope, element, attrs, chartCtrl) {
var tick = {};
var count = attrs.tickCount;
if (count) {
tick.count = count;
}
var outer = attrs.tickOuter;
if (outer) {
outer = angular.lowercase(outer);
if (outer === 'true') {
tick.outer = true;
}
else if (outer === 'false') {
tick.outer = false;
}
}
var tickValues = attrs.tickValues;
if (tickValues) {
if (tickValues.indexOf(',') > -1) {
tick.values = tickValues.split(',');
} else {
tick.values = tickValues;
}
}
var format = attrs.tickFormat;
if (format) {
tick.format = d3.format(format);
}
chartCtrl.addYTick(tick);
if (attrs.tickFormatFunction) {
chartCtrl.addYTickFormatFunction(scope.tickFormatFunction());
}
};
return {
"require": "^c3chart",
"restrict": "E",
"scope": {
"tickFormatFunction": "&"
},
"replace": true,
"link": tickLinker
};
}
angular.module('gridshore.c3js.chart')
.directive('chartBar', ChartBar);
/**
* @ngdoc directive
* @name chartBar
* @description
* `chart-bar` is used to customize the axes properties. Using this directive you can select the propertie(s) to use for the different categories or for the time field. You can also configure for the different columns to use y or y2.
*
* Restrict To:
* Element
*
* Parent Element:
* c3chart
*
* @param {Number} width Fixed with of the bars in pixels
*
* {@link http://c3js.org/reference.html#bar-width| c3js doc}
*
* @param {Number} ratio Change the width of the bar by ratio
*
* {@link http://c3js.org/reference.html#bar-width-ratio| c3js doc}
* @param {Boolean} zerobased Set if we start from zero, default is true.
*
* {@link http://c3js.org/reference.html#bar-zerobased| c3js doc}
*
* @example
* Usage:
* <chart-bar width="..." ratio="..." zerobased="..."/>
* Example:
* {@link http://jettro.github.io/c3-angular-directive/#examples}
*
*/
function ChartBar() {
var barLinker = function (scope, element, attrs, chartCtrl) {
var bar = {};
if (attrs.width) {
bar.width = parseInt(attrs.width);
}
if (attrs.ratio) {
if (!bar.width) {
bar.width = {};
}
bar.width.ratio = parseFloat(attrs.ratio);
}
if (attrs.zerobased) {
bar.zerobased = (attrs.zerobased === 'true');
}
chartCtrl.addBar(bar);
};
return {
require: '^c3chart',
restrict: 'E',
scope: {},
replace: true,
link: barLinker
};
}
angular.module('gridshore.c3js.chart')
.directive('c3chart', ['$timeout', function(timeout) {
return C3Chart(timeout);
}]);
/**
* @ngdoc directive
* @name C3Chart
* @description
* `c3chart` is the main directive to create the chart. Use it to set the padding properties and include the other directives. You can also register the callback in this directive that receives the initialised chart object.
*
* When using multiple charts in the same page you need to provide unique bind-id parameters.
*
* Restrict To:
* Element
*
* Parent Element:
* -
*
* @param {Number} padding-top Set the top padding of the chart.
*
* {@link http://c3js.org/reference.html#padding-top| c3js doc}
*
* @param {Number} padding-bottom Set the bottom padding of the chart.
*
* {@link http://c3js.org/reference.html#padding-bottom| c3js doc}
*
* @param {Number} padding-right Set the right padding of the chart.
*
* {@link http://c3js.org/reference.html#padding-right| c3js doc}
*
* @param {Number} padding-left Set the left padding of the chart.
*
* {@link http://c3js.org/reference.html#padding-left| c3js doc}
*
* @param {String} empty-label Set text displayed when empty data.
*
* {@link http://c3js.org/reference.html#data-empty-label-text| c3js doc}
*
* @param {String} bind-id Id of the chart, needs to be unique when using multiple charts on one page.
*
* {@link http://c3js.org/reference.html#bindto| c3js doc}
*
* @param {String} sort-data You can enter three different versions: asc, desc, null. Using this sorting you can change the order of stacking and the order of the pieces of a pie or donut.
*
* {@link http://c3js.org/reference.html#data-order| c3js doc}
*
* @param {Boolean} show-labels Configure to show the labels 'true' or not, default is false.
*
* {@link http://c3js.org/reference.html#data-labels| c3js doc}
*
* @param {Function} labels-format-function Provide a function to format the labels.
*
* {@link http://c3js.org/reference.html#data-labels-format| c3js doc}
*
* @param {Boolean} show-subchart Configure to show the subchart or not (default).
*
* {@link http://c3js.org/reference.html#subchart-show| c3js doc}
*
* @param {Function} subchart-on-brush-function Use this if you want to do something after brush on subchart
*
* {@link http://c3js.org/reference.html#subchart-onbrush| c3js doc}
*
* @param {Boolean} enable-zoom Configure to enable zoom in the chart or not (defaut).
*
* {@link http://c3js.org/reference.html#zoom-enabled| c3js doc}
*
* @param {Boolean} rescale-zoom Use it to update the y domain according to the zoomed region.
*
* {@link http://c3js.org/reference.html#zoom-rescale| c3js doc}
*
* @param {Function} on-zoom-end-function Use this if you want to do something after zooming
*
* {@link http://c3js.org/reference.html#zoom-onzoomend| c3js doc}
*
* @param {Array} chart-data Provide a reference to a collection that can contain dynamic data. When providing this attrbiute you also need to provide the chart-columns attribute.
*
* Array consisting of objects with values for the different columns: [{"data1":10,"data2":20},{"data1":50,"data2":60}]
*
* @param {Array} chart-columns Provide a reference to a collection that contains the columns. When providing this attrbiute you also need to provide the chart-data attribute.
*
* Array consisting of objects with some properties for the different columns: [{"id": "data1", "type": "line"}, {"id": "data2", "type": "bar"}]
*
* @param {Object} chart-x Provide information about the x column. Used when adding dynamic data to specify the field that contains the x data value.
*
* Object containing reference to the id of the x data field: {"id": "x", "name": "My Data points"}
*
* @param {Function} callback-function Use this if you want to interact with the chart object using the api
*
* {@link http://c3js.org/reference.html#api-focus| c3js doc}
*
* @param {Number} transition-duration Duration of transition (in milliseconds) for chart animation. If you specify 0, transitions will be disabled which is good for large datasets.
*
* {@link http://c3js.org/reference.html#transition-duration| c3js doc}
*
* @param {Object} initial-config Provide the initial config object to start the graph with.
*
* @example
* Usage:
* <c3chart >
* <!-- sub elements -->
* </c3chart>
*
* Example:
*
* {@link http://jettro.github.io/c3-angular-directive/#examples}
*
* Shows how to use dynamic data points.
*
* <c3chart bindto-id="dynamicpie" chart-data="piePoints" chart-columns="pieColumns"/>
*
* $scope.piePoints = [{"data1": 70, "data2": 30, "data3": "100"}];
* $scope.pieColumns = [{"id": "data1", "type": "pie"}, {"id": "data2", "type": "pie"}, {
* "id": "data3",
* "type": "pie"
*
* Show how to register a callback function and use it. The screen contains a button to toggle the legend visibility.
*
* <c3chart bindto-id="dynamicpie" chart-data="piePoints" chart-columns="pieColumns"
* callback-function="handleCallback"/>
*
* $scope.handleCallback = function (chartObj) {
* $scope.theChart = chartObj;
* };
*
* $scope.legendIsShown = true;
* $scope.toggleLegend = function() {
* if ($scope.legendIsShown) {
* $scope.theChart.legend.hide();
* } else {
* $scope.theChart.legend.show();
* }
* $scope.legendIsShown= !$scope.legendIsShown;
* $scope.theChart.flush();
* };
*/
function C3Chart ($timeout) {
var chartLinker = function (scope, element, attrs, chartCtrl) {
var paddingTop = attrs.paddingTop;
var paddingRight = attrs.paddingRight;
var paddingBottom = attrs.paddingBottom;
var paddingLeft = attrs.paddingLeft;
var sortData = attrs.sortData;
var transitionDuration = attrs.transitionDuration;
var initialConfig = attrs.initialConfig;
if (attrs.interactionEnabled && attrs.interactionEnabled === 'false') {
chartCtrl.addInteractionEnabled(false);
}
if (paddingTop) {
chartCtrl.addPadding('top', paddingTop);
}
if (paddingRight) {
chartCtrl.addPadding('right', paddingRight);
}
if (paddingBottom) {
chartCtrl.addPadding('bottom', paddingBottom);
}
if (paddingLeft) {
chartCtrl.addPadding('left', paddingLeft);
}
if (sortData) {
chartCtrl.addSorting(sortData);
}
if (attrs.labelsFormatFunction) {
chartCtrl.addDataLabelsFormatFunction(scope.labelsFormatFunction());
}
if (attrs.onZoomEndFunction) {
chartCtrl.addOnZoomEndFunction(scope.onZoomEndFunction());
}
if (attrs.subchartOnBrushFunction){
chartCtrl.addSubchartOnBrushFunction(scope.subchartOnBrushFunction());
}
if (attrs.callbackFunction) {
chartCtrl.addChartCallbackFunction(scope.callbackFunction());
}
if (transitionDuration) {
chartCtrl.addTransitionDuration(transitionDuration);
}
if (initialConfig) {
chartCtrl.addInitialConfig(initialConfig);
}
// Trick to wait for all rendering of the DOM to be finished.
$timeout(function () {
chartCtrl.showGraph();
});
};
return {
"restrict": "E",
"controller": "ChartController",
"scope": {
"bindto": "@bindtoId",
"showLabels": "@showLabels",
"labelsFormatFunction": "&",
"onZoomEndFunction": "&",
"showSubchart": "@showSubchart",
"subchartOnBrushFunction": "&",
"enableZoom": "@enableZoom",
"rescaleZoom": "@rescaleZoom",
"chartData": "=chartData",
"chartColumns": "=chartColumns",
"chartX": "=chartX",
"callbackFunction": "&",
"emptyLabel": "@emptyLabel"
},
"template": "<div><div id='{{bindto}}'></div><div ng-transclude></div></div>",
"replace": true,
"transclude": true,
"link": chartLinker
};
}
angular.module('gridshore.c3js.chart')
.directive('chartColors', ChartColors);
/**
* @ngdoc directive
* @name chartColors
* @description
* `chart-colors` is used to specify the colors to use in the chart. You can provide the colors or a function to determine the colors.
*
* Restrict To:
* Element
*
* Parent Element:
* c3chart
*
* @param {String} color-pattern A string containing comma separated hex colors
* @param {String} thresholds A string containing comma separated numeric values
*
* {@link http://c3js.org/reference.html#color-pattern| c3js docs}
* @param {Function} color-function Provide a function that receives the value to determine a color for that value.
*
* {@link http://c3js.org/reference.html#data-color| c3js docs}
*
* @example
* Usage:
* <chart-colors color-pattern="..." color-function="..." thresholds="..."/>
*
* Example:
* {@link http://jettro.github.io/c3-angular-directive/#examples}
*
*
*/
function ChartColors () {
var colorsLinker = function (scope, element, attrs, chartCtrl) {
var pattern = attrs.colorPattern;
if (pattern) {
chartCtrl.addColorPatterns(pattern.split(","));
}
var thresholds = attrs.thresholds;
if(thresholds){
chartCtrl.addColorThresholds(thresholds.split(","));
}
if (attrs.colorFunction) {
chartCtrl.addColorFunction(scope.colorFunction());
}
};
return {
"require": "^c3chart",
"restrict": "E",
"scope": {
"colorFunction": "&"
},
"replace": true,
"link": colorsLinker
};
}
angular.module('gridshore.c3js.chart')
.directive('chartColumn', ChartColumn);
/**
* @ngdoc directive
* @name chartColumn