-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathbullet-chart.ts
1800 lines (1630 loc) · 67.6 KB
/
bullet-chart.ts
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
import { Component, Property, NotifyPropertyChanges, Browser, Complex, Event, EmitType } from '@syncfusion/ej2-base';
import { EventHandler, remove, INotifyPropertyChanged, ModuleDeclaration, Collection, isNullOrUndefined } from '@syncfusion/ej2-base';
import { Internationalization } from '@syncfusion/ej2-base';
import { SvgRenderer, Rect, Size, measureText, TextOption } from '@syncfusion/ej2-svg-base';
import { Query } from '@syncfusion/ej2-data';
import { OrientationType, TickPosition, LabelsPlacement, TextPosition, FeatureType, TargetType } from './utils/enum';
import { AnimationModel, BorderModel } from '../common/model/base-model';
import { Margin, Animation, Border } from '../common/model/base';
import { MarginModel } from '../common/model/base-model';
import { BulletChartModel } from './bullet-chart-model';
import { Data } from '../common/model/data';
import { BulletChartAxis } from './renderer/bullet-axis';
import { ScaleGroup } from './renderer/scale-render';
import { redrawElement, textElement, getElement, appendChildElement, RectOption, stringToNumber, removeElement } from '../common/utils/helper';
import { BulletTooltip } from './user-interaction/tooltip';
import { IPrintEventArgs } from '../chart/model/chart-interface';
import { ExportType } from '../common/utils/enum';
import { AccumulationChart } from '../accumulation-chart/accumulation';
import { Chart } from '../chart/chart';
import { ChartTheme } from '../common/utils/enum';
import { RangeNavigator } from '../range-navigator/range-navigator';
import { getTitle, logBase } from '../common/utils/helper';
import { BulletTooltipSettings, Range, BulletLabelStyle, BulletDataLabel } from './model/bullet-base';
import { MajorTickLinesSettings, MinorTickLinesSettings } from './model/bullet-base';
import { BulletChartLegendSettings } from '../bullet-chart/model/bullet-base';
import { BulletChartLegendSettingsModel } from '../bullet-chart/model/bullet-base-model';
import { IBulletMouseEventArgs, IBulletLegendRenderEventArgs } from '../bullet-chart/model/bullet-interface';
import { BulletChartLegend } from '../bullet-chart/legend/legend';
import { BulletTooltipSettingsModel, RangeModel } from './model/bullet-base-model';
import { MajorTickLinesSettingsModel, MinorTickLinesSettingsModel } from './model/bullet-base-model';
import { BulletLabelStyleModel, BulletDataLabelModel } from './model/bullet-base-model';
import { resized, bulletChartMouseClick } from '../common/model/constants';
import { IBulletResizeEventArgs, IBulletStyle, IBulletchartTooltipEventArgs, IBulletLoadedEventArgs } from './model/bullet-interface';
import { IFeatureBarBounds } from './model/bullet-interface';
import { getBulletThemeColor } from './utils/theme';
import { ExportUtils } from '../common/utils/export';
import { PdfPageOrientation } from '@syncfusion/ej2-pdf-export';
import { PrintUtils } from '../common/utils/print';
/**
* bullet chart
*/
@NotifyPropertyChanges
export class BulletChart extends Component<HTMLElement> implements INotifyPropertyChanged {
/**
* `bulletTooltipModule` is used to manipulate and add tooltip to the feature bar.
*/
public bulletTooltipModule: BulletTooltip;
/**
* `bulletChartLegendModule` is used to manipulate and add legend in accumulation chart.
*/
public bulletChartLegendModule: BulletChartLegend;
/**
* The width of the bullet chart as a string accepts input as both like '100px' or '100%'.
* If specified as '100%, bullet chart renders to the full width of its parent element.
*
* @default null
* @aspDefaultValueIgnore
*/
@Property(null)
public width: string;
/**
* The height of the bullet chart as a string accepts input both as '100px' or '100%'.
* If specified as '100%, bullet chart renders to the full height of its parent element.
*
* @default null
* @aspDefaultValueIgnore
*/
@Property(null)
public height: string;
/**
* The locale of the bullet chart as a string.
*
* @default null
* @aspDefaultValueIgnore
*/
@Property(null)
public locale: string;
/**
* Options for customizing major tick lines.
*/
@Complex<MajorTickLinesSettingsModel>({}, MajorTickLinesSettings)
public majorTickLines: MajorTickLinesSettingsModel;
/**
* Options for customizing minor tick lines.
*/
@Complex<MinorTickLinesSettingsModel>({}, MinorTickLinesSettings)
public minorTickLines: MinorTickLinesSettingsModel;
/**
* Specifies the minimum range of an scale.
*
* @default null
*/
@Property(null)
public minimum: number;
/**
* Specifies the maximum range of an scale.
*
* @default null
*/
@Property(null)
public maximum: number;
/**
* Specifies the interval for an scale.
*
* @default null
*/
@Property(null)
public interval: number;
/**
* specifies the interval of minor ticks.
*
* @default 4
*/
@Property(4)
public minorTicksPerInterval: number;
/**
* Options for customizing labels
*/
@Complex<BulletLabelStyleModel>({fontFamily: null, size: null, fontStyle: null, fontWeight: null, color: null}, BulletLabelStyle)
public labelStyle: BulletLabelStyleModel;
/**
* Options for customizing values labels.
*/
@Complex<BulletLabelStyleModel>({fontFamily: null, size: '12px', fontStyle: 'Normal', fontWeight: '400', color: null}, BulletLabelStyle)
public categoryLabelStyle: BulletLabelStyleModel;
/**
* Specifies the format of the bullet chart axis labels.
*
* @default ''
*/
@Property('')
public labelFormat: string;
/**
* Specifies the title of the bullet chart.
*
* @default ''
*/
@Property('')
public title: string;
/**
* Options for customizing the title styles of the bullet chart.
*/
@Complex<BulletLabelStyleModel>({fontFamily: null, size: null, fontStyle: null, fontWeight: null, color: null}, BulletLabelStyle)
public titleStyle: BulletLabelStyleModel;
/**
* Specifies the sub title of the bullet chart.
*
* @default ''
*/
@Property('')
public subtitle: string;
/**
* Options for customizing the sub title styles of the bullet chart.
*/
@Complex<BulletLabelStyleModel>({fontFamily: null, size: null, fontStyle: null, fontWeight: null, color: null}, BulletLabelStyle)
public subtitleStyle: BulletLabelStyleModel;
/**
* Orientation of the scale.
*
* @default 'Horizontal'
*/
@Property('Horizontal')
public orientation: OrientationType;
/**
* Options for customizing the color and width of the chart border.
*/
@Complex<BorderModel>({ color: '#DDDDDD', width: 0 }, Border)
public border: BorderModel;
/**
* Options for customizing the tooltip of the BulletChart.
*/
@Complex<BulletTooltipSettingsModel>({}, BulletTooltipSettings)
public tooltip: BulletTooltipSettingsModel;
/**
* provides Qualitative ranges of the bullet chart.
*/
@Collection<RangeModel>([{ end: null, opacity: 1, color: '' }, { end: null, opacity: 1, color: '' }, { end: null, opacity: 1, color: '' }], Range)
public ranges: RangeModel[];
/**
* specifies the axis label position of the bullet chart.
*
* @default 'Outside'
*/
@Property('Outside')
public labelPosition: LabelsPlacement;
/**
* specifies the tick position of the bullet chart.
*
* @default 'Outside'
*/
@Property('Outside')
public tickPosition: TickPosition;
/**
* Sets the title position of bullet chart.
*
* @default 'Top'.
*/
@Property('Top')
public titlePosition: TextPosition;
/**
* If set to true, the axis will render at the opposite side of its default position.
*
* @default false
*/
@Property(false)
public opposedPosition: boolean;
/**
* Specifies the theme for the bullet chart.
*
* @default 'Material'
*/
@Property('Material')
public theme: ChartTheme;
/**
* Options for customizing animation of the feature bar.
*/
@Complex<AnimationModel>({}, Animation)
public animation: AnimationModel;
/**
* Options for customizing data label of the feature bar.
*/
@Complex<BulletDataLabelModel>({}, BulletDataLabel)
public dataLabel: BulletDataLabelModel;
/**
* Options for customizing the legend of the bullet chart.
*/
@Complex<BulletChartLegendSettingsModel>({}, BulletChartLegendSettings)
public legendSettings: BulletChartLegendSettingsModel;
/**
* default value for enableGroupSeparator.
*
* @default false
*/
@Property(false)
public enableGroupSeparator: boolean;
/**
* Options to customize left, right, top and bottom margins of the bullet chart.
*/
@Complex<MarginModel>({ top: 15, bottom: 10, left: 15, right: 15 }, Margin)
public margin: MarginModel;
/**
* Options for customizing comparative bar color bullet chart.
*
* @default 5
*/
@Property(5)
public targetWidth: number;
/**
* The stroke color for the comparative measure, which can accept values in hex and rgba as valid CSS color strings.
* This property can also be mapped from the data source.
*
* @default '#191919'
*/
@Property('#191919')
public targetColor: string;
/**
* Options for customizing feature bar height of the bullet chart.
*
* @default 6
*/
@Property(6)
public valueHeight: number;
/**
* The stroke color for the feature measure, which can accept values in hex and rgba as valid CSS color strings.
* This property can also be mapped from the data source.
*
* @default null
*/
@Property(null)
public valueFill: string;
/**
* Options for customizing the color and width of the feature bar border.
*/
@Complex<BorderModel>({ color: 'transparent', width: 0 }, Border)
public valueBorder: BorderModel;
/**
* default value of multiple data bullet chart.
*
* @isdatamanager false
* @default null
*/
@Property(null)
public dataSource: Object;
/**
* It defines the query for the data source.
*
* @default null
*/
@Property(null)
public query: Query;
/**
* It defines the category for the data source.
*
* @default null
*/
@Property(null)
public categoryField: string;
/**
* Default type on feature measure.
*
* @default 'Rect'
*/
@Property('Rect')
public type: FeatureType;
/**
* The DataSource field that contains the value value.
*
* @default ''
*/
@Property('')
public valueField: string;
/**
* The DataSource field that contains the target value.
*
* @default ''
*/
@Property('')
public targetField: string;
/**
* The DataSource field that contains the target value.
*
* @default ['Rect', 'Cross', 'Circle']
*/
@Property(['Rect', 'Cross', 'Circle'])
public targetTypes: TargetType[];
/**
* TabIndex value for the bullet chart.
*
* @default 1
*/
@Property(0)
public tabIndex: number;
// Event declaration section starts for bulletcharts
/**
* Triggers before the bulletchart tooltip is rendered.
*
* @event tooltipRender
*/
@Event()
public tooltipRender: EmitType<IBulletchartTooltipEventArgs>;
/**
* Triggers before bullet chart load.
*
* @event load
*/
@Event()
public load: EmitType<IBulletLoadedEventArgs>;
/**
* Triggers after the bullet chart rendering
*
* @event loaded
*/
@Event()
public loaded: EmitType<IBulletLoadedEventArgs>;
/**
* Triggers on clicking the chart.
*
* @event bulletChartMouseClick
*/
@Event()
public bulletChartMouseClick: EmitType<IBulletMouseEventArgs>;
/**
* Triggers before the legend is rendered.
*
* @event legendRender
* @deprecated
*/
@Event()
public legendRender: EmitType<IBulletLegendRenderEventArgs>;
/**
* Triggers before the prints gets started.
*
* @event beforePrint
*/
@Event()
public beforePrint: EmitType<IPrintEventArgs>;
/** @private */
public renderer: SvgRenderer;
/** @private */
public svgObject: HTMLElement;
/** @private */
public intl: Internationalization;
/** @private */
public bulletAxis: BulletChartAxis;
/** @private */
public scale: ScaleGroup;
/** @private */
public availableSize: Size;
/** @private */
private bulletid: number = 57726;
/** @private */
public delayRedraw: boolean;
/** @private */
public dataModule: Data;
/** @private */
public animateSeries: boolean = true;
/** @private */
public containerWidth: number;
/** @private */
public resizeBound: any;
/** @private */
private resizeTo: number;
/** @private */
public containerHeight: number;
/** @private */
private dataCount: number;
/** @private */
public redraw: boolean;
/** @private */
private titleCollections: string[];
/** @private */
private subTitleCollections: string[];
/** @private */
public initialClipRect: Rect;
/** @private */
public bulletChartRect: Rect;
/** @private */
public isTouch: boolean;
/** @private */
public mouseX: number;
/** @private */
public mouseY: number;
private padding: number = 5;
/** @private */
public leftSize: number = 0;
/** @private */
public rightSize: number = 0;
/** @private */
public topSize: number = 0;
/** @private */
public bottomSize: number = 0;
/** @private */
public maxLabelSize: Size = new Size(0, 0);
public maxTitleSize: Size = new Size(0, 0);
/** @private */
public themeStyle: IBulletStyle;
/** @private */
public rangeCollection: number[];
/** @private */
public intervalDivs: number[] = [10, 5, 2, 1];
/** @private */
public format: Function;
private isLegend: boolean;
/** @private */
private currentLegendIndex: number = 0;
private previousTargetId: string = '';
/**
* Gets the current visible ranges of the bullet Chart.
*
* @hidden
*/
public visibleRanges: Range[];
/**
* Constructor for creating the bullet chart.
*
* @param {BulletChartModel} options - Specifies the bullet chart model.
* @param {string | HTMLElement} element - Specifies the element for the bullet chart.
* @hidden
*/
constructor(options?: BulletChartModel, element?: string | HTMLElement) {
super(options, <HTMLElement | string>element);
}
/**
* Initialize the event handler.
*
* @returns {void}
*/
protected preRender(): void {
this.allowServerDataBinding = false;
this.unWireEvents();
this.initPrivateValues();
this.setCulture();
this.wireEvents();
}
/**
* To initialize the private variables.
*
* @returns {void}
*/
private initPrivateValues(): void {
this.delayRedraw = false;
this.scale = new ScaleGroup(this);
this.bulletAxis = new BulletChartAxis(this);
if (this.element.id === '') {
const collection: number = document.getElementsByClassName('e-BulletChart').length;
this.element.id = 'BulletChart_' + this.bulletid + '_' + collection;
}
}
/**
* Method to set culture for BulletChart.
*
* @returns {void}
*/
private setCulture(): void {
this.intl = new Internationalization();
}
/**
* To Initialize the bullet chart rendering.
*
* @returns {void}
*/
protected render(): void {
const loadEventData: IBulletLoadedEventArgs = {
bulletChart: this,
theme: this.theme, name: 'load'
};
this.trigger('load', loadEventData, () => {
this.setTheme();
this.createSvg(this);
this.findRange();
if (this.bulletChartLegendModule && this.legendSettings.visible) {
this.calculateVisibleElements();
this.bulletChartLegendModule.getLegendOptions(this.visibleRanges);
}
this.calculatePosition();
this.renderBulletElements();
this.trigger('loaded', { bulletChart: this });
this.allowServerDataBinding = true;
this.renderComplete();
});
}
/**
* Theming for bullet chart.
*
* @returns {void}
*/
private setTheme(): void {
this.themeStyle = getBulletThemeColor(this.theme);
if ((this.targetColor === null || this.targetColor === '#191919' || this.valueFill == null) && (this.theme.indexOf('Fluent') > -1 || this.theme.indexOf('Bootstrap5') > -1 || this.theme.indexOf('Tailwind3') > -1)) {
this.valueFill = !(this.valueFill) ? (this.theme === 'FluentDark' ? '#797775' : this.theme === 'Bootstrap5' ? '#343A40' : this.theme === 'Tailwind3' ? '#1F2937' : this.theme === 'Tailwind3Dark' ? '#6B7280' : '#A19F9D') : this.valueFill;
this.targetColor = (this.targetColor === '#191919') ? (this.theme === 'FluentDark' ? '#797775' : this.theme === 'Bootstrap5' ? '#343A40' : this.theme === 'Tailwind3' ? '#1F2937' : this.theme === 'Tailwind3Dark' ? '#6B7280' : '#A19F9D') : this.targetColor;
}
if ((this.targetColor === null || this.targetColor === '#191919' || this.valueFill == null) && (this.theme.indexOf('Material3') > -1 || this.theme.indexOf('Bootstrap5') > -1)) {
this.valueFill = !(this.valueFill) ? (this.theme === 'Material3Dark' ? '#938F99' : this.theme === 'Bootstrap5Dark' ? '#343A40' : '#79747E') : this.valueFill;
this.targetColor = (this.targetColor === '#191919') ? (this.theme === 'Material3Dark' ? '#938F99' : this.theme === 'Bootstrap5Dark' ? '#343A40' : '#79747E') : this.targetColor;
}
if (!(document.getElementById(this.element.id + 'Keyboard_bullet_chart_focus'))) {
const style: HTMLStyleElement = document.createElement('style');
style.setAttribute('id', (<HTMLElement>this.element).id + 'Keyboard_bullet_chart_focus');
style.innerText = '.e-bullet-chart-focused:focus,' +
'text[id*=_BulletChartTitle]:focus, text[id*=_BulletChartSubTitle]:focus, rect[id*=_svg_FeatureMeasure_]:focus, g[id*=_chart_legend_g_]:focus {outline: none } .e-bullet-chart-focused:focus-visible,' +
'text[id*=_BulletChartTitle]:focus-visible, text[id*=_BulletChartSubTitle]:focus-visible, rect[id*=_svg_FeatureMeasure_]:focus-visible, g[id*=_chart_legend_g_]:focus-visible {outline: 1.5px ' + this.themeStyle.tabColor + ' solid}';
document.body.appendChild(style);
}
}
private findRange(): void {
if (!this.minimum) {
this.minimum = 0;
}
if (!this.maximum && this.ranges.length) {
this.maximum = 0;
for (let i: number = 0; i < this.ranges.length; i++) {
this.maximum = this.maximum > this.ranges[i as number].end ? this.maximum : this.ranges[i as number].end;
}
}
if (this.maximum === null) {
if (!isNullOrUndefined(this.dataSource)) {
for (let i: number = 0; i < Object.keys(this.dataSource).length; i++) {
if (this.dataSource[i as number][this.targetField] > this.dataSource[i as number][this.valueField]) {
this.maximum = this.maximum > this.dataSource[i as number][this.targetField] ? this.maximum + this.interval :
this.dataSource[i as number][this.targetField] + this.interval;
} else {
this.maximum = this.maximum > this.dataSource[i as number][this.valueField] ? this.maximum + this.interval :
this.dataSource[i as number][this.valueField] + this.interval;
}
}
} else {
this.maximum = 10;
}
}
if (!this.interval) {
this.interval = this.calculateNumericNiceInterval(this.maximum - this.minimum);
}
}
protected getActualDesiredIntervalsCount(availableSize: Size): number {
const size: number = this.orientation === 'Horizontal' ? availableSize.width : availableSize.height;
let desiredIntervalsCount: number = (this.orientation === 'Horizontal' ? 0.533 : 1) * 3;
desiredIntervalsCount = Math.max((size * (desiredIntervalsCount / 100)), 1);
return desiredIntervalsCount;
}
/**
* Numeric Nice Interval for the axis.
*
* @private
* @param {number} delta - The difference between maximum and minimum values.
* @returns {number} - The calculated numeric nice interval for the axis.
*/
protected calculateNumericNiceInterval(delta: number): number {
const actualDesiredIntervalsCount: number = this.getActualDesiredIntervalsCount(this.availableSize);
let niceInterval: number = delta / actualDesiredIntervalsCount;
const minInterval: number = Math.pow(10, Math.floor(logBase(niceInterval, 10)));
for (const interval of this.intervalDivs) {
const currentInterval: number = minInterval * interval;
if (actualDesiredIntervalsCount < (delta / currentInterval)) {
break;
}
niceInterval = currentInterval;
}
return niceInterval;
}
/**
* To set the left and top position for data label template for center aligned bulletchart.
*
* @returns {void}
*/
private setSecondaryElementPosition(): void {
const element: HTMLDivElement = getElement(this.element.id + '_Secondary_Element') as HTMLDivElement;
if (!element) {
return;
}
const rect: ClientRect = this.element.getBoundingClientRect();
const svgRect: ClientRect = getElement(this.element.id + '_svg').getBoundingClientRect();
element.style.left = Math.max(svgRect.left - rect.left, 0) + 'px';
element.style.top = Math.max(svgRect.top - rect.top, 0) + 'px';
element.style.position = 'relative';
}
/**
* Method to create SVG element.
*/
public createSvg(chart: BulletChart): void {
this.removeSvg();
chart.renderer = new SvgRenderer(chart.element.id);
this.calculateAvailableSize(this);
chart.svgObject = <HTMLElement>chart.renderer.createSvg({
id: chart.element.id + '_svg',
width: chart.availableSize.width,
height: chart.availableSize.height
});
this.renderChartBackground();
}
/**
* Creating a background element to the svg object.
*
* @returns {void}
*/
private renderChartBackground(): void {
const rect: RectOption = new RectOption(
this.element.id + '_ChartBorder', this.themeStyle.background,
{ width: this.border.width || 0, color: this.border.color || 'transparent' }, 1,
new Rect(0, 0, this.availableSize.width, this.availableSize.height), 0, 0, '', this.border.dashArray
);
this.svgObject.appendChild(this.renderer.drawRectangle(rect) as HTMLElement);
}
/**
* Rendering the bullet elements.
*
* @returns {void}
*/
private renderBulletElements(): void {
const scaleGroup: Element = this.renderer.createGroup({ 'id': this.svgObject.id + '_scaleGroup' });
this.renderBulletChartTitle();
this.svgObject.appendChild(scaleGroup);
this.rangeCollection = this.scale.drawScaleGroup(scaleGroup);
const size: number = (this.orientation === 'Horizontal') ? this.initialClipRect.width : this.initialClipRect.height;
const intervalValue: number = size / ((this.maximum - this.minimum) / this.interval);
this.bulletAxis.renderMajorTickLines(intervalValue, scaleGroup);
this.bulletAxis.renderMinorTickLines(intervalValue, scaleGroup);
this.bulletAxis.renderAxisLabels(intervalValue, scaleGroup);
this.bulletChartRect.x = (this.titlePosition === 'Left' ||
this.titlePosition === 'Right' || this.orientation === 'Vertical') ? this.bulletChartRect.x : 0;
const elementId: string = this.element.id;
if (this.element.tagName !== 'g') {
const tooltipDiv: Element = redrawElement(this.redraw, elementId + '_Secondary_Element') ||
this.createElement('div');
tooltipDiv.id = elementId + '_Secondary_Element';
appendChildElement(false, this.element, tooltipDiv, this.redraw);
}
if (this.tooltip.enable) {
appendChildElement(
false, this.svgObject, this.renderer.createGroup(
{ id: elementId + '_UserInteraction', style: 'pointer-events:none;' }
),
this.redraw
);
}
//this.bulletAxis.renderYAxisLabels(intervalValue, scaleGroup, this.bulletChartRect);
this.bindData();
this.renderDataLabel();
this.renderBulletLegend();
//this.changeOrientation(scaleGroup);
this.element.appendChild(this.svgObject);
this.setSecondaryElementPosition();
}
/**
* To render the legend
*/
private renderBulletLegend(): void {
if (this.bulletChartLegendModule && this.bulletChartLegendModule.legendCollections.length) {
this.bulletChartLegendModule.calTotalPage = true;
const bounds: Rect = this.bulletChartLegendModule.legendBounds;
this.bulletChartLegendModule.renderLegend(this, this.legendSettings, bounds);
}
}
/**
* Handles the bullet chart resize.
*
* @returns {boolean}
* @private
*/
private bulletResize(): boolean {
this.animateSeries = false;
const arg: IBulletResizeEventArgs = {
chart: this,
name: resized,
currentSize: new Size(0, 0),
previousSize: new Size(
this.availableSize.width,
this.availableSize.height
)
};
if (this.resizeTo) {
clearTimeout(this.resizeTo);
}
this.resizeTo = +setTimeout(
(): void => {
if (this.isDestroyed) {
clearTimeout(this.resizeTo);
return;
}
this.createSvg(this);
arg.currentSize = this.availableSize;
this.trigger(resized, arg);
this.calculatePosition();
this.renderBulletElements();
},
500);
return false;
}
/**
* Process the data values of feature and comparative measure bar.
*
* @returns {void}
*/
private bindData(): void {
if (this.dataSource != null) {
this.dataCount = (this.dataSource as object[]).length;
this.drawMeasures(this.dataCount);
}
}
/**
* Rendering the feature and comaparative measure bars.
*
* @param {number} dataCount - The count of bars to render.
* @returns {void}
*/
private drawMeasures(dataCount: number): void {
this.scale.renderFeatureBar(dataCount);
this.scale.renderComparativeSymbol(dataCount);
}
/**
* To calculate the title bounds.
*
* @returns {void}
*/
private calculatePosition(): void {
const margin: MarginModel = this.margin;
// Title Height;
let titleHeight: number = 0;
let subTitleHeight: number = 0;
let titleSize: Size = new Size(0, 0);
const padding: number = 5;
this.titleCollections = [];
this.subTitleCollections = [];
let maxTitlteWidth: number = 0;
let maxTitlteHeight: number = 0;
let maxVerticalTitlteHeight: number = padding;
if (this.title) {
this.titleCollections = getTitle(this.title, this.titleStyle, this.titleStyle.maximumTitleWidth,
this.enableRtl, this.themeStyle.titleFont);
titleHeight = (measureText(this.title, this.titleStyle, this.themeStyle.titleFont).height *
this.titleCollections.length) + padding;
for (const titleText of this.titleCollections) {
titleSize = measureText(titleText, this.titleStyle, this.themeStyle.titleFont);
maxTitlteWidth = titleSize.width > maxTitlteWidth ? titleSize.width : maxTitlteWidth;
maxTitlteHeight = titleSize.height > maxTitlteHeight ? titleSize.height : maxTitlteHeight;
}
maxVerticalTitlteHeight += maxTitlteHeight;
this.subTitleCollections = getTitle(this.subtitle, this.subtitleStyle, this.titleStyle.maximumTitleWidth, this.enableRtl);
if (this.subtitle) {
for (const subText of this.subTitleCollections) {
titleSize = measureText(subText, this.subtitleStyle, this.themeStyle.subTitleFont);
maxTitlteWidth = titleSize.width > maxTitlteWidth ? titleSize.width : maxTitlteWidth;
maxTitlteHeight = titleSize.height > maxTitlteHeight ? titleSize.height : maxTitlteHeight;
}
subTitleHeight = (measureText(this.subtitle, this.subtitleStyle,
this.themeStyle.subTitleFont).height * this.subTitleCollections.length) + padding;
maxVerticalTitlteHeight += maxTitlteHeight;
}
}
this.maxTitleSize = new Size(maxTitlteWidth, this.orientation === 'Vertical' ? maxVerticalTitlteHeight : maxTitlteHeight);
this.maxLabelSize = this.getMaxLabelWidth();
this.initialClipRect = this.getBulletBounds(
(this.orientation === 'Vertical' ? maxVerticalTitlteHeight : maxTitlteWidth), titleHeight, subTitleHeight, margin);
this.bulletChartRect = new Rect(
this.initialClipRect.x, this.initialClipRect.y, this.initialClipRect.width, this.initialClipRect.height
);
if (this.bulletChartLegendModule) {
this.bulletChartLegendModule.calculateLegendBounds(this.initialClipRect, this.availableSize, this.maxLabelSize);
}
}
/**
* Calculate the rect values based on title position.
*
* @param {number} maxTitlteWidth - The maximum width of the title.
* @param {number} titleHeight - The height of the title.
* @param {number} subTitleHeight - The height of the subtitle.
* @param {MarginModel} margin - The margin settings.
* @returns {Rect} - The calculated rect values.
* @private
*/
public getBulletBounds(
maxTitlteWidth: number, titleHeight: number, subTitleHeight: number, margin: MarginModel
): Rect {
const padding: number = 5;
const rect: Rect = new Rect(0, 0, 0, 0);
const enableRtl: boolean = this.enableRtl;
const labelSpace: number = (this.labelPosition === this.tickPosition) ? padding : 0;
const tickSize: number = ((this.tickPosition === 'Inside') ? 0 : (this.majorTickLines.height));
const labelSize: number = ((this.labelPosition === 'Inside') ? 0 : padding +
((this.tickPosition === 'Outside') ? 0 : (measureText(this.maximum.toString(), this.labelStyle, this.themeStyle.dataLabelFont).height)));
let topAxisLabel: number = 0;
let bottomAxisLabel: number = 0;
let leftAxisLabel: number = 0;
let rightAxisLabel: number = 0;
let topCategory: number = 0;
let bottomCategory: number = 0;
let leftCategory: number = 0;
let rightCategory: number = 0;
const title: number = maxTitlteWidth;
const format: string = this.bulletAxis.getFormat(this);
const isCustomFormat: boolean = format.match('{value}') !== null;
this.bulletAxis.format = this.intl.getNumberFormat({
format: isCustomFormat ? '' : format, useGrouping: this.enableGroupSeparator
});
const formatted: number = measureText(
this.bulletAxis.formatValue(this.bulletAxis, isCustomFormat, format, this.maximum),
this.labelStyle, this.themeStyle.axisLabelFont).width;
let categoryLabelSize: number;
if (this.orientation === 'Horizontal') {
categoryLabelSize = this.maxLabelSize.width;
topAxisLabel = (this.opposedPosition) ? tickSize + labelSize + labelSpace : 0;
bottomAxisLabel = (!this.opposedPosition) ? tickSize + labelSize + labelSpace : 0;
leftCategory = ((categoryLabelSize && !enableRtl) ? (categoryLabelSize) : 0);
leftCategory += (title && this.titlePosition === 'Left') ? padding * 3 : 0;
rightCategory = ((categoryLabelSize && enableRtl) ? (categoryLabelSize) : 0);
rightCategory += (title && this.titlePosition === 'Right') ? padding : 0;
} else {
categoryLabelSize = this.maxLabelSize.height;
rightAxisLabel = (this.opposedPosition) ? tickSize + labelSpace : 0;
rightAxisLabel += (this.opposedPosition && this.labelPosition !== 'Inside') ?
formatted : 0;
leftAxisLabel = (!this.opposedPosition) ? tickSize + labelSpace : 0;
leftAxisLabel += (!this.opposedPosition && this.labelPosition !== 'Inside') ?
formatted : 0;
topCategory = ((categoryLabelSize && enableRtl) ? (categoryLabelSize + padding) : 0);
bottomCategory = ((categoryLabelSize && !enableRtl) ? (categoryLabelSize + padding) : 0);
}
switch (this.titlePosition) {
case 'Left':
rect.x = margin.left + title + leftCategory + leftAxisLabel;
rect.width = (this.availableSize.width - margin.right - rect.x - rightCategory - rightAxisLabel) < 0 ? 0 :
this.availableSize.width - margin.right - rect.x - rightCategory - rightAxisLabel;
rect.y = margin.top + topAxisLabel + topCategory;
rect.height = (this.availableSize.height - rect.y - margin.bottom - bottomAxisLabel - bottomCategory) < 0 ? 0 :