-
Notifications
You must be signed in to change notification settings - Fork 46
/
px-vis-svg.html
170 lines (148 loc) · 5.01 KB
/
px-vis-svg.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
<!--
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="../polymer/polymer.html"/>
<link rel="import" href="px-vis-behavior-common.html" />
<link rel="import" href="px-vis-behavior-d3.html" />
<link rel="import" href="css/px-vis-styles.html">
<!--
### Usage
<px-vis-svg
width="[[width]]"
height="[[height]]"
margin="[[margin]]"
svg="{{svg}}">
</px-vis-svg>
<px-vis-scale
x-axis-type="time"
y-axis-type="linear"
complete-series-config="[[seriesConfig]]"
data-extents="[[dataExtents]]"
width="[[width]]"
height="[[height]]"
margin="[[margin]]"
chart-data={{chartData}}
x="{{x}}"
y="{{y}}"
selected-domain="[[selectedDomain]]">
</px-vis-scale>
@element px-vis-svg
@blurb Element which creates an SVG element and sets up d3
@homepage index.html
@demo demo.html
-->
<dom-module id="px-vis-svg">
<template>
<style include="px-vis-styles"></style>
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
class="px-vis-svg"
id="chartSVG"
overflow="hidden">
</svg>
</template>
</dom-module>
<script>
Polymer({
is: 'px-vis-svg',
/****** EVENTS ******/
/**
* Fired once the d3 svg drawing element has been configured.
*
* Uses the px-vis-behavior-chart behavior, for listening and setting properties locally or globally.
* Detail includes:
*
* ```
* { 'data': d3.select('g') }
* ```
*
* @event px-vis-svg-updated
*/
/**
* Fired once the svg is configured. Passes the svg element inside px-vis-svg.
*
* Uses the px-vis-behavior-chart behavior, for listening and setting property, locally or globally.
* ```
* {'data': this.$.chartSVG}
* ```
* @event px-vis-svg-element-updated
*/
behaviors: [
PxVisBehavior.observerCheck,
PxVisBehavior.sizing,
PxVisBehavior.commonMethods,
PxVisBehaviorD3.svg
],
/**
* Properties block, expose attribute values to the DOM via 'reflect'
*
* @property properties
* @type Object
*/
properties: {
//redefine svg prop so it can notify
/**
* Holder for the d3 instantiated svg container.
* Must be set in ready and passed to all components so they know where to draw.
*
* FUTURE: when Polymer supports SVG, this only needs to be set on the SVG element.
*
* @property svg
* @type Object
*/
svg: {
type: Object,
notify: true
}
},
observers: [
'_setSVG(width,height,margin,offset.*)'
],
/**
* When attached, re-fire set properties for precipitation pattern,
* as well as the svg element that's inside px-svg.
*
* @method attached
*/
attached: function(){
if(this._doesObjHaveValues(this.svg)){
this.fire('px-vis-svg-updated',{ 'data': this.svg, 'dataVar': 'svg', 'method': 'set' });
this.fire('px-vis-svg-element-updated', {'data': this.$.chartSVG, 'dataVar': 'pxSvgElem', 'method': 'set'});
}
},
/**
* Configures the SVG and d3 drawing element.
*
* @method _setSVG
*/
_setSVG: function(){
if(this.hasUndefinedArguments(arguments)) {
return;
}
if(this.width && this.height && this._doesObjHaveValues(this.margin)){
var svg = Px.d3.select(this.$$("svg"))
.attr('width',this.width)
.attr('height',this.height),
newSvg;
newSvg = (this._isVarUndefined(this.svg)) ? svg.append('g') : this.svg;
newSvg.attr('width',this.width)
.attr('height',this.height)
.attr('transform', 'translate(' + (Number(this.margin.left) + Number(this.offset[0])) + ',' + (Number(this.margin.top) + Number(this.offset[1])) + ')');
this.set('svg',newSvg);
this.fire('px-vis-svg-updated',{ 'data': this.svg, 'dataVar': 'svg', 'method': 'set' });
this.set('pxSvgElem', this.$.chartSVG);
this.fire('px-vis-svg-element-updated', {'data': this.$.chartSVG, 'dataVar': 'pxSvgElem', 'method': 'set'});
}
},
});
</script>