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 pathlogarithmic.tsx
More file actions
215 lines (208 loc) · 9.97 KB
/
logarithmic.tsx
File metadata and controls
215 lines (208 loc) · 9.97 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
/**
* Sample for Logarithmic Axis Range Navigator
*/
import * as React from "react";
import * as ReactDOM from "react-dom";
import {
Inject, ChartComponent, Logarithmic, ChartTheme, IChangedEventArgs, ILoadedEventArgs, StepAreaSeries,
StepLineSeries, SeriesCollectionDirective, SeriesDirective, IRangeLoadedEventArgs, Tooltip, Crosshair,
RangeNavigatorComponent, RangenavigatorSeriesCollectionDirective, RangenavigatorSeriesDirective,
RangeTooltip, ILabelRenderEventsArgs, IRangeTooltipRenderEventArgs
} from '@syncfusion/ej2-react-charts';
import { Browser } from '@syncfusion/ej2-base';
import { SampleBase } from '../common/sample-base';
export let zoomFactor : number;
export let zoomPosition :number;
export let data: Object[] = [];
export let max: number = 100;
for (let i: number = 0; i < 100; i++) {
data.push({
x: Math.pow(10, i * 0.1),
y: Math.floor(Math.random() * (80 - 30 + 1)) + 30
});
}
export let themes: string[] = ['Material', 'Fabric', 'Bootstrap', 'Highcontrast'];
export let borderColor: string[] = ['#00bdae', '#4472c4', '#a16ee5', '#79ECE4'];
export let regionColor: string[] = ['rgba(0, 189, 174, 0.3)', 'rgba(68, 114, 196, 0.3)',
'rgba(161, 110, 229, 0.3)', 'rgba(121, 236, 228, 0.3)'];
const SAMPLE_CSS = `
.control-fluid {
padding: 0px;
}
#title{
font-size: 15px;
font-style: normal;
font-family: "Segoe UI";
font-weight: 500;
text-anchor: middle;
transform: none;
opacity: 1;
}
#control-container {
padding: 0px !important;
}
#material-gradient-chart stop {
stop-color: #00bdae;
}
#fabric-gradient-chart stop {
stop-color: #4472c4;
}
#bootstrap-gradient-chart stop {
stop-color: #a16ee5;
}
#highcontrast-gradient-chart stop {
stop-color: #79ECE4;
}
.chart-gradient stop[offset="0"] {
stop-opacity: 0.9;
}
.chart-gradient stop[offset="1"] {
stop-opacity: 0.3;
}
`;
export class LogarithmicAxis extends SampleBase<{}, {}> {
private chart1: ChartComponent;
private rangenavigator1: RangeNavigatorComponent;
render() {
return (
<div className='control-pane'>
<style>
{SAMPLE_CSS}
</style>
<div className='control-section'>
<div className="row" style={{ textAlign: "center" }}>
<div id="title">Inflation vs Goods Consumers</div>
</div>
<div className="row">
<RangeNavigatorComponent id='rangenavigator' ref={rangenavigator => this.rangenavigator1 = rangenavigator}
style={{ textAlign: "center" }}
labelPosition='Outside'
valueType='Logarithmic'
tooltip={{ enable: true}}
interval={1}
value={[4,6]}
labelIntersectAction='None'
width={Browser.isDevice ? '100%' : '80%'}
load={this.rangeLoad.bind(this)}
labelRender={this.renderLabel.bind(this)}
tooltipRender={this.renderTooltip.bind(this)}
changed={this.changed.bind(this)}>
<Inject services={[StepLineSeries, Logarithmic, RangeTooltip]}/>
<RangenavigatorSeriesCollectionDirective>
<RangenavigatorSeriesDirective dataSource={data} xName='x' yName='y'
type='StepLine' width={2}>
</RangenavigatorSeriesDirective>
</RangenavigatorSeriesCollectionDirective>
</RangeNavigatorComponent>
</div>
<div className="row">
<ChartComponent id='charts'
ref={chart => this.chart1 = chart}
style={{ textAlign: "center" }}
primaryXAxis={{
valueType: 'Logarithmic',
crosshairTooltip: { enable: false },
interval: 1,
edgeLabelPlacement: 'Shift',
majorGridLines: { width: 0 },
title: 'Numers of Goods Consumers'
}}
primaryYAxis={{
minimum: 0, maximum: 100,
title: 'Inflation',
labelFormat: '{value}%',
majorTickLines: { width: 0 },
lineStyle: { width: 0 }
}}
width={Browser.isDevice ? '100%' : '80%'}
height='350'
load={this.chartLoad.bind(this)}
chartArea={{ border: { width: 0 } }}
crosshair={{
enable: false,
lineType: 'Vertical'
}}>
<Inject services={[StepAreaSeries, Logarithmic, Tooltip, Crosshair]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={data} xName='x' yName='y' border={{ width: 2}}
type='StepArea' animation={{ enable: false }} marker={{ visible: true }} width={2}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
</div>
<svg style={{ height: '0' }}>
<defs>
<linearGradient id="material-gradient-chart" style={{opacity: 0.75}} className="chart-gradient" x1="0" x2="0" y1="0" y2="1">
<stop offset="0"></stop>
<stop offset="1"></stop>
</linearGradient>
<linearGradient id="fabric-gradient-chart" style={{opacity: 0.75}} className="chart-gradient" x1="0" x2="0" y1="0" y2="1">
<stop offset="0"></stop>
<stop offset="1"></stop>
</linearGradient>
<linearGradient id="bootstrap-gradient-chart" style={{opacity: 0.75}} className="chart-gradient" x1="0" x2="0" y1="0" y2="1">
<stop offset="0"></stop>
<stop offset="1"></stop>
</linearGradient>
<linearGradient id="highcontrast-gradient-chart" style={{opacity: 0.75}} className="chart-gradient" x1="0" x2="0" y1="0" y2="1">
<stop offset="0"></stop>
<stop offset="1"></stop>
</linearGradient>
</defs>
</svg>
<div id="action-description">
<p>
This sample demonstrates rendering logarithmic axis in the range navigator.
</p>
</div>
<div id="description">
<p>
Logarithmic axis uses logarithmic scale and it is very useful in visualizing when the data has values with both lower order of magnitude (eg: 10^-6) and higher order of magnitude (eg: 10^6).
To render Logarithmic axis, set <code>valueType</code> to <code>Logarithmic</code>.
Tooltip is enabled in this example, to see the tooltip in action, while the selected range is changed.
</p>
<br></br>
<p><b>Injecting Module</b></p>
<p>
The range navigator component features are segregated into individual feature-wise modules. To use logarithmic axis, inject the <code>Logarithmic</code> module using the
<code>RangeNavigator.Inject(Logarithmic)</code> method.
</p>
</div>
</div>
</div>
)
}
public changed(args: IChangedEventArgs): void {
if (this.chart1) {
this.chart1.primaryXAxis.zoomFactor = args.zoomFactor;
this.chart1.primaryXAxis.zoomPosition = args.zoomPosition;
this.chart1.dataBind();
} else {
zoomFactor =args.zoomFactor;
zoomPosition = args.zoomPosition;
}
};
public chartLoad(args: ILoadedEventArgs): void {
args.chart.primaryXAxis.zoomFactor = zoomFactor;
args.chart.primaryXAxis.zoomPosition = zoomPosition;
let selectedTheme: string = location.hash.split('/')[1];
selectedTheme = selectedTheme ? selectedTheme : 'Material';
args.chart.theme = (selectedTheme.charAt(0).toUpperCase() + selectedTheme.slice(1)) as ChartTheme;
args.chart.series[0].fill= 'url(#' + args.chart.theme.toLowerCase() + '-gradient-chart)';
args.chart.series[0].border.color = borderColor[themes.indexOf(args.chart.theme)];
};
public rangeLoad(args: IRangeLoadedEventArgs): void {
let selectedTheme: string = location.hash.split('/')[1];
selectedTheme = selectedTheme ? selectedTheme : 'Material';
args.rangeNavigator.theme = (selectedTheme.charAt(0).toUpperCase() + selectedTheme.slice(1)) as ChartTheme;
args.rangeNavigator.series[0].fill= 'url(#' + args.rangeNavigator.theme.toLowerCase() + '-gradient-chart)';
args.rangeNavigator.series[0].border.width = 2;
args.rangeNavigator.series[0].border.color = borderColor[themes.indexOf(args.rangeNavigator.theme)];
};
public renderLabel(args: ILabelRenderEventsArgs):void{
args.text = (+args.text).toExponential().toLocaleUpperCase();
};
public renderTooltip(args: IRangeTooltipRenderEventArgs):void{
args.text = [(+(+args.text).toFixed(1)).toExponential(1).toString().toLocaleUpperCase()];
};
}