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 pathrange-band.tsx
More file actions
196 lines (181 loc) · 8.13 KB
/
range-band.tsx
File metadata and controls
196 lines (181 loc) · 8.13 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
/**
* Rangeband sample for sparkline
*/
import * as React from "react";
import * as ReactDOM from "react-dom";
import { PropertyPane } from '../common/property-pane';
import { SliderComponent } from "@syncfusion/ej2-react-inputs";
import {
SparklineComponent, SparklineTheme, RangeBandSettingsDirective, RangeBandSettingDirective,
ISparklineLoadedEventArgs, SparklineModel, Sparkline
} from '@syncfusion/ej2-react-charts';
import { getInstance } from '@syncfusion/ej2-base';
import { GridComponent, ColumnsDirective, ColumnDirective, Selection, Inject } from '@syncfusion/ej2-react-grids';
import { DropDownListComponent } from '@syncfusion/ej2-react-dropdowns';
import { SampleBase } from '../common/sample-base';
import { products } from './data-source';
const SAMPLE_CSS = `
.control-fluid {
padding: 0px !important;
}
td{
padding: 10px;
}
.e-headertext{
font-weight: bolder;
}
#range-min > * {
padding: 0px !important;
}
#range-max > * {
padding: 0px !important;
}`;
export class GridData {
public id: string;
}
export class RangeBand extends SampleBase<{}, {}> {
private sparklineInstance: SparklineComponent;
private minElement: SliderComponent;
private maxElement: SliderComponent;
public load(args: ISparklineLoadedEventArgs): void {
let theme: string = location.hash.split('/')[1];
theme = theme ? theme : 'Material';
args.sparkline.theme = (theme.charAt(0).toUpperCase() + theme.slice(1)) as SparklineTheme;
}
private lineData: Object[] = [
[0, 6, 4, 1, 3, 2, 5],
[5, 4, 6, 3, 1, 2, 0],
[6, 4, 0, 3, 2, 5, 1],
[4, 6, 3, 0, 1, 2, 5],
[3, 5, 6, 4, 0, 1, 2],
[1, 3, 4, 2, 5, 0, 6],
[2, 4, 0, 3, 5, 6, 1],
[5, 4, 6, 3, 1, 2, 0],
[0, 6, 4, 1, 3, 2, 5],
[6, 4, 0, 3, 2, 5, 1],
[4, 6, 3, 0, 1, 2, 5],
[3, 5, 6, 4, 0, 1, 2],
[1, 3, 4, 2, 5, 0, 6],
[2, 4, 0, 3, 5, 6, 1],
[5, 4, 6, 3, 1, 2, 0],
[0, 6, 4, 1, 3, 2, 5],
[6, 4, 0, 3, 2, 5, 1],
[4, 6, 3, 0, 1, 2, 5],
[2, 4, 0, 3, 5, 6, 1],
[3, 5, 6, 4, 0, 1, 2],
[1, 3, 4, 2, 5, 0, 6]
];
private minChange = () => {
let value: number = parseInt(this.minElement.value.toString(), 10);
this.changeRangeMin(value);
}
private maxChange = () => {
let value: number = parseInt(this.maxElement.value.toString(), 10);
this.changeRangeMax(value);
}
private changeRangeMin: Function = (min: number): void => {
for (let i: number = 1; i < 6; i++) {
let first: SparklineComponent = getInstance('#sparkline2010' + i, Sparkline) as SparklineComponent;
let second: SparklineComponent = getInstance('#sparkline2011' + i, Sparkline) as SparklineComponent;
first.rangeBandSettings[0].startRange = min;
second.rangeBandSettings[0].startRange = min;
document.getElementById('range1').innerHTML = 'Range Band Min <span>' + this.minElement.value;
first.refresh();
second.refresh();
}
}
private changeRangeMax: Function = (max: number): void => {
for (let i: number = 1; i < 6; i++) {
let first: SparklineComponent = getInstance('#sparkline2010' + i, Sparkline) as SparklineComponent;
let second: SparklineComponent = getInstance('#sparkline2011' + i, Sparkline) as SparklineComponent;
first.rangeBandSettings[0].endRange = max;
second.rangeBandSettings[0].endRange = max;
document.getElementById('range2').innerHTML = 'Range Band Max <span>' + this.maxElement.value;
first.refresh();
second.refresh();
}
}
private renderSparkline(): void {
let sparkline: SparklineModel = {
height: '50px',
width: '150px',
lineWidth: 2,
fill: '#0d3c9b',
dataSource: this.lineData[0] as Number[],
rangeBandSettings: [{ startRange: 1, endRange: 3, color: '#bfd4fc' }]
};
setTimeout(() => {
for (let i: number = 1; i < 6; i++) {
let first: SparklineComponent = new SparklineComponent(sparkline);
first.dataSource = this.lineData[i] as number[];
first.appendTo('#sparkline2010' + i);
let second: SparklineComponent = new SparklineComponent(sparkline);
second.dataSource = this.lineData[i + 5] as number[];
second.appendTo('#sparkline2011' + i);
}
}, 500);
}
render() {
return (
<div className='control-pane'>
<style>
{SAMPLE_CSS}
</style>
<div className='col-md-8 control-section'>
<div style={{ "font-size": "16px", "textAlign": "center" }}>
Sales Growth Comparison with various Products
</div>
<GridComponent dataSource={products} resizing={this.renderSparkline.bind(this)} load={this.renderSparkline.bind(this)}
height='400'
allowSelection={false}
enableColumnVirtualization={true}
enableHover={true}>
<ColumnsDirective>
<ColumnDirective field='name' headerText='Name' textAlign='Right' width='50' />
<ColumnDirective headerText='2010' template={(props: GridData) => {
return (<div id={"sparkline2010" + props.id}></div>);
}} textAlign='Center' width='100' />
<ColumnDirective headerText='One Day Index' template={(props: GridData) => {
return (<div id={"sparkline2011" + props.id}></div>);
}} textAlign='Center' width='100' />
</ColumnsDirective>
</GridComponent>
</div>
<div className='col-md-4 property-section'>
<PropertyPane title='Properties'>
<table id='property' title='Properties' className='property-panel-table' style={{ width: '100%' }}>
<tbody>
<tr>
<td>
<div id='range1'>Range Band Min <span> 1</span> </div>
</td>
<td>
<SliderComponent type='MinRange' change={this.minChange.bind(this)} ref={(slider) => this.minElement = slider} step={1} id="range-min" value={1} min={0} max={6} style={{ width: '100px' }} />
</td>
</tr>
<tr>
<td>
<div id='range2'>Range Band Max <span> 3</span> </div>
</td>
<td>
<SliderComponent type='MinRange' change={this.maxChange.bind(this)} ref={(slider) => this.maxElement = slider} step={1} id="range-max" value={3} min={0} max={6} style={{ width: '100px' }} />
</td>
</tr>
</tbody>
</table>
</PropertyPane>
</div>
<div id="action-description">
<p>
This sample depicts the range band feature and its customization options available in sparklines.
</p>
</div>
<div id="description">
<p>
In this example, you can see how to render sparkline with range band and the customization options available in range band. Here, the sparklines are placed inside the data grid control.
</p>
</div>
</div>
)
}
}