/
Navigator.js
137 lines (126 loc) · 4.63 KB
/
Navigator.js
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
import React, { Component } from 'react';
import { Container } from '@sencha/ext-modern';
import { ChartNavigator } from '@sencha/ext-charts';
import createData from './createData';
import ChartToolbar from '../ChartToolbar';
Ext.require([
'Ext.chart.series.Line',
'Ext.chart.axis.Numeric',
'Ext.chart.axis.Time',
'Ext.chart.navigator.Container'
]);
export default class NavigatorExample extends Component {
store = Ext.create('Ext.data.Store', {
fields: [ 'x', 'sin', 'cos' ],
data: createData()
});
state = {
theme: 'default',
zoom: false
};
changeTheme = theme => this.setState({ theme })
toggleZoomOnPan = (zoomOnPan) => {
this.getChart().getInteraction('panzoom').setZoomOnPan(zoomOnPan);
this.setState({zoom:zoomOnPan})
}
componentDidUpdate(prevProps, prevState) {
if (prevState.theme !== this.state.theme) {
this.getChart().setTheme(this.state.theme);
}
}
getChart() {
//Added cmp to access component attributes in ext-react16 [revisit]
return this.navigator.cmp.getChart()
}
categoryRenderer = (axis, value) => Math.round(value * 180 / Math.PI)
render() {
const { theme } = this.state;
const { zoom } = this.state;
return (
<Container padding={!Ext.os.is.Phone && 10} layout="fit">
<ChartToolbar
onThemeChange={this.changeTheme}
onToggleZoomOnPan={this.toggleZoomOnPan}
theme={theme}
/>
<ChartNavigator
shadow
ref={(navigator) => {this.navigator = navigator}}
navigator={{ axis: 'bottom' }}
chart={{
xtype: 'cartesian',
downloadServerUrl: 'http://svg.sencha.io',
reference: 'chart',
insetPadding: '20 10 10 10',
platformConfig: {
phone: {
insetPadding: '10 5 0 0'
}
},
interactions: {
type: 'panzoom',
zoomOnPanGesture: false,
axes: {
left: {
allowPan: false,
allowZoom: false
}
}
},
legend: {
type: 'sprite'
},
store: this.store,
axes: [{
type: 'numeric',
position: 'left',
grid: true
}, {
id: 'bottom',
type: 'category',
position: 'bottom',
grid: true,
renderer: this.categoryRenderer,
label: {
rotation: {
degrees: -90
}
}
}],
series: [{
type: 'line',
title: 'sin',
xField: 'x',
yField: 'sin',
marker: {
type: 'triangle',
fx: {
duration: 200,
easing: 'backOut'
}
},
highlight: {
scaling: 2
}
}, {
type: 'line',
title: 'cos',
xField: 'x',
yField: 'cos',
marker: {
type: 'cross',
fx: {
duration: 200,
easing: 'backOut'
}
},
highlight: {
scaling: 2
}
}],
}}
/>
</Container>
)
}
}