Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / src / chart / Shape.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @class Ext.chart.Shape
17  * @ignore
18  */
19 Ext.define('Ext.chart.Shape', {
20
21     /* Begin Definitions */
22
23     singleton: true,
24
25     /* End Definitions */
26
27     circle: function (surface, opts) {
28         return surface.add(Ext.apply({
29             type: 'circle',
30             x: opts.x,
31             y: opts.y,
32             stroke: null,
33             radius: opts.radius
34         }, opts));
35     },
36     line: function (surface, opts) {
37         return surface.add(Ext.apply({
38             type: 'rect',
39             x: opts.x - opts.radius,
40             y: opts.y - opts.radius,
41             height: 2 * opts.radius,
42             width: 2 * opts.radius / 5
43         }, opts));
44     },
45     square: function (surface, opts) {
46         return surface.add(Ext.applyIf({
47             type: 'rect',
48             x: opts.x - opts.radius,
49             y: opts.y - opts.radius,
50             height: 2 * opts.radius,
51             width: 2 * opts.radius,
52             radius: null
53         }, opts));
54     },
55     triangle: function (surface, opts) {
56         opts.radius *= 1.75;
57         return surface.add(Ext.apply({
58             type: 'path',
59             stroke: null,
60             path: "M".concat(opts.x, ",", opts.y, "m0-", opts.radius * 0.58, "l", opts.radius * 0.5, ",", opts.radius * 0.87, "-", opts.radius, ",0z")
61         }, opts));
62     },
63     diamond: function (surface, opts) {
64         var r = opts.radius;
65         r *= 1.5;
66         return surface.add(Ext.apply({
67             type: 'path',
68             stroke: null,
69             path: ["M", opts.x, opts.y - r, "l", r, r, -r, r, -r, -r, r, -r, "z"]
70         }, opts));
71     },
72     cross: function (surface, opts) {
73         var r = opts.radius;
74         r = r / 1.7;
75         return surface.add(Ext.apply({
76             type: 'path',
77             stroke: null,
78             path: "M".concat(opts.x - r, ",", opts.y, "l", [-r, -r, r, -r, r, r, r, -r, r, r, -r, r, r, r, -r, r, -r, -r, -r, r, -r, -r, "z"])
79         }, opts));
80     },
81     plus: function (surface, opts) {
82         var r = opts.radius / 1.3;
83         return surface.add(Ext.apply({
84             type: 'path',
85             stroke: null,
86             path: "M".concat(opts.x - r / 2, ",", opts.y - r / 2, "l", [0, -r, r, 0, 0, r, r, 0, 0, r, -r, 0, 0, r, -r, 0, 0, -r, -r, 0, 0, -r, "z"])
87         }, opts));
88     },
89     arrow: function (surface, opts) {
90         var r = opts.radius;
91         return surface.add(Ext.apply({
92             type: 'path',
93             path: "M".concat(opts.x - r * 0.7, ",", opts.y - r * 0.4, "l", [r * 0.6, 0, 0, -r * 0.4, r, r * 0.8, -r, r * 0.8, 0, -r * 0.4, -r * 0.6, 0], "z")
94         }, opts));
95     },
96     drop: function (surface, x, y, text, size, angle) {
97         size = size || 30;
98         angle = angle || 0;
99         surface.add({
100             type: 'path',
101             path: ['M', x, y, 'l', size, 0, 'A', size * 0.4, size * 0.4, 0, 1, 0, x + size * 0.7, y - size * 0.7, 'z'],
102             fill: '#000',
103             stroke: 'none',
104             rotate: {
105                 degrees: 22.5 - angle,
106                 x: x,
107                 y: y
108             }
109         });
110         angle = (angle + 90) * Math.PI / 180;
111         surface.add({
112             type: 'text',
113             x: x + size * Math.sin(angle) - 10, // Shift here, Not sure why.
114             y: y + size * Math.cos(angle) + 5,
115             text:  text,
116             'font-size': size * 12 / 40,
117             stroke: 'none',
118             fill: '#fff'
119         });
120     }
121 });