-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.tsx
167 lines (145 loc) · 5.91 KB
/
index.tsx
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
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrLegendModule, IgrDataChartCoreModule, IgrDataChartCategoryModule, IgrDataChartCategoryCoreModule, IgrDataChartInteractivityModule, IgrDataChartAnnotationModule, IgrDataChartStackedModule, IgrStackedFragmentSeriesModule } from 'igniteui-react-charts';
import { IgrLegend, IgrDataChart, IgrCategoryYAxis, IgrNumericXAxis, IgrStacked100BarSeries, IgrStackedFragmentSeries, IgrDataToolTipLayer } from 'igniteui-react-charts';
import { EnergyRenewableConsumptionItem, EnergyRenewableConsumption } from './EnergyRenewableConsumption';
import { IgrCategoryChart, IgrChartSelection, IgrSeriesMatcher } from 'igniteui-react-charts';
const mods: any[] = [
IgrLegendModule,
IgrDataChartCoreModule,
IgrDataChartCategoryModule,
IgrDataChartCategoryCoreModule,
IgrDataChartInteractivityModule,
IgrDataChartAnnotationModule,
IgrDataChartStackedModule,
IgrStackedFragmentSeriesModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component<any, any> {
private legend: IgrLegend
private legendRef(r: IgrLegend) {
this.legend = r;
this.setState({});
}
private chart: IgrDataChart
private chartRef(r: IgrDataChart) {
this.chart = r;
this.setState({});
}
private yAxis: IgrCategoryYAxis
private xAxis: IgrNumericXAxis
private stacked100BarSeries: IgrStacked100BarSeries
private s1: IgrStackedFragmentSeries
private s2: IgrStackedFragmentSeries
private s3: IgrStackedFragmentSeries
private s4: IgrStackedFragmentSeries
private dataToolTipLayer: IgrDataToolTipLayer
constructor(props: any) {
super(props);
this.legendRef = this.legendRef.bind(this);
this.chartRef = this.chartRef.bind(this);
}
public componentDidMount() {
this.selectionMatcherOnViewInit();
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="legend-title">
Renewable Energy Consumption
</div>
<div className="legend">
<IgrLegend
ref={this.legendRef}
orientation="Horizontal">
</IgrLegend>
</div>
<div className="container fill">
<IgrDataChart
ref={this.chartRef}
legend={this.legend}
isHorizontalZoomEnabled="false"
isVerticalZoomEnabled="false"
selectionMode="SelectionColorFill"
selectionBehavior="Auto"
selectionBrush="orange">
<IgrCategoryYAxis
name="yAxis"
dataSource={this.energyRenewableConsumption}
label="location"
isInverted="true">
</IgrCategoryYAxis>
<IgrNumericXAxis
name="xAxis"
minimumValue="0"
title="TWh">
</IgrNumericXAxis>
<IgrStacked100BarSeries
name="stacked100BarSeries"
dataSource={this.energyRenewableConsumption}
xAxisName="xAxis"
yAxisName="yAxis"
showDefaultTooltip="true"
areaFillOpacity="1">
<IgrStackedFragmentSeries
name="s1"
valueMemberPath="hydro"
title="Hydro">
</IgrStackedFragmentSeries>
<IgrStackedFragmentSeries
name="s2"
valueMemberPath="wind"
title="Wind">
</IgrStackedFragmentSeries>
<IgrStackedFragmentSeries
name="s3"
valueMemberPath="solar"
title="Solar">
</IgrStackedFragmentSeries>
<IgrStackedFragmentSeries
name="s4"
valueMemberPath="other"
title="Other">
</IgrStackedFragmentSeries>
</IgrStacked100BarSeries>
<IgrDataToolTipLayer
name="dataToolTipLayer">
</IgrDataToolTipLayer>
</IgrDataChart>
</div>
</div>
);
}
private _energyRenewableConsumption: EnergyRenewableConsumption = null;
public get energyRenewableConsumption(): EnergyRenewableConsumption {
if (this._energyRenewableConsumption == null)
{
this._energyRenewableConsumption = new EnergyRenewableConsumption();
}
return this._energyRenewableConsumption;
}
private _timer: ReturnType<typeof setInterval>;
public selectionMatcherOnViewInit(): void {
var chart = this.chart;
this._timer = setInterval(() => {
var matcher = new IgrSeriesMatcher();
var data = this.energyRenewableConsumption;
var selection = new IgrChartSelection();
selection.item = data[1];
matcher.memberPath = "hydro";
matcher.memberPathType = "ValueMemberPath";
selection.matcher = matcher;
chart.selectedSeriesItems.add(selection);
var selection2 = new IgrChartSelection();
selection2.item = data[2];
matcher.memberPath = "wind";
matcher.memberPathType = "ValueMemberPath";
selection2.matcher = matcher;
chart.selectedSeriesItems.add(selection2);
}, 100);
}
}
// rendering above component in the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Sample/>);