-
Notifications
You must be signed in to change notification settings - Fork 322
/
Series.ts
1640 lines (1404 loc) · 43.2 KB
/
Series.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
/**
* Functionality for any series-based elements, like Line Series (graphs),
* Pie slice lists, etc.
*/
/**
* ============================================================================
* IMPORTS
* ============================================================================
* @hidden
*/
import { Component, IComponentProperties, IComponentDataFields, IComponentAdapters, IComponentEvents } from "../../core/Component";
import { AxisDataItem } from "../axes/Axis";
import { Sprite } from "../../core/Sprite";
import { List, ListTemplate, IListEvents, ListDisposer } from "../../core/utils/List";
import { Dictionary, DictionaryDisposer } from "../../core/utils/Dictionary";
import { DataItem } from "../../core/DataItem";
import { Container } from "../../core/Container";
import { SerialChart } from "../types/SerialChart";
import { Label } from "../../core/elements/Label";
import { Axis } from "../axes/Axis";
import { Tooltip } from "../../core/elements/Tooltip";
import { Bullet } from "../elements/Bullet";
import { LegendDataItem, LegendSettings } from "../Legend";
import { options } from "../../core/Options";
import { Ordering } from "../../core/utils/Order";
import { Color } from "../../core/utils/Color";
import { registry } from "../../core/Registry";
import * as $iter from "../../core/utils/Iterator";
import * as $math from "../../core/utils/Math";
import * as $ease from "../../core/utils/Ease";
import * as $utils from "../../core/utils/Utils";
import * as $object from "../../core/utils/Object";
import * as $type from "../../core/utils/Type";
import * as $array from "../../core/utils/Array";
import * as $colors from "../../core/utils/Colors";
export interface IHeatRule {
target: Sprite;
property: string;
min: any;
max: any;
dataField?: string;
minValue?: number;
maxValue?: number;
}
/**
* ============================================================================
* DATA ITEM
* ============================================================================
* @hidden
*/
/**
* Defines a [[DataItem]] for [[Series]].
*
* @see {@link DataItem}
*/
export class SeriesDataItem extends DataItem {
/**
* Related item's width in pixels.
*
* This is passed to bullets so that we'd know if the bullet (LabelBullet)
* fits to max width/height.
*
* At the moment this is only used by column series.
*
* @ignore Exclude from docs
*/
public itemWidth: number;
/**
* Related item's height in pixels.
*
* This is passed to bullets so that we'd know if the bullet (LabelBullet)
* fits to max width/height.
*
* At the moment this is only used by column series.
*
* @ignore Exclude from docs
*/
public itemHeight: number;
/**
* A dictionary of data items bullets, where key is uid of a bullet template.
*
* @ignore Exclude from docs
* @todo review description
*/
public bullets = new Dictionary<string, Sprite>();
/**
* Defines a type of [[Component]] this data item is used for.
*/
public _component!: Series;
/**
* Constructor
*/
constructor() {
super();
this.className = "SeriesDataItem";
//@todo Should we make `bullets` list disposable?
this._disposers.push(new DictionaryDisposer(this.bullets));
this.values.value = {};
this.values.value = {};
this.applyTheme();
}
/**
* Destroys this object and all related data.
*/
public dispose() {
this.bullets.clear();
super.dispose();
}
/**
* data items's numeric value.
*
* @param value Value
*/
public set value(value: number) {
this.setValue("value", value);
}
/**
* @return Value
*/
public get value(): number {
return this.values.value.value;
}
}
/**
* ============================================================================
* REQUISITES
* ============================================================================
* @hidden
*/
/**
* Defines data fields for [[Series]].
*/
export interface ISeriesDataFields extends IComponentDataFields {
/**
* Name of the field in data that holds numeric value.
*/
value?: string;
/**
* Name of the field in data that holds boolean flag if item should be hidden.
*/
hidden?: string;
}
/**
* Defines properties for [[Series]].
*/
export interface ISeriesProperties extends IComponentProperties {
/**
* Minimal distance between two adjacent bullets in pixels.
*
* If bullet is closer, it will be skipped and not shown.
*
* This allows to avoid crammed up graphs wil a lot of bullets.
*
* @default 0
*/
minBulletDistance?: number;
/**
* Should series be hidden in chart's legend?
*/
hiddenInLegend?: boolean;
/**
* Series' name.
*/
name?: string;
}
/**
* Defines events for [[Series]].
*/
export interface ISeriesEvents extends IComponentEvents {
/**
* @todo Description
*/
selectionextremeschanged: {};
/**
* @todo Description
*/
extremeschanged: {};
/**
* @todo Description
*/
dataitemchanged: {
dataItem: DataItem
};
}
/**
* Defines adapters for [[Series]].
*
* @see {@link Adapter}
*/
export interface ISeriesAdapters extends IComponentAdapters, ISeriesProperties {
/**
* Applied to the name used by screen readers.
*/
itemReaderText: string
}
/**
* ============================================================================
* MAIN CLASS
* ============================================================================
* @hidden
*/
/**
* Defines base class for any kind of serial data.
*
* @see {@link ISeriesEvents} for a list of available Events
* @see {@link ISeriesAdapters} for a list of available Adapters
* @todo Separate axis-related stuff to some other class so that MapSeries would not have unrelated stuff
*/
export class Series extends Component {
/**
* Defines the type of data fields used for the series.
*/
public _dataFields: ISeriesDataFields;
/**
* Defines available properties.
*/
public _properties!: ISeriesProperties;
/**
* Defines available adapters.
*/
public _adapter!: ISeriesAdapters;
/**
* Defines available events.
*/
public _events!: ISeriesEvents;
/**
* Defines a type of data item used for the series.
*/
public _dataItem: SeriesDataItem;
/**
* A reference to the legend data item related to this series.
*/
protected _legendDataItem: LegendDataItem;
/**
* Should this series excluded from the axis scale calculations?
*
* @default false
*/
protected _ignoreMinMax: boolean = false;
/**
* Container series' elements are placed in.
*
* @ignore Exclude from docs
*/
public mainContainer: Container;
/**
* Should series' bullets?
*
* @default true
*/
protected _showBullets: boolean = true;
/**
* List of series' bullets.
*/
protected _bullets: ListTemplate<Sprite>;
/**
* Container bullets are placed in.
*
* @ignore Exclude from docs
*/
public bulletsContainer: Container;
/**
* A chart series belongs to.
*/
public _chart: SerialChart;
/**
* A container axis ranges are placed in.
*
* @ignore Exclude from docs
*/
public rangesContainer: Container;
/**
* A list of axis ranges for this series.
*/
public axisRanges: List<AxisDataItem>;
/**
* Settings for the appearance of the related legend items.
*/
public legendSettings: LegendSettings = new LegendSettings();
/**
* Lowest overal values by type.
*/
protected _tmin = new Dictionary<string, number>();
/**
* Highest overal values by type.
*/
protected _tmax = new Dictionary<string, number>();
/**
* Lowest values in current selection by type.
*/
protected _smin = new Dictionary<string, number>();
/**
* Highest values in current selection by type.
*/
protected _smax = new Dictionary<string, number>();
/**
* [dataItemsByAxis description]
*
* Both by category and date.
*
* @ignore Exclude from docs
* @todo Description
*/
public dataItemsByAxis = new Dictionary<string, Dictionary<string, this["_dataItem"]>>();
/**
* Normally series items are focusable using keyboard, so that people can
* select them with a TAB key. However, if there are a lot of data points on
* screen it might be long and useless to tab through all o fthem.
*
* This is where `skipFocusThreshold` comes in. If there are more items than
* the value set here, we will not make those focusable and rather let screen
* reader software rely on the series summary, or authors provide alternative
* detailed information display, such as HTML table.
*
* Different series might have different threshold defaults.
*/
public skipFocusThreshold: number = 20;
/**
* Holds a default screen reader text for series data items. It will be used
* to generate information for screen readers. If not set, the series will
* try to deduce reader text from `tooltipText` or `tooltipHTML`. If those
* are not set either, a default reader text will be used which is relevant
* for each Series type.
*/
protected _itemReaderText: string;
/*
public heatMapfillRule: (fill:Color, column: Sprite) => any = function(fill:Color, sprite: Sprite) {
let dataItem: SeriesDataItem = <SeriesDataItem>sprite.dataItem;
if (dataItem && dataItem.value) {
let series = dataItem.component;
if($type.hasValue(series.minColor) && $type.hasValue(series.maxColor) && $type.isNumber(series.minValue) && $type.isNumber(series.maxValue)){
let percent = (dataItem.values.value.workingValue - series.minValue) / (series.maxValue - series.minValue);
return new Color($colors.interpolate(series.minColor.rgb, series.maxColor.rgb, percent));
}
}
};
*/
protected _heatRules: List<IHeatRule>;
/**
* Most of the series use absolute values. However sometimes various
* calculated percent values are need, e.g. item's percent representation
* across all values in series, etc.
*
* It's a resource-intensive operation, so it is disabled by default.
*
* If you need percents to be calculated, e.g. for showing them in tooltips,
* or creating 100% stacks, this setting needs to be set to `true`.
*
* NOTE: `PieChart`, which relies on slice percentages, has this
* automatically set to `true`.
*
* @default false
*/
public calculatePercent: boolean = false;
/**
* Specifies if series should be automatically disposed when removing from
* chart's `series` list.
*
* @default true
*/
public autoDispose: boolean = true;
/**
* When chart/series' data is processed, all kinds of derivative values are
* calculated. E.g. sum, min, max, change, etc. This is a potentially
* time-consuming operation, especially prominent in data-heavy charts.
*
* If your chart does not need those values, and you have a lot of data,
* setting this to `true` might give a dramatic increase in initial chart
* load speed.
*
* Please note, regular column and line series usage scenarios do not
* require derivative values. Those come into play only when you do advanced
* functionality like coloring segments of charts in different colors
* depending on change between open and close values, have stacked series, or
* display any of the derived values, like percent, in tooltips or bullets.
*
* @default false
*/
public simplifiedProcessing: boolean = false;
/**
* Constructor
*/
constructor() {
super();
if (this.constructor === Series) {
throw new Error("'Series' cannot be instantiated directly. Please use a specific series type.");
}
this.className = "Series";
this.isMeasured = false;
this.layout = "none";
this.shouldClone = false;
this.setPropertyValue("hidden", false);
this.axisRanges = new List<AxisDataItem>();
this.axisRanges.events.on("inserted", this.processAxisRange, this, false);
this.minBulletDistance = 0; // otherwise we'll have a lot of cases when people won't see bullets and think it's a bug
this.mainContainer = this.createChild(Container);
this.mainContainer.shouldClone = false;
this.mainContainer.mask = this.createChild(Sprite);
this._disposers.push(this.mainContainer);
// all bullets should go on top of lines/fills. So we add a separate container for bullets and later set it's parent to chart.bulletsContainer
let bulletsContainer = this.mainContainer.createChild(Container);
this._shouldBeReady.push(bulletsContainer);
bulletsContainer.shouldClone = false;
bulletsContainer.layout = "none";
bulletsContainer.virtualParent = this;
this._disposers.push(bulletsContainer);
this.bulletsContainer = bulletsContainer;
this.tooltip = new Tooltip();
this.tooltip.virtualParent = this;
this._disposers.push(this.tooltip);
this.hiddenState.transitionEasing = $ease.cubicIn;
// this data item holds sums, averages, etc
this.dataItem = this.createDataItem();
this._disposers.push(this.dataItem);
this.dataItem.component = this;
// Apply accessibility
this.role = "group";
this.applyTheme();
}
/**
* We need this here so that class names can be applied to bullets container.
*
* @ignore Exclude from docs
*/
public applyTheme(): void {
super.applyTheme();
if (options.autoSetClassName && this.bulletsContainer) {
this.bulletsContainer.className = this.className + "-bullets";
this.bulletsContainer.setClassName();
}
}
/**
* Sets defaults that instantiate some objects that rely on parent, so they
* cannot be set in constructor.
*/
protected applyInternalDefaults(): void {
super.applyInternalDefaults();
if (!$type.hasValue(this.readerTitle)) {
this.readerTitle = this.language.translate("Series");
}
}
/**
* Returns a new/empty DataItem of the type appropriate for this object.
*
* @see {@link DataItem}
* @return Data Item
*/
protected createDataItem(): this["_dataItem"] {
return new SeriesDataItem();
}
/**
* Chart series is used on.
*
* @param value Chart
*/
public set chart(value: this["_chart"]) {
this._chart = value;
}
/**
* @return Chart
*/
public get chart(): this["_chart"] {
return this._chart;
}
/**
* Positions bullet.
*
* @param bullet Sprite
*/
public positionBullet(bullet: Sprite): void {
// Placeholder method for extending classes to override.
}
/**
* Decorates newly created bullet after it has been instert into the list.
*
* @param event List event
* @todo investigate why itemReaderText is undefined
*/
protected processBullet(event: IListEvents<Sprite>["inserted"]) {
let bullet: Sprite = event.newValue;
bullet.isTemplate = true;
// Add accessibility options to bullet
// If there are relatively few bullets, make them focusable
if (this.itemsFocusable()) {
bullet.focusable = true;
}
}
/**
* removes bullets
*
* @param event List event
*/
protected removeBullet(event: IListEvents<Sprite>["removed"]) {
let bullet: Sprite = event.oldValue;
this.dataItems.each((dataItem) => {
let eachBullet = dataItem.bullets.getKey(bullet.uid);
if (eachBullet) {
eachBullet.dispose();
}
})
this.invalidate();
}
/**
* Validates data items.
*
* @ignore Exclude from docs
*/
public validateDataItems() {
super.validateDataItems();
this.processValues(false);
}
/**
* Returns first value for the specific key in the series.
*
* @param key Key
* @return Value
* @todo Description
* @todo Convert to propert object property iterator
*/
protected getFirstValue(key: string, startIndex: number): number {
// find first
/*
return $iter.findMap(this.dataItems.iterator(), (dataItem) => {
for (let key in dataItem.values) {
if ($object.hasKey(dataItem.values, key)) {
let value: number = dataItem.values[key].workingValue;
if ($type.isNumber(value)) {
return value;
}
}
}
return null;
});*/
if (startIndex > 0 && startIndex < this.dataItems.length - 1) {
startIndex++;
}
for (let i = startIndex; i >= 0; i--) {
let dataItem = this.dataItems.getIndex(i);
let value: number = dataItem.getActualWorkingValue(key);
if ($type.isNumber(value)) {
return value;
}
}
return null;
}
/**
* [rangeChangeUpdate description]
*
* @todo Description
*/
protected rangeChangeUpdate() {
super.rangeChangeUpdate();
this.processValues(true);
}
/**
* [processValues description]
*
* @todo Description
* @todo Convert to propert object property iterator
* @param dataItems [description]
*/
protected processValues(working: boolean) {
if (!this.simplifiedProcessing) {
let dataItems = this.dataItems;
let count: { [index: string]: number } = {};
let sum: { [index: string]: number } = {};
let low: { [index: string]: number } = {};
let high: { [index: string]: number } = {};
let open: { [index: string]: number } = {};
let close: { [index: string]: number } = {};
let previous: { [index: string]: number } = {};
let first: { [index: string]: number } = {};
//let duration: number = 0; // todo: check if series uses selection.change or selection.change.percent and set duration to interpolationduration
let startIndex: number = $math.max(0, this._workingStartIndex);
startIndex = $math.min(startIndex, this.dataItems.length);
let endIndex: number = $math.min(this._workingEndIndex, this.dataItems.length);
if (!$type.isNumber(startIndex)) {
startIndex = 0;
}
if (!$type.isNumber(endIndex)) {
endIndex = this.dataItems.length;
}
if (startIndex > 0) {
let dataItem = dataItems.getIndex(startIndex - 1);
$object.each(dataItem.values, (key, values) => {
let value: number = dataItem.getActualWorkingValue(key);
if ($type.isNumber(value)) {
// save previous
previous[key] = value;
}
});
}
for (let i = startIndex; i < endIndex; i++) {
let dataItem = dataItems.getIndex(i);
$object.each(dataItem.values, (key, values) => {
let value: number = dataItem.getActualWorkingValue(key);
//if (i >= startIndex && i <= endIndex) { // do not add to count, sum etc if it is not within start/end index
if ($type.isNumber(value)) {
// count values
if (!$type.isNumber(count[key])) {
count[key] = 0;
}
count[key]++;
// sum values
if (!$type.isNumber(sum[key])) {
sum[key] = 0;
}
sum[key] += value;
// open
if (!$type.isNumber(open[key])) {
open[key] = value;
}
// close
close[key] = value;
// low
if (!$type.isNumber(low[key])) {
low[key] = value;
}
else {
if (low[key] > value) {
low[key] = value;
}
}
// high
if (!$type.isNumber(high[key])) {
high[key] = value;
}
else {
if (high[key] < value) {
high[key] = value;
}
}
if (!$type.isNumber(first[key])) {
first[key] = this.getFirstValue(key, startIndex);
}
// change
dataItem.setCalculatedValue(key, value - first[key], "change");
// change from start percent
// will fail if first value is 0
dataItem.setCalculatedValue(key, (value - first[key]) / first[key] * 100, "changePercent");
// previous change
let prevValue: number = previous[key];
if (!$type.isNumber(prevValue)) {
prevValue = value;
}
dataItem.setCalculatedValue(key, value - prevValue, "previousChange");
// previous change percent
dataItem.setCalculatedValue(key, (value - prevValue) / prevValue * 100, "previousChangePercent");
// save previous
previous[key] = value;
}
});
}
if (this.calculatePercent) {
for (let i = startIndex; i < endIndex; i++) {
let dataItem = dataItems.getIndex(i);
$object.each(dataItem.values, (key) => {
let ksum: number = sum[key];
let value: number = dataItem.getActualWorkingValue(key);
if ($type.isNumber(value)) {
if (ksum > 0) {
// this hack is made in order to make it possible to animate single slice to 0
// if there is only one slice left, percent value is always 100%, so it won't animate
// so we use real value of a slice instead of current value
if (value == ksum) {
ksum = dataItem.values[key].value;
}
let percent = value / ksum * 100;
dataItem.setCalculatedValue(key, percent, "percent");
}
else {
dataItem.setCalculatedValue(key, 0, "percent");
}
}
});
}
}
// calculate one before first (cant do that in cycle, as we don't know open yet
// when drawing line chart we should draw line to the invisible data point to the left, otherwise the line will always look like it starts from the selected point
// so we do startIndex - 1
if (startIndex > 0) {
let zeroItem: this["_dataItem"] = dataItems.getIndex(startIndex - 1);
$object.each(zeroItem.values, (key) => {
let value = zeroItem.values[key].value;
// change
zeroItem.setCalculatedValue(key, value - open[key], "change");
// change percent
zeroItem.setCalculatedValue(key, (value - open[key]) / open[key] * 100, "changePercent");
});
}
// we save various data like sum, average to dataPoint of the series
let dataItem: DataItem = this.dataItem;
$object.each(dataItem.values, (key) => {
dataItem.setCalculatedValue(key, sum[key], "sum");
dataItem.setCalculatedValue(key, sum[key] / count[key], "average");
dataItem.setCalculatedValue(key, open[key], "open");
dataItem.setCalculatedValue(key, close[key], "close");
dataItem.setCalculatedValue(key, low[key], "low");
dataItem.setCalculatedValue(key, high[key], "high");
dataItem.setCalculatedValue(key, count[key], "count");
});
}
}
/**
* (Re)validates the whole series, effectively causing it to redraw.
*
* @ignore Exclude from docs
*/
public validate(): void {
$iter.each(this.axisRanges.iterator(), (axisRange) => {
//axisRange.contents.disposeChildren(); // not good for columns, as they are reused
// axisRange.appendChildren();
axisRange.validate();
});
super.validate();
let bulletsContainer = this.bulletsContainer;
bulletsContainer.fill = this.fill;
bulletsContainer.stroke = this.stroke;
bulletsContainer.x = this.pixelX;
bulletsContainer.y = this.pixelY;
if (this.bulletsContainer.children.length > 0) {
if (this._showBullets) {
for (let i = 0; i < this.startIndex; i++) {
let dataItem = this.dataItems.getIndex(i);
if (dataItem) {
dataItem.bullets.each((key, bullet) => {
bullet.__disabled = true;
})
}
}
for (let i = this.dataItems.length - 1; i > this.endIndex; i--) {
let dataItem = this.dataItems.getIndex(i);
if (dataItem) {
dataItem.bullets.each((key, bullet) => {
bullet.__disabled = true;
})
}
}
}
else {
this.bulletsContainer.children.each((bullet) => {
bullet.__disabled = true;
})
}
}
this.updateTooltipBounds();
}
/**
* @ignore
*/
public updateTooltipBounds() {
if (this.topParent) {
this.tooltip.setBounds({ x: 0, y: 0, width: this.topParent.maxWidth, height: this.topParent.maxHeight });
}
}
protected shouldCreateBullet(dataItem: this["_dataItem"], bulletTemplate: Sprite): boolean {
return true;
}
/**
* Validates data item's element, effectively redrawing it.
*
* @ignore Exclude from docs
* @param dataItem Data item
*/
public validateDataElement(dataItem: this["_dataItem"]): void {
super.validateDataElement(dataItem);
if (this._showBullets) {
if (!this.isHidden) {
this.bulletsContainer.visible = true;
}
this.bullets.each((bulletTemplate) => {
// always better to use the same, this helps to avoid redrawing
let bullet: Sprite = <Sprite>dataItem.bullets.getKey(bulletTemplate.uid);
if (this.shouldCreateBullet(dataItem, bulletTemplate)) {
if (!bullet) {
let disabledField = bulletTemplate.propertyFields.disabled;
let dataContext = <any>dataItem.dataContext;
if (disabledField && dataContext && dataContext[disabledField] === false) {
bulletTemplate.applyOnClones = false;
bulletTemplate.disabled = false;
bullet = bulletTemplate.clone();
bulletTemplate.disabled = true;
bulletTemplate.applyOnClones = true;
}
else {
bullet = bulletTemplate.clone();
}
bullet.shouldClone = false;
dataItem.addSprite(bullet);
if (!this.visible || this.isHiding) {
bullet.hide(0);
}
}
let currentDataItem: this["_dataItem"] = <this["_dataItem"]>bullet.dataItem;
if (currentDataItem != dataItem) {
// set to undefined in order not to reuse
if (currentDataItem) {
currentDataItem.bullets.setKey(bulletTemplate.uid, undefined);
}
let readerText = this.itemReaderText;
if (bullet instanceof Bullet) {
if (!readerText) {
readerText = ("{" + bullet.xField + "}: {" + bullet.yField + "}");
}
if (bullet.isDynamic) {
dataItem.events.on("workingvaluechanged", bullet.deepInvalidate, bullet, false);
//dataItem.events.on("calculatedvaluechanged", bullet.deepInvalidate, bullet, false);
this.dataItem.events.on("workingvaluechanged", bullet.deepInvalidate, bullet, false);
}
bullet.deepInvalidate();
}
// Add accessibility to bullet
if (bullet.focusable) {
bullet.events.on("focus", (ev) => {
bullet.readerTitle = this.populateString(readerText, bullet.dataItem);
}, undefined, false);
bullet.events.on("blur", (ev) => {
bullet.readerTitle = "";
}, undefined, false);
}
if (bullet.hoverable) {
bullet.events.on("over", (ev) => {
bullet.readerTitle = this.populateString(readerText, bullet.dataItem);
}, undefined, false);
bullet.events.on("out", (ev) => {
bullet.readerTitle = "";
}, undefined, false);
}
}
bullet.parent = this.bulletsContainer;
dataItem.bullets.setKey(bulletTemplate.uid, bullet);
// pass max w/h so we'd know if we should show/hide somethings
bullet.maxWidth = dataItem.itemWidth;
bullet.maxHeight = dataItem.itemHeight;
bullet.__disabled = false;
this.positionBullet(bullet);
}
});
}
else {
this.bulletsContainer.visible = false;
}
}
/**
* [handleDataItemWorkingValueChange description]
*