This repository was archived by the owner on Jul 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtooltip.tsx
More file actions
151 lines (141 loc) · 7.83 KB
/
tooltip.tsx
File metadata and controls
151 lines (141 loc) · 7.83 KB
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
import * as React from "react";
import * as ReactDOM from "react-dom";
import { LinearGaugeComponent, LinearGaugeTheme, Position, IAxisLabelRenderEventArgs, ILoadedEventArgs, ILoadEventArgs, IResizeEventArgs, ITooltipRenderEventArgs, GaugeTooltip, AnnotationsDirective, Annotations, Inject, AnnotationDirective, AxesDirective, AxisDirective, PointersDirective, PointerDirective, RangesDirective, RangeDirective } from '@syncfusion/ej2-react-lineargauge';
import { SampleBase } from '../common/sample-base';
const SAMPLE_CSS = `
.control-fluid {
padding: 0px !important;
}`;
/**
* Linear gauge tooltip sample
*/
export class Tooltip extends SampleBase<{}, {}> {
private gaugeInstance: LinearGaugeComponent;
public load(args: ILoadedEventArgs): void {
let selectedTheme: string = location.hash.split('/')[1];
selectedTheme = selectedTheme ? selectedTheme : 'Material';
args.gauge.theme = (selectedTheme.charAt(0).toUpperCase() + selectedTheme.slice(1)) as LinearGaugeTheme;
}
render() {
return (
<div className='control-pane'>
<style>
{SAMPLE_CSS}
</style>
<div className='control-section'>
<LinearGaugeComponent id='tooltipContainer' ref={gauge => this.gaugeInstance = gauge} orientation='Horizontal' axisLabelRender={this.labelRender.bind(this)} load={this.gaugeLoad.bind(this)} loaded={this.gaugeLoaded.bind(this)} resized={this.gaugeResized.bind(this)} tooltipRender={this.tooltipRender.bind(this)} container={{ width: 140, border: { width: 2, color: '#a6a6a6' } }} tooltip={{ enable: true, fill: '#fffff', textStyle: { color: '#fffff' } }} >
<Inject services={[Annotations, GaugeTooltip]} />
<AxesDirective>
<AxisDirective minimum={0} maximum={10} majorTicks={{ interval: 1 }} minorTicks={{ interval: 0.2 }} line={{ offset: 140 }} labelStyle={{ font: { color: '#000000' } }}>
<PointersDirective>
<PointerDirective type='Bar' value={5.4} color='#ff66b3' offset={15}>
</PointerDirective>
</PointersDirective>
</AxisDirective>
<AxisDirective opposedPosition={true} minimum={0} maximum={25} majorTicks={{ interval: 1 }} minorTicks={{ interval: 0.2 }} line={{ offset: -140 }} labelStyle={{ font: { color: '#000000' } }}>
<PointersDirective>
<PointerDirective type='Bar' value={16.5} color='#4d94ff' offset={-15}>
</PointerDirective>
</PointersDirective>
</AxisDirective>
</AxesDirective>
<AnnotationsDirective>
<AnnotationDirective content='<div id="first"><h1 style="font-size:15px">Inches</h1></div>'
axisIndex={0}
axisValue={5.4}
x={35}
y={-58}
zIndex='1'>
</AnnotationDirective>
<AnnotationDirective content='<div id="second"><h1 style="font-size:15px">Centimeters</h1></div>'
axisIndex={1}
axisValue={16.5}
x={50}
y={52}
zIndex='1'>
</AnnotationDirective>
</AnnotationsDirective>
</LinearGaugeComponent>
</div>
<div id="action-description">
<p>
This sample visualizes the tooltip for pointer in gauge. To see tooltip in action, hover pointer or tap the pointer.
</p>
</div>
<div id="description">
<p>
This sample demonstrates the default linear gauge. The linear gauge control indicates the values of scales in horizontal
or vertical sliding meter. You can use <code>axes</code>,
<code>ranges</code>, <code>pointers</code> and <code>container</code> properties to customize the appearance of the
gauge. In this sample, an axis with multiple ranges and a pointer has been used.
</p>
<p>
More information about linear gauge can be found in this
<a target="_blank" href="http://ej2.syncfusion.com/documentation">documentation section</a>.
</p>
</div>
</div>
)
}
public tooltipRender(args: ITooltipRenderEventArgs): void {
args.content = (args.axis.visibleRange.max === 25) ? Number(args.content).toFixed(1) + ' cm' : Number(args.content).toFixed(1) + ' in';
}
public gaugeLoad(args: ILoadEventArgs): void {
let selectedTheme: string = location.hash.split('/')[1];
selectedTheme = selectedTheme ? selectedTheme : 'Material';
args.gauge.theme = (selectedTheme.charAt(0).toUpperCase() + selectedTheme.slice(1)) as LinearGaugeTheme;
let width: number = Number(document.getElementById('tooltipContainer').offsetWidth);
if (width < 500) {
args.gauge.axes[1].majorTicks.interval = 2;
args.gauge.axes[1].minorTicks.interval = 1;
args.gauge.orientation = 'Vertical';
args.gauge.annotations[0].x = -57;
args.gauge.annotations[0].y = -30;
args.gauge.annotations[1].x = 50;
args.gauge.annotations[1].y = -45;
} else {
args.gauge.axes[1].majorTicks.interval = 1;
args.gauge.axes[1].minorTicks.interval = 0.5;
args.gauge.orientation = 'Horizontal';
args.gauge.annotations[0].x = 35;
args.gauge.annotations[0].y = -58;
args.gauge.annotations[1].x = 50;
args.gauge.annotations[1].y = 52;
}
}
public gaugeLoaded(args: ILoadedEventArgs): void {
if (document.getElementById('tooltipContainer')) {
if (args.gauge.availableSize.width < 500) {
document.getElementById('tooltipContainer_Annotation_0').style.transform = 'rotate(270deg)';
document.getElementById('tooltipContainer_Annotation_1').style.transform = 'rotate(270deg)';
} else {
document.getElementById('tooltipContainer_Annotation_0').style.transform = '';
document.getElementById('tooltipContainer_Annotation_1').style.transform = '';
}
}
}
public labelRender(args: IAxisLabelRenderEventArgs): void {
if (args.axis.visibleRange.min === args.value || args.axis.visibleRange.max === args.value) {
args.text = '';
}
}
public gaugeResized(args: IResizeEventArgs): void {
if (args.currentSize.width < 500) {
this.gaugeInstance.axes[1].majorTicks.interval = 2;
this.gaugeInstance.axes[1].minorTicks.interval = 1;
this.gaugeInstance.orientation = 'Vertical';
this.gaugeInstance.annotations[0].x = -57;
this.gaugeInstance.annotations[0].y = -30;
this.gaugeInstance.annotations[1].x = 50;
this.gaugeInstance.annotations[1].y = -45;
} else {
this.gaugeInstance.axes[1].majorTicks.interval = 1;
this.gaugeInstance.axes[1].minorTicks.interval = 0.5;
this.gaugeInstance.orientation = 'Horizontal';
this.gaugeInstance.annotations[0].x = 35;
this.gaugeInstance.annotations[0].y = -58;
this.gaugeInstance.annotations[1].x = 50;
this.gaugeInstance.annotations[1].y = 52;
}
}
}