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 pathlabels.tsx
More file actions
250 lines (246 loc) · 13.4 KB
/
labels.tsx
File metadata and controls
250 lines (246 loc) · 13.4 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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/**
* Sample for labels
*/
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { PropertyPane } from '../common/property-pane';
import {
CircularGaugeComponent, ILoadedEventArgs, GaugeTheme, AxesDirective, AxisDirective, Inject, AnnotationsDirective, AnnotationDirective,
PointersDirective, PointerDirective, RangesDirective, RangeDirective, Annotations, TickModel
} from '@syncfusion/ej2-react-circulargauge';
import { SampleBase } from '../common/sample-base';
import { DropDownList } from '@syncfusion/ej2-dropdowns';
const SAMPLE_CSS = `
.control-fluid {
padding: 0px !important;
}`;
export class Labels extends SampleBase<{}, {}> {
private gauge: CircularGaugeComponent;
private tickOffset: HTMLInputElement;
private tickHeight: HTMLInputElement;
private labelOffset: HTMLInputElement;
private isMajorTicks: boolean = true;
private loaded: boolean = false;
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 GaugeTheme;
}
public ticksOffset(): void {
let value: number = +this.tickOffset.value;
if (this.isMajorTicks) {
this.gauge.axes[0].majorTicks.offset = value;
} else {
this.gauge.axes[0].minorTicks.offset = value;
}
document.getElementById('offset').innerHTML = 'Tick Offset <span> ' + value;
this.gauge.refresh();
}
public ticksHeight(): void {
let value: number = +this.tickHeight.value;
if (this.isMajorTicks) {
this.gauge.axes[0].majorTicks.height = value;
} else {
this.gauge.axes[0].minorTicks.height = value;
}
document.getElementById('height').innerHTML = 'Tick Height <span> ' + value;
this.gauge.refresh();
}
public labelsOffset(): void {
let value: number = +this.labelOffset.value;
this.gauge.axes[0].labelStyle.offset = value;
document.getElementById('labelOffsetValue').innerHTML = 'Label Offset <span> ' + value;
this.gauge.refresh();
}
public ticks: DropDownList; public tickPosition: DropDownList; public labelPosition: DropDownList;
render() {
return (
<div className='control-pane'>
<div className='control-section row'>
<div className='col-lg-8'>
<CircularGaugeComponent load={this.load.bind(this)} id='range-container' loaded={this.onChartLoad.bind(this)} ref={gauge => this.gauge = gauge}>
<Inject services={[Annotations]} />
<AxesDirective>
<AxisDirective startAngle={210} endAngle={150} radius='75%' minimum={0} maximum={180}
majorTicks={{
position: 'Inside', color: '#757575', width: 2, height: 10, interval: 20
}} lineStyle={{ width: 2, color: '#9E9E9E' }}
minorTicks={{
position: 'Inside', color: '#757575', height: 5, width: 2, interval: 10
}} labelStyle={{
position: 'Outside', autoAngle: true,
font: {
size: '10px'
}
}}>
<AnnotationsDirective>
<AnnotationDirective content='<div id="content" style="color:#518C03;font-size:20px;font-family:Segoe UI;font-weight:semibold;">145</div>'
angle={0} radius='0%' zIndex='1'>
</AnnotationDirective>
</AnnotationsDirective>
<PointersDirective>
<PointerDirective value={145} radius='60%' color='#8BC34A' pointerWidth={10} border={{
width: 0,
color: 'transparent'
}}
animation={{ enable: false }}
type="RangeBar"
roundedCornerRadius={10}
cap={{
radius: 0,
border: {
width: 0
}
}} />
</PointersDirective>
</AxisDirective>
</AxesDirective>
</CircularGaugeComponent>
</div>
<div className='col-lg-4 property-section'>
<PropertyPane title='Properties'>
<table id='property' title='Properties' className='property-panel-table' style={{ width: '100%' }}>
<tbody>
<tr>
<td>
<div> Ticks </div>
</td>
<td>
<div>
<select id="Ticks" className="form-control" style={{ width: '90%' }}>
<option value="major"> Major Ticks</option>
<option value="minor">Minor Ticks</option>
</select>
</div>
</td>
</tr>
<tr>
<td>
<div> Tick Position </div>
</td>
<td>
<div>
<select id="tickposition" className="form-control" style={{ width: '90%' }}>
<option value="Inside"> Inside</option>
<option value="Outside">Outside</option>
</select>
</div>
</td>
</tr>
<tr>
<td>
<div> Label Position </div>
</td>
<td>
<div>
<select id="labelposition" className="form-control" style={{ width: '90%' }}>
<option value="Outside"> Outside</option>
<option value="Inside">Inside</option>
</select>
</div>
</td>
</tr>
<tr>
<td>
<div id='offset'>Tick Offset <span> 0</span> </div>
</td>
<td>
<div>
<input type="range" onChange={this.ticksOffset.bind(this)} ref={d => this.tickOffset = d} id="tickOffset" defaultValue="0" min="0" max="50" style={{ width: '90%' }} />
</div>
</td>
</tr>
<tr>
<td>
<div id='height'>Tick Height <span> 10</span> </div>
</td>
<td>
<div>
<input type="range" onChange={this.ticksHeight.bind(this)} ref={d => this.tickHeight = d} id="tickHeight" defaultValue="10" min="1" max="50" style={{ width: '90%' }} />
</div>
</td>
</tr>
<tr>
<td>
<div id='labelOffsetValue'>Label Offset <span> 0</span> </div>
</td>
<td>
<div>
<input type="range" onChange={this.labelsOffset.bind(this)} ref={d => this.labelOffset = d} id="labelOffset" defaultValue="0" min="0" max="50" style={{ width: '90%' }} />
</div>
</td>
</tr>
</tbody>
</table>
</PropertyPane>
</div>
</div>
<div id="action-description">
<p>
This sample illustrates how to customize the ticks and labels of an axis.
Position, offset, and height of the tick and label can be changed by using the options provided in the property panel.
</p>
</div>
<div id="description">
<p>
In this example, you can see how to render and configure the ticks and labels of an axis in the circular gauge. Labels are
units that are used to display the values in the axis. You can customize <code>labels</code> with the properties
like <code>angle</code>, <code>font</code>,
<code>position</code>, etc. Ticks are used to mark some values on the axis. You can also customize the ticks using
<code>majorTicks</code>,
<code>minorTicks</code> properties.
</p>
<p>
More information on the labels can be found in this
<a target="_blank" href="http://ej2.syncfusion.com/documentation"> documentation section</a>.
</p>
</div>
</div>
)
}
public onChartLoad(args: {}): void {
if (!this.loaded) {
this.loaded = true;
this.ticks = new DropDownList({
index: 0, width: 130,
change: () => {
let value: string = this.ticks.value.toString();
let tickProp: TickModel; this.isMajorTicks = value === 'major';
if (this.isMajorTicks) {
tickProp = this.gauge.axes[0].majorTicks;
} else {
tickProp = this.gauge.axes[0].minorTicks;
}
this.tickPosition.value = tickProp.position;
this.tickOffset.value = tickProp.offset.toString();
this.tickHeight.value = tickProp.height.toString();
document.getElementById('offset').innerHTML = 'Tick Offset <span> ' + tickProp.offset;
document.getElementById('height').innerHTML = 'Tick Height <span> ' + tickProp.height;
}
});
this.ticks.appendTo('#Ticks');
this.tickPosition = new DropDownList({
index: 0, width: 130,
change: () => {
let value: string = this.tickPosition.value.toString();
if (this.isMajorTicks) {
this.gauge.axes[0].majorTicks.position = value == 'Inside' ? 'Inside' : 'Outside';
} else {
this.gauge.axes[0].minorTicks.position = value == 'Inside' ? 'Inside' : 'Outside';
}
this.gauge.refresh();
}
});
this.tickPosition.appendTo('#tickposition');
this.labelPosition = new DropDownList({
index: 0, width: 130,
change: () => {
let value: string = this.labelPosition.value.toString();
this.gauge.axes[0].labelStyle.position = value == 'Inside' ? 'Inside' : 'Outside';
this.gauge.refresh();
}
});
this.labelPosition.appendTo('#labelposition');
}
}
}