forked from predixdesignsystem/px-vis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpx-vis-clip-path.html
132 lines (109 loc) · 3.98 KB
/
px-vis-clip-path.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
<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" />
<!--
"The clipping path restricts the region to which paint can be applied. Conceptually, any parts of the drawing that lie outside of the region bounded by the currently active clipping path are not drawn." (MDN)
Ostensibly, the clipping path gets applied to drawing components to prevent them from drawing on certain parts of the chart, such stopping a line series drawing where the axis is drawn.
To use, specfify the sizing, svg, and interpreters as specified in the example. It will return an ID for the clipping path which can be passed to other drawing objects. This component returns TWO different clip path IDs. clipPath includes the margin on top and seriesClipPath excludes it.
##### Usage
<px-vis-clip-path
clip-path="{{clipPath}}"
series-clip-path="{{serieClipPath}}"
svg="[[svg]]"
x="[[x]]"
y="[[y]]"
width="[[width]]"
height="[[height]]"
margin="[[margin]]">
</px-vis-clip-path>
## MDN Spec
https://developer.mozilla.org/en-US/docs/Web/SVG/Element/clipPath
@element px-vis-clip-path
@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">
<template>
</template>
</dom-module>
<script>
Polymer({
is: 'px-vis-clip-path',
behaviors: [
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 bigger clip path intended for other chart objects such as events
*/
_clipPathSvg: {
type: Object
},
/**
* holder for smaller clip path intended for the chart series
*/
_seriesClipPathSvg: {
type: Object
},
/**
* top offset to be applied to the series clip path
*/
seriesClipPathYOffset: {
type: Number,
value: 0
}
},
observers: [
'_drawElement(x,y,svg,width,height, margin.*)'
],
/**
* Creates and sets two clipping paths.
*
* @method _drawElement
*/
_drawElement: function() {
//if the clip path has not been set, create it
if(!this._clipPathSvg) {
this.set('clipPath', this.generateRandomID('cp_'));
this.fire('px-vis-clip-path-updated', { 'dataVar': 'clipPath', 'data': this.clipPath, 'method':'set' });
this.svg
.append('clipPath')
.attr('id',this.clipPath)
.append('rect');
this._clipPathSvg = this.svg.select('clipPath#'+this.clipPath+' rect');
}
//update the clip path
this._clipPathSvg
.attr('y',-this.margin.top)
.attr('width', Math.max(this.width - this.margin.left, 0))
.attr('height', Math.max(this.height - this.margin.bottom, 0));
//if the second clip path has not been set, create it
if(!this._seriesClipPathSvg) {
this.set('seriesClipPath', this.generateRandomID('cps_'));
this.fire('px-vis-series-clip-path-updated', { 'dataVar': 'seriesClipPath', 'data': this.seriesClipPath, 'method':'set' });
this.svg
.append('clipPath')
.attr('id',this.seriesClipPath)
.append('rect');
this._seriesClipPathSvg = this.svg.select('clipPath#'+this.seriesClipPath + ' rect');
}
//update the second clip path
this._seriesClipPathSvg
.attr('y', this.seriesClipPathYOffset)
.attr('width', Math.max(this.width - this.margin.left - this.margin.right,0))
.attr('height', Math.max(this.height - this.margin.bottom -
this.margin.top - this.seriesClipPathYOffset,0));
}
});
</script>