forked from predixdesignsystem/px-vis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpx-vis-radar-grid.html
177 lines (160 loc) · 4.06 KB
/
px-vis-radar-grid.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
<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="../px-colors-design/colors.html" />
<link rel="import" href="px-vis-line-svg.html"/>
<!--
Element which draws lines series onto the chart
##### Usage
<px-vis-radar-grid
svg="[[svg]]"
tick-values="[[gridTicks]]"
dimensions="[[dimensions]]"
domain-changed="[[domainChanged]]">
</px-vis-radar-grid>
@element px-vis-radar-grid
@blurb Element which draws lines series onto the chart
@homepage index.html
@demo demo.html
-->
<link rel="import" href="css/px-vis-styles.html">
<dom-module id="px-vis-radar-grid">
<template>
<style include="px-vis-styles"></style>
<px-vis-line-svg
id="line"
radial-line
multi-path
svg="[[svg]]"
series-id="[[_seriesKey]]"
chart-data="[[_gridData]]"
complete-series-config="[[_completeSeriesConfig]]"
x="[[x]]"
y="[[y]]"
domain-changed="[[domainChanged]]"
stroke-width="[[strokeWidth]]"
interpolation-function="[[_returnInterpolation()]]">
</px-vis-line-svg>
</template>
</dom-module>
<script>
Polymer({
is: 'px-vis-radar-grid',
behaviors: [
PxVisBehaviorD3.svg,
PxVisBehaviorD3.axes,
PxVisBehavior.commonMethods,
PxColorsBehavior.baseColors
],
/**
* Properties block, expose attribute values to the DOM via 'reflect'
*
* @property properties
* @type Object
*/
properties: {
/**
* The calculated grid data
*
*/
_gridData: {
type: Array,
notify: true
},
/**
* The color for the grid lines
*
*/
axisColor: {
type: "String",
value: "grey7"
},
/**
* A configuration file for the gridlines
*
*/
_completeSeriesConfig: {
type: Object,
notify: true
},
/**
* The access key for the seriesConfig
*
*/
_seriesKey: {
type: String,
value: "radarGrids"
},
/**
* The values obtained from the axis where we want our gridlines
*
*/
tickValues: {
type: Array,
notify: true
},
/**
* The dimensions of or chart
*
*/
dimensions: {
type: Array,
notify: true
},
/**
* The stroke width for the grid
*
*/
strokeWidth: {
type: Number,
value: 1
}
},
observers: [
'createGridData(dimensions.*,tickValues.*)'
],
/**
* Draws the gridlines
*
*/
createGridData: function() {
this.debounce('radarGrids', function(){
if(this.tickValues && this.dimensions && this.tickValues.length > 0 && this.dimensions.length > 0) {
var data = [],
config = {},
domain = this.y.domain(),
c;
if(domain[0] !== this.tickValues[0]){
this.tickValues.push(domain[0]);
}
if(domain[1] !== this.tickValues[this.tickValues.length - 1]){
this.tickValues.push(domain[1]);
}
for(var i = 0; i < this.tickValues.length; i++) {
data.push({});
for(var j = 0; j < this.dimensions.length; j++) {
data[i][this.dimensions[j]] = this.tickValues[i];
}
}
//get the color
c = this._checkThemeVariable("--px-vis-gridlines-color", this.colors[this.axisColor]);
//make sure it is RGB
c = c[0] === '#' ? this._hexToRgb(c) : c;
config[this._seriesKey] = {
"color" : c,
'x' : this.dimensions
};
this.set('_completeSeriesConfig', config);
this.set('_gridData', data);
}
},10);
},
/**
* helper function to return a d3 interpolation function
*
*/
_returnInterpolation: function(){
return Px.d3.curveLinearClosed;
}
});
</script>