4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-chart-LegendItem'>/**
19 </span> * @class Ext.chart.LegendItem
20 * @extends Ext.draw.CompositeSprite
21 * A single item of a legend (marker plus label)
23 Ext.define('Ext.chart.LegendItem', {
25 /* Begin Definitions */
27 extend: 'Ext.draw.CompositeSprite',
29 requires: ['Ext.chart.Shape'],
33 // Position of the item, relative to the upper-left corner of the legend box
38 constructor: function(config) {
39 this.callParent(arguments);
40 this.createLegend(config);
43 <span id='Ext-chart-LegendItem-method-createLegend'> /**
44 </span> * Creates all the individual sprites for this legend item
46 createLegend: function(config) {
48 index = config.yFieldIndex,
50 seriesType = series.type,
54 refX = legend.x + me.x,
55 refY = legend.y + me.y,
57 markerConfig, label, mask,
58 radius, toggle = false,
59 seriesStyle = Ext.apply(series.seriesStyle, series.style);
61 function getSeriesProp(name) {
62 var val = series[name];
63 return (Ext.isArray(val) ? val[idx] : val);
66 label = me.add('label', surface.add({
71 font: legend.labelFont,
72 text: getSeriesProp('title') || getSeriesProp('yField')
75 // Line series - display as short line with optional marker in the middle
76 if (seriesType === 'line' || seriesType === 'scatter') {
77 if(seriesType === 'line') {
78 me.add('line', surface.add({
80 path: 'M0.5,0.5L16.5,0.5',
82 "stroke-width": series.lineWidth,
83 "stroke-linejoin": "round",
84 "stroke-dasharray": series.dash,
85 stroke: seriesStyle.stroke || '#000',
91 if (series.showMarkers || seriesType === 'scatter') {
92 markerConfig = Ext.apply(series.markerStyle, series.markerConfig || {});
93 me.add('marker', Ext.chart.Shape[markerConfig.type](surface, {
94 fill: markerConfig.fill,
98 radius: markerConfig.radius || markerConfig.size,
105 // All other series types - display as filled box
107 me.add('box', surface.add({
114 fill: series.getLegendColor(index),
127 mask = me.add('mask', surface.add({
131 width: bbox.width || 20,
132 height: bbox.height || 20,
133 zIndex: (z || 0) + 1000,
141 //add toggle listener
142 me.on('mouseover', function() {
144 'font-weight': 'bold'
149 series._index = index;
150 series.highlightItem();
153 me.on('mouseout', function() {
155 'font-weight': 'normal'
157 series._index = index;
158 series.unHighlightItem();
161 if (!series.visibleInLegend(index)) {
163 label.setAttributes({
168 me.on('mousedown', function() {
171 label.setAttributes({
176 label.setAttributes({
182 me.updatePosition({x:0, y:0}); //Relative to 0,0 at first so that the bbox is calculated correctly
185 <span id='Ext-chart-LegendItem-method-updatePosition'> /**
186 </span> * Update the positions of all this item's sprites to match the root position
188 * @param {Object} relativeTo (optional) If specified, this object's 'x' and 'y' values will be used
189 * as the reference point for the relative positioning. Defaults to the Legend.
191 updatePosition: function(relativeTo) {
198 relativeTo = me.legend;
200 for (; i < ln; i++) {
205 x: 20 + relativeTo.x + me.x,
206 y: relativeTo.y + me.y
212 x: relativeTo.x + me.x,
213 y: relativeTo.y + me.y - 6
220 x: relativeTo.x + me.x,
221 y: relativeTo.y + me.y