forked from predixdesignsystem/px-vis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpx-vis-tooltip.html
179 lines (158 loc) · 4.8 KB
/
px-vis-tooltip.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
<link rel="import" href="../polymer/polymer.html"/>
<link rel="import" href="../px-tooltip/px-tooltip.html" />
<link rel="import" href="px-vis-behavior-common.html" />
<link rel="import" href="px-vis-behavior-register.html" />
<link rel="import" href="px-vis-behavior-d3.html" />
<link rel="import" href="px-vis-behavior-datetime.html"/>
<link rel="import" href="px-vis-register.html" />
<!--
Element providing on-chart tooltip display
- Consumes tooltipData property
##### Usage
<px-vis-tooltip
hover-target=[[mouseRect]]
mouse-position="[[mousePosition]]"
width="250"
margin="[[margin]]"
chart-data="[[chartData]]"
tooltip-data="[[tooltipData]]"
complete-series-config="[[completeSeriesConfig]]"
x-axis-type="time"
tooltip-style="light"
muted-series="[[mutedSeries]]">
</px-vis-tooltip>
@element px-vis-tooltip
@blurb Element providing on-chart hover functionality to get data values near the mouse cursor.
@homepage index.html
@demo demo.html
-->
<link rel="import" href="css/px-vis-tooltip-styles.html">
<dom-module id="px-vis-tooltip">
<template>
<style include="px-vis-tooltip-styles"></style>
<template is="dom-if" if="[[_tooltipDataHidden(tooltipData)]]">
<px-tooltip
id="tooltip"
tooltip-style="[[tooltipStyle]]"
for="[[hoverTarget]]"
delay="50"
orientation="[[orientation]]"
follow-mouse
mouse-coords="[[mousePosition]]">
<px-vis-register
id="register"
tooltip-style="[[tooltipStyle]]"
truncation-length="100"
groupings="[[_groupings]]"
force-date-time-display="[[forceDateTimeDisplay]]"
tooltip-data=[[tooltipData]]
chart-data="[[chartData]]"
x-axis-type="[[xAxisType]]"
y-axis-type="[[yAxisType]]"
complete-series-config="[[completeSeriesConfig]]"
muted-series="[[mutedSeries]]"
number-format="[[numberFormat]]"
number-format-culture="[[numberFormatCulture]]"
number-format-is-currency$="[[numberFormatIsCurrency]]"
number-format-currency="[[numberFormatCurrency]]"
number-format-zero="[[numberFormatZero]]"
first-date-time-format="[[firstDateTimeFormat]]"
second-date-time-format="[[secondDateTimeFormat]]"
separator="[[separator]]"
timezone="[[timezone]]"
prevent-min-size>
</px-vis-register>
</px-tooltip>
</template>
</template>
</dom-module>
<script>
Polymer({
is: 'px-vis-tooltip',
behaviors: [
PxVisBehavior.dataset,
PxVisBehavior.tooltipData,
PxVisBehavior.axisTypes,
PxVisBehavior.completeSeriesConfig,
PxVisBehavior.mutedSeries,
PxVisBehavior.formatting,
PxVisBehaviorTime.datetime,
PxVisBehavior.forceDateTimeDisplay,
PxVisBehaviorRegister.groupings
],
/**
* Properties block, expose attribute values to the DOM via 'reflect'
*
* @property properties
* @type Object
*/
properties: {
/**
* The dom element over which the tooltip should be shown. Generally some <g> or <rect> element on the svg
*
*/
hoverTarget: {
type: Object
},
/**
* x,y screen position where you want the tooltip to be displayed. Can be the mouse position; can also be any arbitraty screen position.
*
*/
mousePosition:{
type: Array
},
/**
* Tooltip style supports two values:
* - `light` : gives tooltip a white background
* - `dark` : gives tooltip a balck backgound. Default
*
*/
tooltipStyle: {
type: String,
value: "dark"
},
/**
* The actual px-tooltip elem in case we need access to it higher up the dom.
*
*/
tooltipElem: {
type: Object
},
/**
* Orientation for the tooltip
*
*/
orientation: {
type: String,
value: "auto"
},
_groupings: {
type: Number,
value: 1,
computed: '_checkGroups(tooltipData.*, groupings)'
}
}, //properties
ready: function() {
this.set('tooltipElem', this.$.tooltip);
},
detached: function() {
this.tooltipElem.remove();
},
_checkGroups: function() {
// if the dev specified a number of groups
if(this.groupings && this.groupings > 1) {
return this.groupings
}
if(this.tooltipData.series.length < 16) {
return 1;
} else if(this.tooltipData.series.length < 24) {
return 2;
} else {
return 3;
}
},
_tooltipDataHidden: function(tooltipData) {
return tooltipData.hidden !== true;
}
});
</script>