1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-chart.LegendItem-method-constructor'><span id='Ext-chart.LegendItem'>/**
2 </span></span> * @class Ext.chart.LegendItem
3 * @extends Ext.draw.CompositeSprite
4 * A single item of a legend (marker plus label)
7 Ext.define('Ext.chart.LegendItem', {
9 /* Begin Definitions */
11 extend: 'Ext.draw.CompositeSprite',
13 requires: ['Ext.chart.Shape'],
17 // Position of the item, relative to the upper-left corner of the legend box
22 constructor: function(config) {
23 this.callParent(arguments);
24 this.createLegend(config);
27 <span id='Ext-chart.LegendItem-method-createLegend'> /**
28 </span> * Creates all the individual sprites for this legend item
30 createLegend: function(config) {
32 index = config.yFieldIndex,
34 seriesType = series.type,
38 refX = legend.x + me.x,
39 refY = legend.y + me.y,
41 markerConfig, label, mask,
42 radius, toggle = false,
43 seriesStyle = Ext.apply(series.seriesStyle, series.style);
45 function getSeriesProp(name) {
46 var val = series[name];
47 return (Ext.isArray(val) ? val[idx] : val);
50 label = me.add('label', surface.add({
55 font: legend.labelFont,
56 text: getSeriesProp('title') || getSeriesProp('yField')
59 // Line series - display as short line with optional marker in the middle
60 if (seriesType === 'line' || seriesType === 'scatter') {
61 if(seriesType === 'line') {
62 me.add('line', surface.add({
64 path: 'M0.5,0.5L16.5,0.5',
66 "stroke-width": series.lineWidth,
67 "stroke-linejoin": "round",
68 "stroke-dasharray": series.dash,
69 stroke: seriesStyle.stroke || '#000',
75 if (series.showMarkers || seriesType === 'scatter') {
76 markerConfig = Ext.apply(series.markerStyle, series.markerConfig || {});
77 me.add('marker', Ext.chart.Shape[markerConfig.type](surface, {
78 fill: markerConfig.fill,
82 radius: markerConfig.radius || markerConfig.size,
89 // All other series types - display as filled box
91 me.add('box', surface.add({
98 fill: series.getLegendColor(index),
111 mask = me.add('mask', surface.add({
115 width: bbox.width || 20,
116 height: bbox.height || 20,
117 zIndex: (z || 0) + 1000,
125 //add toggle listener
126 me.on('mouseover', function() {
128 'font-weight': 'bold'
133 series._index = index;
134 series.highlightItem();
137 me.on('mouseout', function() {
139 'font-weight': 'normal'
141 series._index = index;
142 series.unHighlightItem();
145 if (!series.visibleInLegend(index)) {
147 label.setAttributes({
152 me.on('mousedown', function() {
155 label.setAttributes({
160 label.setAttributes({
166 me.updatePosition({x:0, y:0}); //Relative to 0,0 at first so that the bbox is calculated correctly
169 <span id='Ext-chart.LegendItem-method-updatePosition'> /**
170 </span> * Update the positions of all this item's sprites to match the root position
172 * @param {Object} relativeTo (optional) If specified, this object's 'x' and 'y' values will be used
173 * as the reference point for the relative positioning. Defaults to the Legend.
175 updatePosition: function(relativeTo) {
182 relativeTo = me.legend;
184 for (; i < ln; i++) {
189 x: 20 + relativeTo.x + me.x,
190 y: relativeTo.y + me.y
196 x: relativeTo.x + me.x,
197 y: relativeTo.y + me.y - 6
204 x: relativeTo.x + me.x,
205 y: relativeTo.y + me.y
211 });</pre></pre></body></html>