-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathpx-vis-clip-path-complex-area.html
146 lines (123 loc) · 3.76 KB
/
px-vis-clip-path-complex-area.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
<!--
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" />
<!--
### Usage
<px-vis-clip-complex-area
svg="[[svg]]"
x="[[x]]"
y="[[y]]"
domain-changed="[[domainChanged]]"
chart-data="[[chartData]]"
dimensions="[[dimensions]]"
clip-path="{{clipPath}}">
</px-vis-clip-complex-area>
## MDN Spec
https://developer.mozilla.org/en-US/docs/Web/SVG/Element/clipPath
@element px-vis-clip-path-complex-area
@blurb The clipping path restricts the region to which paint can be applied.
@homepage index.html
@demo demo.html
-->
<dom-module id="px-vis-clip-path-complex-area">
<template>
</template>
</dom-module>
<script>
Polymer({
is: 'px-vis-clip-path-complex-area',
behaviors: [
PxVisBehavior.observerCheck,
PxVisBehaviorD3.svg,
PxVisBehavior.sizing,
PxVisBehaviorD3.axes,
PxVisBehavior.commonMethods,
PxVisBehaviorD3.clipPath
],
/**
* Properties block, expose attribute values to the DOM via 'reflect'
*
* @property properties
* @type Object
*/
properties: {
/**
* Holder for the clip path object
*
*/
_clipPathObj: {
type: Object
},
/**
* Holder for the clip path svg
*
*/
_clipPathSvg: {
type: Object
}
},
observers: [
'_drawElement(domainChanged, svg, dimensions, chartData)'
],
detached: function() {
// this._clipPathObj.remove();
},
/**
* Creates and sets a clipping path
*
* @method _drawElement
*/
_drawElement: function() {
if(this.hasUndefinedArguments(arguments)) {
return;
}
if(this.domainChanged) {
if(!this._clipPathObj) {
this.set('clipPath', this.generateRandomID('cp_'));
this.fire('px-vis-clip-path-updated', { 'dataVar': 'clipPath', 'data': this.clipPath, 'method':'set' });
this._clipPathObj = this.svg
.append("clipPath")
.attr("id",this.clipPath);
}
var _this = this,
area = Px.d3.radialArea()
.angle(function(d) {
return _this.x(d);
})
.innerRadius(function(d) {
// ~~ --> round pixels values to optimize svg perfs
return ~~_this.y.range()[0];
})
.outerRadius(function(d) {
// ~~ --> round pixels values to optimize svg perfs
return ~~_this.y.range()[1] + 1; //+1px to not clip the very edge
})
.defined( function(d) {
return _this.x(d) || _this.x(d) === 0;
})
.curve(Px.d3.curveLinearClosed);
this._clipPathSvg = this._clipPathObj.selectAll("path")
.data([this.dimensions])
.enter()
.append("path");
//cant do merge because our data is not changing. So always run
this._clipPathObj.selectAll("path")
.attr('d', function(d) {
return area(d);
});
}
}
});
</script>