4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../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-method-constructor'><span id='Ext-chart-LegendItem'>/**
19 </span></span> * @class Ext.chart.LegendItem
20 * @extends Ext.draw.CompositeSprite
21 * A single item of a legend (marker plus label)
24 Ext.define('Ext.chart.LegendItem', {
26 /* Begin Definitions */
28 extend: 'Ext.draw.CompositeSprite',
30 requires: ['Ext.chart.Shape'],
34 // Position of the item, relative to the upper-left corner of the legend box
39 constructor: function(config) {
40 this.callParent(arguments);
41 this.createLegend(config);
44 <span id='Ext-chart-LegendItem-method-createLegend'> /**
45 </span> * Creates all the individual sprites for this legend item
47 createLegend: function(config) {
49 index = config.yFieldIndex,
51 seriesType = series.type,
55 refX = legend.x + me.x,
56 refY = legend.y + me.y,
58 markerConfig, label, mask,
59 radius, toggle = false,
60 seriesStyle = Ext.apply(series.seriesStyle, series.style);
62 function getSeriesProp(name) {
63 var val = series[name];
64 return (Ext.isArray(val) ? val[idx] : val);
67 label = me.add('label', surface.add({
72 font: legend.labelFont,
73 text: getSeriesProp('title') || getSeriesProp('yField')
76 // Line series - display as short line with optional marker in the middle
77 if (seriesType === 'line' || seriesType === 'scatter') {
78 if(seriesType === 'line') {
79 me.add('line', surface.add({
81 path: 'M0.5,0.5L16.5,0.5',
83 "stroke-width": series.lineWidth,
84 "stroke-linejoin": "round",
85 "stroke-dasharray": series.dash,
86 stroke: seriesStyle.stroke || '#000',
92 if (series.showMarkers || seriesType === 'scatter') {
93 markerConfig = Ext.apply(series.markerStyle, series.markerConfig || {});
94 me.add('marker', Ext.chart.Shape[markerConfig.type](surface, {
95 fill: markerConfig.fill,
99 radius: markerConfig.radius || markerConfig.size,
106 // All other series types - display as filled box
108 me.add('box', surface.add({
115 fill: series.getLegendColor(index),
128 mask = me.add('mask', surface.add({
132 width: bbox.width || 20,
133 height: bbox.height || 20,
134 zIndex: (z || 0) + 1000,
142 //add toggle listener
143 me.on('mouseover', function() {
145 'font-weight': 'bold'
150 series._index = index;
151 series.highlightItem();
154 me.on('mouseout', function() {
156 'font-weight': 'normal'
158 series._index = index;
159 series.unHighlightItem();
162 if (!series.visibleInLegend(index)) {
164 label.setAttributes({
169 me.on('mousedown', function() {
172 label.setAttributes({
177 label.setAttributes({
183 me.updatePosition({x:0, y:0}); //Relative to 0,0 at first so that the bbox is calculated correctly
186 <span id='Ext-chart-LegendItem-method-updatePosition'> /**
187 </span> * Update the positions of all this item's sprites to match the root position
189 * @param {Object} relativeTo (optional) If specified, this object's 'x' and 'y' values will be used
190 * as the reference point for the relative positioning. Defaults to the Legend.
192 updatePosition: function(relativeTo) {
199 relativeTo = me.legend;
201 for (; i < ln; i++) {
206 x: 20 + relativeTo.x + me.x,
207 y: relativeTo.y + me.y
213 x: relativeTo.x + me.x,
214 y: relativeTo.y + me.y - 6
221 x: relativeTo.x + me.x,
222 y: relativeTo.y + me.y