-
Notifications
You must be signed in to change notification settings - Fork 13
/
nvd3-line-with-focus.html
181 lines (165 loc) · 3.71 KB
/
nvd3-line-with-focus.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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="nvd3-behavior.html">
<!--
An element to create line with focus chart using nvd3.
Example:
<nvd3-line-with-focus
data="[[data]]"
height="100"
width="400"
brush-extent='[50,70]'
auto-resize
show-legend
use-interactive-guideline>
</nvd3-line-with-focus>
Data Format:
```
[
{
"key": "Sine Wave",
"color": "#ff7f0e",
"values": [{
"x": 0,
"y": 0
}, {
"x": 1,
"y": 0.09983341664682815
}, {
"x": 2,
"y": 0.19866933079506122
}, {
"x": 3,
"y": 0.29552020666133955
}, {
"x": 4,
"y": 0.3894183423086505
}, {
"x": 5,
"y": 0.479425538604203
}]
}, {
"key": "Cosine Wave",
"color": "#2ca02c",
"values": [{
"x": 0,
"y": 0.5
}, {
"x": 1,
"y": 0.49750208263901285
}, {
"x": 2,
"y": 0.4900332889206208
}, {
"x": 3,
"y": 0.477668244562803
}, {
"x": 4,
"y": 0.46053049700144255
}, {
"x": 5,
"y": 0.4387912809451864
}]
}
]
```
@group NVD3 Elements
@element nvd3-line-with-focus
@demo demo/nvd3-line-with-focus.html
@hero hero.svg
-->
<dom-module id="nvd3-line-with-focus">
<template>
<style include="nvd3-shared-styles"></style>
<!-- We need to put svg tag inside a div to set correct margins -->
<div>
<svg id="svg"></svg>
</div>
</template>
<script>
Polymer({
is: 'nvd3-line-with-focus',
behaviors: [NVD3.ChartBehavior],
properties: {
/**
* NVD3 chart object.
*/
_chart: {
type: Object,
value: function() {
return nv.models.lineWithFocusChart();
}
},
/**
* Extent to the specified values.
*/
brushExtent: {
type: Array,
observer: '_brushExtentChanged'
},
/**
* Whether to display the legend or not
*/
showLegend: {
type: Boolean,
value: false
},
/**
* Sets the chart to use a guideline and floating tooltip instead of
* requiring the user to hover over specific hotspots.
*/
useInteractiveGuideline: {
type: Boolean,
value: false
},
/**
* Custom Labels for x axis.
* e.g. {
* "0": "Label 0",
* "1": "Label 1",
* "2": "Label 2",
* "3": "Label 3",
* "4": "Label 4"
* }
*/
xAxisLabels: {
type: Object,
value: {},
observer: '_xAxisLabelsChanged'
},
/**
* NVD3 components which are used in this chart.
* It's required for binding events.
*/
_components: {
type: Array,
value: ['lines', 'legend', 'focus', 'xAxis', 'x2Axis', 'yAxis', 'y2Axis', 'tooltip']
}
},
_brushExtentChanged: function() {
this._chart.brushExtent(this.brushExtent);
},
/**
* Check if custom labels is set and update tickFormat of x axis.
*
* @private
*/
_xAxisLabelsChanged: function() {
var xAxisLabels = this.xAxisLabels;
this._chart.xAxis.tickFormat(function(d) {
if (xAxisLabels.hasOwnProperty(d)) {
return xAxisLabels[d];
} else {
return d;
}
});
this._chart.x2Axis.tickFormat(function(d) {
if (xAxisLabels.hasOwnProperty(d)) {
return xAxisLabels[d];
} else {
return d;
}
});
}
});
</script>
</dom-module>