-
Notifications
You must be signed in to change notification settings - Fork 46
/
px-vis-behavior-d3.html
2112 lines (1859 loc) · 52.9 KB
/
px-vis-behavior-d3.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-d3-imports/px-d3-imports.html" />
<link rel="import" href="px-vis-imports.html" />
<link rel="import" href="px-vis-behavior-common.html" />
<link rel="import" href="px-vis-scheduler.html" />
<link rel="import" href="../iron-meta/iron-meta.html">
<script>
var PxVisBehaviorD3 = window.PxVisBehaviorD3 = (window.PxVisBehaviorD3 || {});
/*
Name:
PxVisBehaviorD3.svg
Description:
Polymer behavior that provides the svg property and core methods for d3 components.
Dependencies:
- D3.js
@polymerBehavior PxVisBehaviorD3.svg
*/
PxVisBehaviorD3.svg = [{
properties: {
/**
* svg is a holder for the d3 instantiated svg container to draw to.
* Must be set in ready and passed to all components so they know whom to draw to.
*
* @property svg
* @type Object
*/
svg: {
type: Object,
notify: true
},
/*
*
* The SVG element inside the chart - not a D3 selected element.
*/
pxSvgElem: {
type: Object,
notify:true
}
},
/**
* Generates a random id string.
*
* Takes a string prefix, then adds 10 random chars
*
* @param {string}
* @return {id string}
*/
generateRandomID: function(baseStr) {
var id = baseStr,
abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
len = abc.length;
for(var i = 0; i < 10; i++){
id += abc.charAt(Math.floor(Math.random() * len));
}
Px.uniqueIds = Px.uniqueIds || [];
if(Px.uniqueIds.indexOf(id) !== -1) {
//id exists, recreate it.
return this.generateRandomID(baseStr);
} else {
Px.uniqueIds.push(id);
}
return id;
},
/*
* Clones a SVG elem and sets a component property with the d3 instance of that clone.
*
* The intent of this is to clone the high level 'g' elem we draw to and attach it.
* The draw order matters in SVG and we want the some stuff to appear on top of everything else
* Since we cannot easily ensure it draw order with components, we can stick top level items in a different 'g' that we know is drawn after the main 'g'
*
* @param {element}
* @param {string}
*/
cloneSVGElem: function(svg,prop,onBottom) {
var tempSVG = svg,
clone = tempSVG.cloneNode();
if(!onBottom || tempSVG.parentNode.childNodes.length === 0) {
tempSVG.parentNode.appendChild(clone);
} else {
tempSVG.parentNode.insertBefore(clone, tempSVG.parentNode.firstChild );
}
this.set(prop,Px.d3.select(clone));
},
/**
* Draws the current svg into a canvas
*/
_drawSVGOnCanvas: function(canvas, elem, callback, x, y) {
var svgData = elem.outerHTML,
opacity = getComputedStyle(elem).getPropertyValue('opacity'),
oldAlpha = canvas.globalAlpha,
canvasContext = canvas.getContext('2d');
x = x ? x : 0;
y = y ? y : 0;
canvasContext.globalAlpha = opacity;
//stupid IE can't get outerHTML of svg even though it's now a W3C spec
if(!svgData) {
svgData = this._getSVGOuterHtml(elem);
}
//check if drawing an svg on canvas is ok
var smallSvg = '<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200"><div></div></svg>',
testCanvas = document.createElement('canvas'),
successLoadImage,
failureLoadImage;
failureLoadImage = function() {
//fallback on canvg
this._drawCanvg(canvas, svgData, x, y, function() {
canvasContext.globalAlpha = oldAlpha;
callback(this.resultCanvas);
});
}.bind(this);
successLoadImage = function(testedCanvas) {
//image has been loaded successfully on canvas, now test if it has been tainted
try {
testedCanvas.toDataURL();
//ok no error were thrown, we can proceed
this._nativeDrawSvgOnCanvas(canvas, svgData, x, y, function() {
canvasContext.globalAlpha = oldAlpha;
callback(canvas);
}, function() {
//fallback on canvg
this._drawCanvg(canvas, svgData, x, y, function() {
canvasContext.globalAlpha = oldAlpha;
callback(this.resultCanvas);
});
}.bind(this));
} catch(err) {
//fallback on canvg
this._drawCanvg(canvas, svgData, x, y, function() {
canvasContext.globalAlpha = oldAlpha;
callback(this.resultCanvas);
});
}
}.bind(this);
this._nativeDrawSvgOnCanvas(testCanvas, smallSvg, x, y, successLoadImage, failureLoadImage);
},
/**
* Uses canvg third party to "translate" svg to javascript instructions
* for the canvas, and draw on the canvas
*/
_drawCanvg: function(canvas, svgData, x, y, callback) {
var options = {ignoreDimensions: true,
ignoreClear: true,
renderCallback: callback,
offsetX: x,
offsetY: y,
resultCanvas: canvas};
canvg(canvas, svgData, options);
},
/**
* Tries to draw the SVG to canvas and if that doesnt work, falls back on a failure callback
*/
_nativeDrawSvgOnCanvas: function(canvas, svgData, x, y, sucessCallback, failureCallback) {
//detect canvas tainting failures
var DOMURL = window.URL || window.webkitURL || window,
blob = new Blob([svgData], {type: 'image/svg+xml;charset=utf-8'}),
url = DOMURL.createObjectURL(blob),
img = new Image();
//once svg has been loaded
img.onload = function() {
//catching error for IE 11 here:
//http://stackoverflow.com/questions/25214395/unexpected-call-to-method-or-property-access-while-drawing-svg-image-onto-canvas
try {
canvas.getContext('2d').drawImage(img, x, y);
DOMURL.revokeObjectURL(url);
} catch(err) {
failureCallback(canvas);
return;
}
sucessCallback(canvas);
};
//Safari...
img.onerror = function(err) {
failureCallback(canvas);
}.bind(this);
img.src = url;
},
/**
* fix for IE to get outer HTML
*/
_getSVGOuterHtml: function(svg) {
var serializeXML = function(node, output) {
var nodeType = node.nodeType;
if (nodeType == 3) { // TEXT nodes.
// Replace special XML characters with their entities.
output.push(node.textContent.replace(/&/, '&').replace(/</, '<').replace('>', '>'));
} else if (nodeType == 1) { // ELEMENT nodes.
// Serialize Element nodes.
output.push('<', node.tagName);
if (node.hasAttributes()) {
var attrMap = node.attributes;
for (var i = 0, len = attrMap.length; i < len; ++i) {
var attrNode = attrMap.item(i);
output.push(' ', attrNode.name, '=\'', attrNode.value, '\'');
}
}
if (node.hasChildNodes()) {
output.push('>');
var childNodes = node.childNodes;
for (var i = 0, len = childNodes.length; i < len; ++i) {
serializeXML(childNodes.item(i), output);
}
output.push('</', node.tagName, '>');
} else {
output.push('/>');
}
} else if (nodeType == 8) {
// TODO(codedread): Replace special characters with XML entities?
output.push('<!--', node.nodeValue, '-->');
} else {
// TODO: Handle CDATA nodes.
// TODO: Handle ENTITY nodes.
// TODO: Handle DOCUMENT nodes.
throw 'Error serializing XML. Unhandled node of type: ' + nodeType;
}
}
var output = [];
var childNode = svg.firstChild;
while (childNode) {
serializeXML(childNode, output);
childNode = childNode.nextSibling;
}
return '<svg xmlns="' + svg.attributes.xmlns.value + '" width="' +
svg.attributes.width.value + '" height="' + svg.attributes.height.value +
'">' + output.join('') + '</svg>';
}
}, PxVisBehavior.svgDefinition, PxVisBehavior.uniqueIds];
/*
Name:
PxVisBehaviorD3.svg
Description:
Polymer behavior that provides the svg properties when there are two svgs in a chart.
Dependencies:
- D3.js
@polymerBehavior PxVisBehaviorD3.svgLower
*/
PxVisBehaviorD3.svgLower = [{
properties: {
/*
*
* The SVG element inside the chart - not a D3 selected element. Used when there are two svgs in a chart
*/
pxSvgElemLower: {
type: Object,
notify:true
}
}
}, PxVisBehavior.svgLowerDefinition];
/*
Name:
PxVisBehaviorD3.canvasContext
Description:
Polymer behavior that provides the canvasContext property.
Dependencies:
- D3.js
@polymerBehavior PxVisBehaviorD3.canvasContext
*/
PxVisBehaviorD3.canvasContext = [{
properties: {
/**
* canvasContext is a holder for the instantiated canvas context to draw to.
* Must be set in ready and passed to all components so they know whom to draw to.
*
*/
canvasContext: {
type: Object,
notify:true
},
/**
* An array of the generated layers
*
*/
canvasLayers: {
type: Object,
notify: true,
value: function() { return {}; }
}
}
}, PxVisBehavior.canvasLayersConfig];
/*
Name:
PxVisBehaviorD3.canvas
Description:
Polymer behavior that provides the canvasContext and renderToSvg properties
Dependencies:
- D3.js
@polymerBehavior PxVisBehaviorD3.canvas
*/
PxVisBehaviorD3.canvas = [{
properties: {
/**
* Boolean to specify if drawings should render to svg instead of canvas
*
*/
renderToSvg: {
type: Boolean,
value: false
}
},
observers: [
'_renderToSvgChanged(renderToSvg)'
],
_renderToSvgChanged: function(renderToSvg) {
if(this.hasUndefinedArguments(arguments)) {
return;
}
if(this.renderToSvg && this.canvasContext && this.canvasContext.pxClearCanvas) {
//make sure the canvas cleans itself
this.canvasContext.pxClearCanvas();
}
//flush so that the dom if are processed and make the switch
//between svg and canvas components
if(this._isAttached) {
Polymer.dom.flush();
}
}
}, PxVisBehavior.observerCheck, PxVisBehaviorD3.canvasContext, PxVisBehavior.isAttached]
/*
Name:
PxVisBehaviorD3.renderToCanvas
Description:
Polymer behavior that provides the renderToCanvas property
Dependencies:
- D3.js
@polymerBehavior PxVisBehaviorD3.renderToCanvas
*/
PxVisBehaviorD3.renderToCanvas = [{
properties: {
/**
* Boolean to specify if drawings should render to canvas instead of svg
*/
renderToCanvas: {
type: Boolean,
value: false,
observer: '_renderToCanvasChanged'
}
},
_renderToCanvasChanged: function(renderToCanvas) {
if(this.hasUndefinedArguments(arguments)) {
return;
}
if(!this.renderToCanvas && this.canvasContext && this.canvasContext.pxClearCanvas) {
//make sure the canvas cleans itself
this.canvasContext.pxClearCanvas();
}
//flush so that the dom if are processed and make the switch
//between svg and canvas components
if(this._isAttached) {
Polymer.dom.flush();
}
}
}, PxVisBehavior.observerCheck, PxVisBehavior.isAttached];
/*
Name:
PxVisBehaviorD3.axes
Description:
Polymer behavior that provides the x,y and isMultiY properties for d3 components.
Dependencies:
- D3.js
@polymerBehavior PxVisBehaviorD3.axes
*/
PxVisBehaviorD3.axes = [{
properties: {
/**
* x is a holder for the d3 instantiated scale object
* Must be set in the svg component and passed to all components so they know the drawing scale.
* This can be set declaratively
*
* See: https://github.com/d3/d3/blob/master/API.md#scales-d3-scale
*
* @property x
* @type Function
*/
x: {
type: Function,
notify:true
},
/**
* y is a holder for the d3 instantiated scale object
* Must be set in the svg component and passed to all components so they know the drawing scale.
* This can be set declaratively
*
* See: https://github.com/d3/d3/blob/master/API.md#scales-d3-scale
*
* @property y
* @type {Object|Function}
*/
y: {
type: Object,
notify:true
},
isMultiY: {
type: Boolean,
readOnly: true,
computed: '_getIsMultiY(y.*)'
}
},
_getIsMultiY: function() {
if(this.hasUndefinedArguments(arguments)) {
return;
}
return typeof this.y === 'object';
},
/**
* This functions process Y axis and applies the result to some variable.
* If in single Y it just run the function and assign the result to `result`, if multi Y
* it runs the function for each axis and stores the result against the axis key
* on `result`
*/
_processYValues: function(callback) {
callback = callback.bind(this);
if(this.isMultiY) {
var result = {},
keys = Object.keys(this.y);
for(var i=0; i<keys.length; i++) {
result[keys[i]] = callback(this.y[keys[i]], keys[i]);
}
return result;
} else {
result = callback(this.y);
}
return result;
}
}, PxVisBehavior.observerCheck];
/*
Name:
PxVisBehaviorD3.domainUpdate
Description:
Polymer behavior that provides domain update property
Dependencies:
- D3.js
@polymerBehavior PxVisBehaviorD3.domainUpdate
*/
PxVisBehaviorD3.domainUpdate = {
properties: {
/**
* Number which increments up when the domain(s) has(have) changed.
*
* 0 (false) indicates that domains have not been set.
*
* Serves as a trigger for many elements to redraw.
*
* @property domainChanged
* @type Number
*/
domainChanged: {
type: Number,
notify: true,
value: 0
}
}
};
/*
Name:
PxVisBehaviorD3.axisOrientation
Description:
Polymer behavior that provides the orientation property for d3 components.
Dependencies:
- D3.js
@polymerBehavior PxVisBehaviorD3.axisOrientation
*/
PxVisBehaviorD3.axisOrientation = {
properties: {
/**
* Defines which side the axis should be on.
* - 'left'
* - 'right'
* - 'bottom'
* - 'top'
*
* @property orientation
* @type String
* @default bottom
*/
orientation: {
type: String,
value: 'left'
}
}
};
/*
Name:
PxVisBehaviorD3.axis
Description:
Polymer behavior that provides the axis and orientation properties for d3 components.
Dependencies:
- D3.js
@polymerBehavior PxVisBehaviorD3.axis
*/
PxVisBehaviorD3.axis = [{
properties: {
/**
* axis is a general holder for the d3 instantiated scale object
* Can pass any type of instantiated scale object, IE pass in either your x or your y depending which this axis is for.
* This can be set declaratively
*
* See: https://github.com/d3/d3/blob/master/API.md#scales-d3-axis
*
* @property axis
* @type Object
*/
axis: {
type: Object
},
/**
* Defines which side the axis should be on.
* - 'left'
* - 'right'
* - 'bottom'
* - 'top'
*
* @property orientation
* @type String
* @default bottom
*/
orientation: {
type: String,
value: 'bottom',
}
}
}, PxVisBehaviorD3.axisOrientation];
/*
Name:
PxVisBehaviorD3.selectedDomain
Description:
Polymer behavior that provides the an object to hold user selected domains for d3 components.
Dependencies:
- D3.js
@polymerBehavior PxVisBehaviorD3.selectedDomain
*/
PxVisBehaviorD3.selectedDomain = {
properties: {
/**
* New chart extents selected by the user
*
* Serves as a trigger for the scale component to redefine the chart extents
*
* @property selectedDomain
* @type Object
*/
selectedDomain: {
type:Object,
value: function() {
return {x:[], y:[]};
},
notify:true
}
}
};
/*
Name:
PxVisBehaviorD3.selectedTimeDomain
Description:
Polymer behavior that provides the ability to use px-datetime (px-rangepicker) to drive the selection
of a time domain in a px-vis time based chart
Dependencies:
- D3.js
@polymerBehavior PxVisBehaviorD3.selectedTimeDomain
*/
PxVisBehaviorD3.selectedTimeDomain = [{
properties: {
/**
* Range object defining the time span
* * Format ISO8601 strings
* ```
* {
* "from": "2013-01-07T22:44:30.652Z",
* "to" : "2013-02-04T22:44:30.652Z"
* }
* ```
*
* Updates and is updated by SelectedDomain
*
*/
range: {
type: Object,
notify: true
},
_preventDomainUpdate: {
type: Boolean,
value: false
},
_preventRangeUpdate: {
type: Boolean,
value: false
}
},
observers: [
'_rangeChanged(range)'
],
attached: function() {
this._isAttached = true;
},
_rangeChanged: function(range) {
if(this.hasUndefinedArguments(arguments)) {
return;
}
if(this._isAttached && !this._preventRangeUpdate) {
//update selectedDomain with those new values
//make sure we don't trigger a domain update when changing it from here
this._preventDomainUpdate = true;
var newDomain = {},
dataExtents = {};
// newDomain.y = this.selectedDomain.y;
newDomain.x = [];
newDomain.x[0] = Number(Px.moment(this.range.from, Px.moment.ISO_8601).format('x'));
newDomain.x[1] = Number(Px.moment(this.range.to, Px.moment.ISO_8601).format('x'));
if(this.dataExtents && this.dataExtents.y.length > 0) {
dataExtents["y"] = this.dataExtents.y;
} else {
dataExtents.y = [Infinity, -Infinity];
}
dataExtents.x = newDomain.x;
// this.set('selectedDomain', newDomain);
this.set('dataExtents', dataExtents);
this._preventDomainUpdate = false;
}
},
// _selectedDomainChanged: function(selectedDomain) {
// if(this._isAttached && !this._preventDomainUpdate) {
// //update selectedDomain with those new values
// //make sure we don't trigger a domain update when changing it from here
// this._preventRangeUpdate = true;
//
// var newRange = {};
// newRange.from = Px.moment(this.selectedDomain.x[0]).toISOString();
// newRange.to = Px.moment(this.selectedDomain.x[1]).toISOString();
//
// this.set('range', newRange);
//
// this._preventRangeUpdate = false;
// }
// }
}, PxVisBehavior.observerCheck, PxVisBehaviorD3.selectedDomain];
/*
Name:
PxVisBehaviorD3.clipPathBoolean
Description:
Polymer behavior that provides a clipPath boolean to determine
if clip path should be used or not.
!!Do not confuse with PxVisBehaviorD3.clipPath!!
rule fo thumbis this behavior is for canvas element and
PxVisBehaviorD3.clipPath for svg elements
Dependencies:
- D3.js
@polymerBehavior PxVisBehaviorD3.clipPathBoolean
*/
PxVisBehaviorD3.clipPathBoolean = {
properties: {
/**
* Whether to use the clipPath to avoid drawing outside of the axes.
*/
clipPath: {
type: Boolean,
value: false
},
}
};
/*
Name:
PxVisBehaviorD3.clipPath
Description:
Polymer behavior that provides the clipPath object for d3 components.
Dependencies:
- D3.js
@polymerBehavior PxVisBehaviorD3.clipPath
*/
PxVisBehaviorD3.clipPath = {
properties: {
/**
* Holder for a clipping path ID
*
*/
clipPath: {
type:String,
notify:true
},
/**
* A more restricting clip path used to limit where the series are being drawn
*
*/
seriesClipPath: {
type:String,
notify: true
}
},
/**
* Add the clip-path attr to the element
*
* @method addClipPath
*/
addClipPath: function(elem) {
if(typeof(this.clipPath) !== 'undefined' && this._doesD3HaveValues(elem)){
elem.attr("clip-path", 'url(#' + this.clipPath + ')');
}
}
};
/*
Name:
PxVisBehaviorD3.dynamicRedraw
Description:
Polymer behavior that provides the dynamicRedraw objects for d3 components.
Dependencies:
- D3.js
@polymerBehavior PxVisBehaviorD3.dynamicRedraw
*/
PxVisBehaviorD3.dynamicRedraw = {
properties: {
/**
* Boolean to specify if we should redraw the chart series when we move an axis. More of a chart type by chart type configuration rather than a developer configuration. IE, for charts such as multi-y timeseries, it is unnessary. For charts such as parallel coordinates, it is necessary.
*/
redrawSeries: {
type: Boolean,
value: false
},
/**
* The accompanying array of series elements required to redraw.
*/
redrawElems: {
type: Array,
value: function() { return [] }
},
/**
* Boolean specifing if the lines should redraw as you move the axis or just at the end.
*/
dynamicRedraw: {
type: Boolean,
value: false
}
}
};
/*
Name:
PxVisBehaviorD3.labelTypeSize
Description:
Polymer behavior that provides the labelTypeSize objects for d3 components.
Dependencies:
- D3.js
@polymerBehavior PxVisBehaviorD3.labelTypeSize
*/
PxVisBehaviorD3.labelTypeSize = {
properties: {
/**
* Defines the base label type size
*
* @property labelTypeSize
* @type Number
* @default 12
*/
labelTypeSize: {
type: Number,
value: 12,
}
}
};
/*
Name:
PxVisBehaviorD3.axisConfig
Description:
Polymer behavior that provides the axisConfig objects for d3 components.
Dependencies:
- D3.js
@polymerBehavior PxVisBehaviorD3.axisConfig
*/
PxVisBehaviorD3.axisConfig = [{
properties: {
/**
* The displayed title for the axis
*
* @property title
* @type String
* @default ''
*/
title: {
type:String,
value: ''
},
/**
* Defines on which side the tick mark the label should sit.
* - 'center'
* - 'before'
* - 'after'
*
* @property labelPosition
* @type String
* @default center
*/
labelPosition: {
type: String,
value: 'center'
},
/**
* Defines how the label should be rotated. Number is the degree of rotation
*
* @property labelRotation
* @type Number
* @default 0
*/
labelRotation: {
type: Number,
value: 0,
},
/**
* Defines how the label should be moved in x,y. Array is an x,y pair and coresponds to the number of pixels to move the label
*
* @property labelTranslation
* @type Array
* @default [0,0]
*/
labelTranslation: {
type: Array,
value: function() {return [0,0];},
},
/**
* Array of the series which belong to this axis
*
* @property series
* @type Array
*/
series: {
type: Array,
value: function() {return[];}
},
/**
* An x,y amount to move the axis to allow for labels and titles
*
* @property translateAmt
* @type Array
*/
translateAmt: {
type: Array,
value:function(){ return [0,0]; }
},
/**
* Optional object to specify placement of the title. If none is supplied, then it uses `orientation` to determine title location.
*
*```
* {
* x: Number, // a x number of pixels
* y: Number, // a y number of pixels
* r: Number, // a number of degrees to rotate
* anchor: String, // middle, start, end
* }
*```
*/
titleLocation: {
type: Object,
value: function(){ return {} }
},
/**
* Defines the Title type size
*
*/
titleTypeSize: {
type: Number,
value: 15,
},
/**
* Defines the axis stroke width
*
*/
strokeWidth: {
type: Number,
value: 1
},
/**
* Defines the axis tickSizeOuter. Default is to hide them
*
* See: https://github.com/d3/d3-axis#axis_tickSizeOuter
*/
tickSizeOuter: {