]> git.proxmox.com Git - extjs.git/blame - extjs/packages/charts/src/chart/label/Label.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / charts / src / chart / label / Label.js
CommitLineData
6527f429
DM
1/**\r
2 * @class Ext.chart.label.Label\r
3 * @extends Ext.draw.sprite.Text\r
4 *\r
5 * Sprite used to represent labels in series.\r
6 *\r
7 * Important: the actual default values are determined by the theme used.\r
8 * Please see the `label` config of the {@link Ext.chart.theme.Base#axis}.\r
9 */\r
10Ext.define('Ext.chart.label.Label', {\r
11 extend: 'Ext.draw.sprite.Text',\r
12 requires: ['Ext.chart.label.Callout'],\r
13\r
14 inheritableStatics: {\r
15 def: {\r
16 processors: {\r
17 callout: 'limited01',\r
18 calloutHasLine: 'bool',\r
19 calloutPlaceX: 'number',\r
20 calloutPlaceY: 'number',\r
21 calloutStartX: 'number',\r
22 calloutStartY: 'number',\r
23 calloutEndX: 'number',\r
24 calloutEndY: 'number',\r
25 calloutColor: 'color',\r
26 calloutWidth: 'number',\r
27 calloutVertical: 'bool',\r
28 labelOverflowPadding: 'number',\r
29 display: 'enums(none,under,over,rotate,insideStart,insideEnd,inside,outside)',\r
30 orientation: 'enums(horizontal,vertical)',\r
31 renderer: 'default'\r
32 },\r
33\r
34 defaults: {\r
35 callout: 0,\r
36 calloutHasLine: true,\r
37 calloutPlaceX: 0,\r
38 calloutPlaceY: 0,\r
39 calloutStartX: 0,\r
40 calloutStartY: 0,\r
41 calloutEndX: 0,\r
42 calloutEndY: 0,\r
43 calloutWidth: 1,\r
44 calloutVertical: false,\r
45 calloutColor: 'black',\r
46 labelOverflowPadding: 5,\r
47 display: 'none',\r
48 orientation: '',\r
49 renderer: null\r
50 },\r
51\r
52 triggers: {\r
53 callout: 'transform',\r
54 calloutPlaceX: 'transform',\r
55 calloutPlaceY: 'transform',\r
56 labelOverflowPadding: 'transform',\r
57 calloutRotation: 'transform',\r
58 display: 'hidden'\r
59 },\r
60\r
61 updaters: {\r
62 hidden: function (attrs) {\r
63 attrs.hidden = attrs.display === 'none';\r
64 }\r
65 }\r
66 }\r
67 },\r
68\r
69 config: {\r
70 /**\r
71 * @cfg {Object} fx Animation configuration.\r
72 */\r
73 fx: {\r
74 customDurations: {\r
75 callout: 200\r
76 }\r
77 },\r
78 field: null,\r
79 /**\r
80 * @cfg {Boolean|Object} calloutLine\r
81 *\r
82 * True to draw a line between the label and the chart with the default settings,\r
83 * or an Object that defines the 'color', 'width' and 'length' properties of the line.\r
84 * This config is only applicable when the label is displayed outside the chart.\r
85 *\r
86 * Default value: false.\r
87 */\r
88 calloutLine: true\r
89 },\r
90\r
91 applyCalloutLine: function (calloutLine) {\r
92 if (calloutLine) {\r
93 return Ext.apply({}, calloutLine);\r
94 }\r
95 },\r
96\r
97 prepareModifiers: function () {\r
98 this.callParent(arguments);\r
99 this.calloutModifier = new Ext.chart.label.Callout({sprite: this});\r
100 this.fx.setNext(this.calloutModifier);\r
101 this.calloutModifier.setNext(this.topModifier);\r
102 },\r
103\r
104 render: function (surface, ctx) {\r
105 var me = this,\r
106 attr = me.attr,\r
107 calloutColor = attr.calloutColor;\r
108\r
109 ctx.save();\r
110 ctx.globalAlpha *= attr.callout;\r
111 if (ctx.globalAlpha > 0 && attr.calloutHasLine) {\r
112 if (calloutColor && calloutColor.isGradient) {\r
113 calloutColor = calloutColor.getStops()[0].color;\r
114 }\r
115 ctx.strokeStyle = calloutColor;\r
116 ctx.fillStyle = calloutColor;\r
117 ctx.lineWidth = attr.calloutWidth;\r
118 ctx.beginPath();\r
119 ctx.moveTo(me.attr.calloutStartX, me.attr.calloutStartY);\r
120 ctx.lineTo(me.attr.calloutEndX, me.attr.calloutEndY);\r
121 ctx.stroke();\r
122\r
123 ctx.beginPath();\r
124 ctx.arc(me.attr.calloutStartX, me.attr.calloutStartY, 1 * attr.calloutWidth, 0, 2 * Math.PI, true);\r
125 ctx.fill();\r
126\r
127 ctx.beginPath();\r
128 ctx.arc(me.attr.calloutEndX, me.attr.calloutEndY, 1 * attr.calloutWidth, 0, 2 * Math.PI, true);\r
129 ctx.fill();\r
130 }\r
131 ctx.restore();\r
132\r
133 Ext.draw.sprite.Text.prototype.render.apply(me, arguments);\r
134 }\r
135});