forked from nohuhu/Ext.ux.chart.TitleChart
/
demo_titlechart.js
148 lines (141 loc) · 4.72 KB
/
demo_titlechart.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
138
139
140
141
142
143
144
145
146
147
148
/*
* Title Chart demo page.
*
* Copyright (C) 2011-2012 Alexander Tokarev.
*
* This code is licensed under the terms of the Open Source LGPL 3.0 license.
* Commercial use is permitted to the extent that the code/component(s) do NOT
* become part of another Open Source or Commercially licensed development library
* or toolkit without explicit permission.
*
* License details: http://www.gnu.org/licenses/lgpl.html
*/
Ext.onReady(function () {
var panel, chart, legend,
title = 'Ain\'t it cool to have a Title?',
store = Ext.create('Ext.data.Store', {
fields: [ 'name', 'data' ],
data: [
{ name: 'Field 0', data: Math.random() * 100 },
{ name: 'Field 1', data: Math.random() * 100 },
{ name: 'Field 2', data: Math.random() * 100 },
{ name: 'Field 3', data: Math.random() * 100 },
{ name: 'Field 4', data: Math.random() * 100 },
{ name: 'Field 5', data: Math.random() * 100 },
{ name: 'Field 6', data: Math.random() * 100 },
{ name: 'Field 7', data: Math.random() * 100 },
{ name: 'Field 8', data: Math.random() * 100 },
{ name: 'Field 9', data: Math.random() * 100 },
{ name: 'Field 10', data: Math.random() * 100 },
{ name: 'Field 11', data: Math.random() * 100 },
{ name: 'Field 12', data: Math.random() * 100 }
]
});
var buttonHandler = function(button, object) {
var positions = { '←': 'left', '↑': 'top', '→': 'right', '↓': 'bottom' };
switch ( object ) {
case 'legend':
if ( positions[button.text] ) {
legend.position = positions[button.text];
legend.isVertical = !!("left|right".indexOf(legend.position) !== -1);
chart.legend = legend;
legend.show && legend.show();
}
else {
legend.hide && legend.hide();
chart.legend = false;
};
break;
case 'title':
if ( positions[button.text] ) {
chart.title = title;
chart.titleLocation = positions[button.text];
}
else {
chart.title = false;
};
};
chart.redraw();
};
panel = Ext.create('widget.panel', {
width: 450,
height: 400,
position: 'absolute',
x: 100,
y: 100,
title: 'Title Chart demo',
renderTo: Ext.getBody(),
layout: 'fit',
tbar: [{
xtype: 'tbtext',
text: 'Move Title:'
}, {
xtype: 'tbseparator'
}, {
text: '←',
handler: Ext.bind(buttonHandler, panel, [ 'title' ], 1)
}, {
text: '↑',
handler: Ext.bind(buttonHandler, panel, [ 'title' ], 1)
}, {
text: '↓',
handler: Ext.bind(buttonHandler, panel, [ 'title' ], 1)
}, {
text: '→',
handler: Ext.bind(buttonHandler, panel, [ 'title' ], 1)
}, {
text: '⊗',
handler: Ext.bind(buttonHandler, panel, [ 'title' ], 1)
}, {
xtype: 'tbseparator'
}, {
xtype: 'tbtext',
text: ' '
}, {
hideLabel: true,
id: 'titleFontText',
xtype: 'textfield',
width: 120,
emptyText: 'CSS font:',
listeners: {
specialkey: function(field, event){
if (event.getKey() === event.ENTER) {
Ext.getCmp('titleFontButton').handler();
}
}
}
}, {
id: 'titleFontButton',
text: 'Set font',
handler: function(){
chart.titleFont = Ext.getCmp('titleFontText').getValue();
chart.redraw();
}
}],
items: {
xtype: 'titlechart',
title: title,
titleFont: 'bold 16px sans-serif',
titlePadding: 5,
titleMargin: 5,
insetPadding: 5,
id: 'chart',
animate: Ext.isIE ? false : true,
store: store,
shadow: Ext.isIE ? false : true,
legend: false,
theme: 'Base:gradients',
series: [{
type: 'pie',
field: 'data',
showInLegend: true,
label: {
display: 'rotate',
contrast: true
}
}]
}
});
chart = panel.down('chart');
chart.redraw();
});