-
Notifications
You must be signed in to change notification settings - Fork 46
/
px-vis-behavior-common.html
3609 lines (3161 loc) · 91.9 KB
/
px-vis-behavior-common.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!--
Copyright (c) 2018, General Electric
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="px-vis-polyfills.html" />
<link rel="import" href="px-vis-behavior-colors.html" />
<script>
var PxVisBehavior = window.PxVisBehavior = (window.PxVisBehavior || {});
/**
Name:
PxVisBehavior.observerCheck
Description:
Polymer behavior that provides a function used to check if any argument
in an observer is undefined
@polymerBehavior PxVisBehavior.observerCheck
*/
PxVisBehavior.observerCheck = {
hasUndefinedArguments: function(args) {
for(var i=0; i<args.length; i++) {
//check if arg is undefined or if it's a 'var.*' undefined type of arg
if(args[i] === undefined || (args[i] && args[i].path && args[i].hasOwnProperty('base') && args[i].base === undefined)) {
return true;
}
}
return false;
}
};
/*
Name:
PxVisBehavior.baseSize
Description:
Polymer behavior that provides height and width
@polymerBehavior PxVisBehavior.baseSize
*/
PxVisBehavior.baseSize = {
properties: {
/**
* The width of the elem; generally the width of the charting area for most components
*
*/
width: {
type: Number,
notify: true
},
/**
* The height of the component; generally the height of the charting area for most components.
*
*/
height: {
type: Number,
notify: true
}
}
};
/*
Name:
PxVisBehavior.margins
Description:
Polymer behavior that provides margin definitions
@polymerBehavior PxVisBehavior.margins
*/
PxVisBehavior.margins = {
properties: {
/**
* Copy of the default margin for checking if it has changed
*
*/
_defaultMargin:{
type:Object,
value: function() {
return {
left: 0,
right: 0,
top: 0,
bottom: 0
};
}
},
/**
* Defines the base margin for the chart. Calcs are run to add to the margin to accommodate axes and other elements which exist within the SVG frame, but outside the chart frame.
*
*/
margin:{
type:Object,
value: function() {
return {
left: 0,
right: 0,
top: 0,
bottom: 0
};
}
}
}
};
/*
Name:
PxVisBehavior.sizing
Description:
Polymer behavior that provides the basic sizing properties for px-vis components.
Dependencies:
- none
@polymerBehavior PxVisBehavior.sizing
*/
PxVisBehavior.sizing = [{
properties: {
/**
* An optional offset for a variety of elements
*
*
*/
offset: {
type: Array,
value: function() {
return [0,0];
}
}
}
}, PxVisBehavior.baseSize, PxVisBehavior.margins];
/*
Name:
PxVisBehavior.truncating
Description:
Polymer behavior that provides the string truncation method
@polymerBehavior PxVisBehavior.truncating
*/
PxVisBehavior.truncating = {
properties: {
/**
* Defines if the label should get truncated and to how many characters.
*
* Default length is 10 characters, not including the ellipsis which gets inserted.
*
* The length must be at least 2.
*
* To disable truncation, set the value to -1
*
* @property truncationLength
* @type Number
* @default 10
*/
truncationLength: {
type: Number,
value: 10
},
},
/**
* _truncateName takes a string and string length [optional].
* Returns a truncated string with the middle replaced by an ellipsis. The ellipsis does not count towards the total character count.
* Follows these truncation principles: http://www.gesdh.com/predix/product/principles/truncation/
* Example: LNG_BAH_HOT_EFFECTIVENESS_CORE8 --> LNG_B...CORE8
*
* Length cannot be less than 2 characters.
* Default length is 10 characters.
*
* If the string is less than or equal to the length or the length is invalid, returns the original string.
*
* @param {String} name, {Integer} len
* @return {String} truncatedString
*/
_truncateName:function(name,len) {
var len = len || this.truncationLength;
// make sure length is legit
if(len < 2) {
return name;
}
//check that name is greater than length; if not, return it
if(name.length <= len) {
return name;
}
// truncate
var frontLen = Math.ceil(len / 2),
backLen = Math.floor(len / 2),
front = name.slice(0,frontLen),
back = name.slice(-backLen);
return front + '...' + back;
}
};
/*
Name:
PxVisBehavior.formatting
Description:
Polymer behavior that provides the string and number formating options and methods. Includes name truncation and numbro-element number formating options.
Dependencies:
- numbro-element components
@polymerBehavior PxVisBehavior.formatting
*/
PxVisBehavior.formatting = [{
properties: {
/**
* Defines how a display number should be formatted:
* Provide localization for currency formatting
*
* For valid formats and features, see: http://numbrojs.com/languages.html
* For docs on the component, see: https://www.predix-ui.com/#/components/px-number-formatter/
*
* @property numberFormatCulture
* @type String
* @default 'en-US'
*/
numberFormatCulture: {
type:String
},
/**
* Defines how a display number should be formatted:
* Specify whether the value should be formatted as a currency
*
* For valid formats and features, see: http://numbrojs.com/format.html
* For docs on the component, see: https://www.predix-ui.com/#/components/px-number-formatter/
*
* @property numberFormatIsCurrency
* @type Boolean
* @default false
*/
numberFormatIsCurrency: {
type :Boolean,
value: false
},
/**
* Defines how a display number should be formatted:
* Provide a new default format for currency
*
* For valid formats and features, see: http://numbrojs.com/format.html
* For docs on the component, see: https://www.predix-ui.com/#/components/px-number-formatter/
*
* @property numberFormatCurrency
* @type String
* @default '$0,0.00'
*/
numberFormatCurrency: {
type: String,
value:'$0,0.00'
},
/**
* Defines how a display number should be formatted:
* Provides a new default format
*
* For valid formats and features, see: http://numbrojs.com/format.html
* For docs on the component, see: https://www.predix-ui.com/#/components/px-number-formatter/
*
* @property numberFormatDefault
* @type String
* @default '0,0.0000'
*/
numberFormatDefault: {
type: String,
value: '0,0.0000'
},
/**
* Defines how a display number should be formatted:
* The format used to generate the output
*
* For valid formats and features, see: http://numbrojs.com/format.html
* For docs on the component, see: https://www.predix-ui.com/#/components/px-number-formatter/
*
* @property numberFormat
* @type String
* @default '0,0.00'
*/
numberFormat: {
type: String,
value: '0,0.00'
},
/**
* Defines how a display number should be converted back to a Number:
* A formatted String to extract a value from
*
* For valid formats and features, see: http://numbrojs.com/format.html#unformat
* For docs on the component, see: https://www.predix-ui.com/#/components/px-number-formatter/
*
* @property numberFormatUnformat
* @type String
* @default '0,0.0000'
*/
numberFormatUnformat: {
type: String,
value: '0,0.0000'
},
/**
* Defines how to display 0 values
*
* For valid formats and features, see: http://numbrojs.com/format.html
* For docs on the component, see: https://www.predix-ui.com/#/components/px-number-formatter/
*
* @property numberFormatZero
* @type String
* @default ''
*/
numberFormatZero: {
type: String,
value:'0'
}
}
}, PxVisBehavior.truncating];
/*
Name:
PxVisBehavior.dataChecks
Description:
Polymer behavior that provides the data checkting methods
Dependencies:
- D3.js
@polymerBehavior PxVisBehavior.dataChecks
*/
PxVisBehavior.dataChecks = {
/**
* returns true if the data is valid: non NaN, null or undefined
*/
_isValidData: function(d) {
//false and "" will return false, which is fine as they're not valid data
return d || d === 0;
},
/**
* returns true if the data is not null
*/
_isDataNotNull: function(d) {
//false and "" will return false, which is fine as they're not valid data
return d !== null;
}
};
/*
Name:
PxVisBehavior.dataset
Description:
Polymer behavior that provides the data object for d3 components.
Dependencies:
- D3.js
@polymerBehavior PxVisBehavior.dataset
*/
PxVisBehavior.dataset = [{
properties: {
/**
* container for the data object that drives the chart / component
* Generally loaded with an iron-ajax tag (but doesnt have to be)
* This can be set declaratively
*
* @property chartData
* @type Object
*/
chartData:{
type: Array
}
}
}, PxVisBehavior.dataChecks];
/*
Name:
PxVisBehavior.completeSeriesConfig
Description:
Polymer behavior that provides a computed series configuration object to components.
Dependencies:
- D3.js
@polymerBehavior PxVisBehavior.completeSeriesConfig
*/
PxVisBehavior.completeSeriesConfig = {
properties: {
/**
* A configuration file generated by the chart behavior based on seriesConfig and defaultSeriesConfig.
*
*/
completeSeriesConfig: {
type: Object,
notify: true
}
}
};
/*
Name:
PxVisBehavior.combinedMutedSeries
Description:
Polymer behavior that provides the combinedMutedSeries property px-vis components.
Dependencies:
-
@polymerBehavior PxVisBehavior.combinedMutedSeries
*/
PxVisBehavior.combinedMutedSeries = {
properties: {
/**
* Aimed at regrouping all muted series when different behavior can mute
* series (multi series for example: brush + navigator + categories)
*/
combinedMutedSeries:{
type:Object,
notify: true,
value:function(){ return {}; },
}
}
};
/*
Name:
PxVisBehavior.mutedSeries
Description:
Polymer behavior that provides the mutedSeries property px-vis components.
Dependencies:
-
@polymerBehavior PxVisBehavior.mutedSeries
*/
PxVisBehavior.mutedSeries = [{
properties: {
/**
* A list of user selected muted series. Tied declaratively to series components
*
* The series name is the key and the value is a boolean for whether it is muted or not:
*
*```
* {
* 'seriesId1':true,
* 'seriesId2':false,
* }
*```
*
* In this example, seriesId1 is muted. seriesId2 was muted, but has been turned back on.
*
*/
mutedSeries:{
type:Object,
notify: true,
value:function(){ return {}; },
},
/**
* Allows for a "hard" muting of the series/categories: the
* series/category won't show up
* in the tooltip anymore, it's tooltip data won't be shown in the register
* and its extents won't be taken into account by the chart
*/
hardMute: {
type: Boolean,
value: false
}
}
}, PxVisBehavior.completeSeriesConfig];
/*
Name:
PxVisBehavior.seriesKeys
Description:
Polymer behavior that provides the seriesKeys definition
Dependencies:
- D3.js
@polymerBehavior PxVisBehavior.seriesKeys
*/
PxVisBehavior.seriesKeys = {
properties: {
/**
* Representes the keys avaiable in completeSeriesConfig.
*/
seriesKeys: {
type: Array,
value: function() {
return [];
}
}
}
};
/*
Name:
PxVisBehavior.mutedCompleteSeriesConfig
Description:
Polymer behavior that provides the _mutedCompleteSeriesConfig property
Dependencies:
-
@polymerBehavior PxVisBehavior.mutedCompleteSeriesConfig
*/
PxVisBehavior.mutedCompleteSeriesConfig = [{
properties: {
_mutedCompleteSeriesConfig: {
type: Object,
computed: '_computeMutedCompleteSeriesConfig(completeSeriesConfig, hardMute, mutedSeries.*)'
},
_nonMutedSeriesKeys: {
type: Array,
computed: '_computeNonMutedSeriesKeys(_mutedCompleteSeriesConfig,seriesKeys)'
}
},
_computeNonMutedSeriesKeys: function() {
if(this.hasUndefinedArguments(arguments)) {
return;
}
if(!(this._mutedCompleteSeriesConfig === undefined || this.seriesKeys === undefined)) {
var keys = Object.keys(this._mutedCompleteSeriesConfig);
//ensure all keys exists in case we deleted some but haven't updated
//the completeSeriesConfig yet
return keys.filter(function(key) {
return this.seriesKeys.indexOf(key) !== -1;
}.bind(this));
}
},
_computeMutedCompleteSeriesConfig: function(completeSeriesConfig, hardMute, mutedSeries) {
if(this.hasUndefinedArguments(arguments)) {
return;
}
if(!(this.completeSeriesConfig === undefined || this.hardMute === undefined || this.mutedSeries === undefined)) {
if(!this.hardMute) {
return this.completeSeriesConfig;
} else {
//create a new conf without the muted series
var newConf = {},
keys = Object.keys(this.completeSeriesConfig);
for(var i=0; i<keys.length; i++) {
if(!this.mutedSeries[keys[i]]) {
newConf[keys[i]] = this.completeSeriesConfig[[keys[i]]];
}
}
return newConf;
}
}
},
}, PxVisBehavior.observerCheck, PxVisBehavior.completeSeriesConfig, PxVisBehavior.mutedSeries, PxVisBehavior.seriesKeys];
/*
Name:
PxVisBehavior.muteUnmuteSeries
Description:
Polymer behavior that provides the mutedSeries property and methods to mute/unmute series for px-vis components.
Dependencies:
-
@polymerBehavior PxVisBehavior.muteUnmuteSeries
*/
PxVisBehavior.muteUnmuteSeries = [{
properties: {},
/**
* Method to mute or umute
*
*/
muteUnmuteSeries: function(series, fromRegister) {
//TODO Polymer 2.0: fix this
// make sure we are not dealing with APM's IDs
if(series.indexOf('.') === -1) {
// if it doesnt exist, let's add it and set to true
if( typeof(this.mutedSeries[series]) === 'undefined' ) {
this.set('mutedSeries.' + series, true);
} else {
//if does exist, flip the bit
this.set('mutedSeries.' + series, !this.mutedSeries[series]);
}
} else {
var muted = this.mutedSeries;
this.mutedSeries = [];
muted[series] = typeof(muted[series]) === 'undefined' ? true : !muted[series];
this.set('mutedSeries', muted);
}
this.fire('px-vis-muted-series-updated', { 'name': series, 'value': this.mutedSeries[series], 'fromRegister': fromRegister});
}
}, PxVisBehavior.mutedSeries];
/*
Name:
PxVisBehavior.tooltipData
Description:
Polymer behavior that provides the tooltipData property px-vis components.
Dependencies:
-
@polymerBehavior PxVisBehavior.tooltipData
*/
PxVisBehavior.tooltipData = {
properties: {
/**
* Data reported back by the interaction space component. Displays the series name, values, and timestamp in the register. tooltipData is in the form:
*
*```
* {
* "time": "2015-03-25T20:34:47.085Z",
* "hidden": false,
* "series":[{
* "name":"seriesId1",
* "coord":[xCoord1, yCoord1], //in pixel space
* "value":{
* "x":xVal1, //in data space
* "seriesId1":yVal1 //in data space
* }
* },{
* "name":"seriesId2",
* "coord":[xCoord2, yCoord2], //in pixel space
* "value":{
* "x":xVal2, //in data space
* "seriesId2":yVal2 //in data space
* },
* }],
* "mouse":[ mouseX, mouseY ], //in pixel space
* "xArr":[xCoord1 , xCoord2], //in pixel space
* "yArr":[yCoord1 , yCoord2], //in pixel space
* }
*```
*
* When not hovering on a chart, the tooltipData should still have the series names in order for them to still appear in the register. IE:
*
*```
* {
* "time": null,
* "hidden": true,
* "series":[{
* "name":"seriesId1",
* "value": null
* },{
* "name":"seriesName1",
* "value": null
* }],
* "mouse": null,
* "xArr": null,
* "yArr": null
* }
*```
*
* @property tooltipData
* @type Object
*/
tooltipData:{
type:Object,
notify:true
},
/**
* The "empty" dataset that should be used for tooltipData when not hovering
*/
defaultEmptyData: {
type: Object,
value: null,
notify:true
}
}
};
/*
Name:
PxVisBehavior.crosshairData
Description:
Polymer behavior that provides the crosshairData property px-vis components.
Dependencies:
-
@polymerBehavior PxVisBehavior.crosshairData
*/
PxVisBehavior.crosshairData = {
properties: {
/**
* Data reported back by the interaction space component so charts can share a crosshair. Has two sets of data: 1) the full data retrieved at the shared key so if all charts use the same datasets, this data can just be displayed on all the charts. 2) a list of just the shared key so if they use different datasets, a search for the closest data at each point can be made. crosshairData is in the form:
*
*```
* {
* "rawData":[{
* "[[sharedKey]]": [[sharedKeyVal1]],
* "[[key1]]":[[val]],
* "[[key2]]":[[val]]
* },{
* "[[sharedKey]]": [[sharedKeyVal2]],
* "[[key1]]":[[val]],
* "[[key2]]":[[val]]
* }],
* "timeStamps":[ timeStamp1, timeStamp2 ]
* }
*```
* @property crosshairData
* @type Object
*/
crosshairData: {
type: Object,
notify: true
},
/**
* Bool indicating if interaction space is currently generating data
*
**/
generatingCrosshairData: {
type: String,
value: false,
notify: true
},
/**
* Allows the crosshair to search all datapoints within a pixel radius. If set
* to 0 will only pick up the closest point
*/
crosshairPixelSearch: {
type: Number,
value: 0
}
}
};
/*
Name:
PxVisBehavior.extentsData
Description:
Polymer behavior that provides the extentsData property px-vis components.
Dependencies:
-
@polymerBehavior PxVisBehavior.extentsData
*/
PxVisBehavior.extentsData = {
properties: {
/**
* Data reported back by the interaction space. Displays the interpreted x & y coords, width and height, and domain extents. extentsData is in the form:
*
*```
* {
* x1 = {pixel-space}
* y1 = {pixel-space}
* x2 = {pixel-space}
* y2 = {pixel-space}
* w = {pixels}
* h = {pixels}
* eX = [{domain}, {domain}];
* eY = [{domain}, {domain}];
* }
*```
*
* @property extentsData
* @type Object
*/
extentsData:{
type:Object,
notify:true
},
/**
* Used by the chart to interpret if extentsData is strip or zoom
*/
extentsAction: {
type: String,
notify: true
}
}
};
/*
Name:
PxVisBehavior.commonMethods
Description:
Polymer behavior that provides the commonMethods properties px-vis components.
Dependencies:
-
@polymerBehavior PxVisBehavior.commonMethods
*/
PxVisBehavior.commonMethods = [{
/**
* Checks to see if an object is empty
*
* @param {object}
* @return {bool}
*/
_isObjEmpty:function(obj){
if(typeof(obj) === 'undefined' || obj === null) {
return true;
}
if(obj.length) {
return !obj.length;
}
return !this._hasProps(obj);
},
/**
* Checks to see if an d3 obj is empty
*
* @param {object}
* @return {bool}
*/
_isD3Empty:function(obj) {
if(this._isObjEmpty(obj)) {
return true;
}
return obj.empty();
},
/**
* Checks to see if an d3 obj has something
*
* @param {object}
* @return {bool}
*/
_doesD3HaveValues:function(obj){
if(this._isObjEmpty(obj)) {
return false;
}
return !obj.empty();
},
/**
* Checks to see if an object has values
*
* @param {object}
* @return {bool}
*/
_doesObjHaveValues:function(obj){
if(typeof(obj) === 'undefined' || obj === null) {
return false;
}
if(obj.length) {
return !!obj.length;
}
return this._hasProps(obj);
},
_hasProps: function(obj) {
//use iterator over object to find out if we have any property,
//faster than Object.keys for big objects
var i = 0;
for(var prop in obj) {
if(Object.prototype.hasOwnProperty.call(obj, prop)) {
i++;
break;
}
}
return i!==0;
},
/**
* Checks to see if an object is defined
*
* @param {object}
* @return {bool}
*/
_isVarDefined:function(obj){
if(typeof(obj) === 'undefined'){
return false;
}
return true;
},
/**
* Checks to see if an object is defined
*
* @param {object}
* @return {bool}
*/
_isVarUndefined:function(obj){
if(typeof(obj) === 'undefined'){
return true;
}
return false;
},
/**
* escapes '.' in css selectors so that we can appropriately select stuff with dots in thei ids
*/
_escapeCssSelector: function(selector) {
return selector.replace('.', '\\.');
},
/**
* Checks if a theme variable exists, if so, returns the theme value, if not, returns the default
*/
_checkThemeVariable: function(varName, defaultValue) {
var themeVar;
if (Polymer.Element) {
// 2.0 code
if (window.ShadyCSS) {
themeVar = ShadyCSS.getComputedStyleValue(this, varName);
} else {
themeVar = getComputedStyle(this).getPropertyValue(varName);
}
} else {
// 1.0 code
themeVar = this.getComputedStyleValue(varName);
}
return (!themeVar || themeVar.length === 0) ? defaultValue : themeVar;
},
/**
* converts a hex to rgb color
*/
_hexToRgb: function(hex) {
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, function(m, r, g, b) {
return r + r + g + g + b + b;
});
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? 'rgb(' + parseInt(result[1], 16) + ',' +
parseInt(result[2], 16)+ ',' +
parseInt(result[3], 16) + ')' : null;
},
/**
* Binary search through sorted chartData
*/
_binarySearch: function(data, key, val, lowerIndex, upperIndex) {
if(this.isVarNumber(lowerIndex) && this.isVarNumber(upperIndex) && lowerIndex === upperIndex) {
return null;
}
var upperIndex = this.isVarNumber(upperIndex) ? upperIndex : data.length,
lowerIndex = this.isVarNumber(lowerIndex) ? lowerIndex : 0,
index = Math.floor((upperIndex - lowerIndex) / 2) + lowerIndex,
dataVal = Number(data[index][key]);
if(dataVal === val) {
return data[index];
} else if(val < dataVal) {
return this._binarySearch(data, key, val, lowerIndex, index);
} else if(val > dataVal) {
return this._binarySearch(data, key, val, index+1, upperIndex);
}
return null;
},
/**
* Binary search through sorted chartData returning all vals within a window
*/
_fuzzyBinarySearch: function(data, key, lowerFuzz, upperFuzz, lowerIndex, upperIndex) {
if(this.isVarNumber(lowerIndex) && this.isVarNumber(upperIndex) && lowerIndex >= upperIndex) {
return null;