You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

10 lines
13 KiB

/*
YUI 3.17.2 (build 9c3c78e)
Copyright 2014 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add("charts-legend",function(e,t){var n="top",r="right",i="bottom",s="left",o="external",u="horizontal",a="vertical",f="width",l="height",c="position",h="x",p="y",d="px",v,m={setter:function(t){var n=this.get("legend");return n&&n.destroy(!0),t instanceof e.ChartLegend?(n=t,n.set("chart",this)):(t.chart=this,t.hasOwnProperty("render")||(t.render=this.get("contentBox"),t.includeInChartLayout=!0),n=new e.ChartLegend(t)),n}},g={_positionLegendItems:function(e,t,n,r,i,s,o,u,a){var f=0,l=0,c,h,p,v,m,y=this.get("width"),b,w,E,S,x,T=s.top-u,N=y-(s.left+s.right),C,k,L,A;g._setRowArrays(e,N,o),b=g.rowArray,S=g.totalWidthArray,w=b.length;for(;l<w;++l){T+=u,E=b[l],m=E.length,x=g.getStartPoint(y,S[l],a,s);for(f=0;f<m;++f)c=E[f],h=c.node,p=c.width,v=c.height,c.x=x,c.y=0,C=isNaN(C)?x:Math.min(C,x),k=isNaN(k)?T:Math.min(k,T),L=isNaN(L)?x+p:Math.max(x+p,L),A=isNaN(A)?T+v:Math.max(T+v,A),h.setStyle("left",x+d),h.setStyle("top",T+d),x+=p+o;T+=c.height}this._contentRect={left:C,top:k,right:L,bottom:A},this.get("includeInChartLayout")&&this.set("height",T+s.bottom)},_setRowArrays:function(e,t,n){var r=e[0],i=[[r]],s=1,o=0,u=e.length,a=r.width,f,l=[[a]];for(;s<u;++s)r=e[s],f=r.width,a+n+f<=t?(a+=n+f,i[o].push(r)):(a=n+f,i[o]&&(o+=1),i[o]=[r]),l[o]=a;g.rowArray=i,g.totalWidthArray=l},getStartPoint:function(e,t,n,i){var o;switch(n){case s:o=i.left;break;case"center":o=(e-t)*.5;break;case r:o=e-t-i.right}return o}},y={_positionLegendItems:function(e,t,n,r,i,s,o,u,a){var f=0,l=0,c,h,p,v,m,g=this.get("height"),b,w,E,S,x,T=s.left-o,N,C=g-(s.top+s.bottom),k,L,A,O;y._setColumnArrays(e,C,u),b=y.columnArray,S=y.totalHeightArray,w=b.length;for(;l<w;++l){T+=o,E=b[l],m=E.length,x=y.getStartPoint(g,S[l],a,s),N=0;for(f=0;f<m;++f)c=E[f],h=c.node,p=c.height,v=c.width,c.y=x,c.x=T,k=isNaN(k)?T:Math.min(k,T),L=isNaN(L)?x:Math.min(L,x),A=isNaN(A)?T+v:Math.max(T+v,A),O=isNaN(O)?x+p:Math.max(x+p,O),h.setStyle("left",T+d),h.setStyle("top",x+d),x+=p+u,N=Math.max(N,c.width);T+=N}this._contentRect={left:k,top:L,right:A,bottom:O},this.get("includeInChartLayout")&&this.set("width",T+s.right)},_setColumnArrays:function(e,t,n){var r=e[0],i=[[r]],s=1,o=0,u=e.length,a=r.height,f,l=[[a]];for(;s<u;++s)r=e[s],f=r.height,a+n+f<=t?(a+=n+f,i[o].push(r)):(a=n+f,i[o]&&(o+=1),i[o]=[r]),l[o]=a;y.columnArray=i,y.totalHeightArray=l},getStartPoint:function(e,t,r,s){var o;switch(r){case n:o=s.top;break;case"middle":o=(e-t)*.5;break;case i:o=e-t-s.bottom}return o}},b=e.Base.create("cartesianChartLegend",e.CartesianChart,[],{_redraw:function(){if(this._drawing){this._callLater=!0;return}this._drawing=!0,this._callLater=!1;var e=this.get("width"),t=this.get("height"),n=this._getLayoutBoxDimensions(),r=n.left,i=n.right,s=n.top,o=n.bottom,u=this.get("leftAxesCollection"),a=this.get("rightAxesCollection"),f=this.get("topAxesCollection"),l=this.get("bottomAxesCollection"),c=0,h,p,v="visible",m=this.get("graph"),g,y,b,w,E,S,x,T,N=this.get("allowContentOverflow"),C,k,L,A,O,M=this.get("legend"),_={};if(u){L=[],h=u.length;for(c=h-1;c>-1;--c)L.unshift(r),r+=u[c].get("width")}if(a){k=[],h=a.length,c=0;for(c=h-1;c>-1;--c)i+=a[c].get("width"),k.unshift(e-i)}if(f){A=[],h=f.length;for(c=h-1;c>-1;--c)A.unshift(s),s+=f[c].get("height")}if(l){O=[],h=l.length;for(c=h-1;c>-1;--c)o+=l[c].get("height"),O.unshift(t-o)}E=e-(r+i),S=t-(o+s),_.left=r,_.top=s,_.bottom=t-o,_.right=e-i;if(!N){g=this._getTopOverflow(u,a),y=this._getBottomOverflow(u,a),b=this._getLeftOverflow(l,f),w=this._getRightOverflow(l,f),C=g-s;if(C>0){_.top=g;if(A){c=0,h=A.length;for(;c<h;++c)A[c]+=C}}C=y-o;if(C>0){_.bottom=t-y;if(O){c=0,h=O.length;for(;c<h;++c)O[c]-=C}}C=b-r;if(C>0){_.left=b;if(L){c=0,h=L.length;for(;c<h;++c)L[c]+=C}}C=w-i;if(C>0){_.right=e-w;if(k){c=0,h=k.length;for(;c<h;++c)k[c]-=C}}}E=_.right-_.left,S=_.bottom-_.top,x=_.left,T=_.top;if(M&&M.get("includeInChartLayout"))switch(M.get("position")){case"left":M.set("y",T),M.set("height",S);break;case"top":M.set("x",x),M.set("width",E);break;case"bottom":M.set("x",x),M.set("width",E);break;case"right":M.set("y",T),M.set("height",S)}if(f){h=f.length,c=0;for(;c<h;c++)p=f[c],p.get("width")!==E&&p.set("width",E),p.get("boundingBox").setStyle("left",x+d),p.get("boundingBox").setStyle("top",A[c]+d);p._hasDataOverflow()&&(v="hidden")}if(l){h=l.length,c=0;for(;c<h;c++)p=l[c],p.get("width")!==E&&p.set("width",E),p.get("boundingBox").setStyle("left",x+d),p.get("boundingBox").setStyle("top",O[c]+d);p._hasDataOverflow()&&(v="hidden")}if(u){h=u.length,c=0;for(;c<h;++c)p=u[c],p.get("boundingBox").setStyle("top",T+d),p.get("boundingBox").setStyle("left",L[c]+d),p.get("height")!==S&&p.set("height",S);p._hasDataOverflow()&&(v="hidden")}if(a){h=a.length,c=0;for(;c<h;++c)p=a[c],p.get("boundingBox").setStyle("top",T+d),p.get("boundingBox").setStyle("left",k[c]+d),p.get("height")!==S&&p.set("height",S);p._hasDataOverflow()&&(v="hidden")}this._drawing=!1;if(this._callLater){this._redraw();return}m&&(m.get("boundingBox").setStyle("left",x+d),m.get("boundingBox").setStyle("top",T+d),m.set("width",E),m.set("height",S),m.get("boundingBox").setStyle("overflow",v)),this._overlay&&(this._overlay.setStyle("left",x+d),this._overlay.setStyle("top",T+d),this._overlay.setStyle("width",E+d),this._overlay.setStyle("height",S+d))},_getLayoutBoxDimensions:function(){var e={top:0,right:0,bottom:0,left:0},t=this.get("legend"),a,d,v,m,g=this.get(f),y=this.get(l),b;if(t&&t.get("includeInChartLayout")){b=t.get("styles").gap,a=t.get(c);if(a!==o){d=t.get("direction"),v=d===u?l:f,m=t.get(v),e[a]=m+b;switch(a){case n:t.set(p,0);break;case i:t.set(p,y-m);break;case r:t.set(h,g-m);break;case s:t.set(h,0)}}}return e},destructor:function(){var e=this.get("legend");e&&e.destroy(!0)}},{ATTRS:{legend:m}});e.CartesianChart=b,v=e.Base.create("pieChartLegend",e.PieChart,[],{_redraw:function(){if(this._drawing){this._callLater=!0;return}this._drawing=!0,this._callLater=!1;var e=this.get("graph"),t=this.get("width"),o=this.get("height"),u,a,c=this.get("legend"),d=0,v=0,m=0,g=0,y,b,w,E,S,x;if(e)if(c){S=c.get
("position"),x=c.get("direction"),u=e.get("width"),a=e.get("height"),y=c.get("width"),b=c.get("height"),E=c.get("styles").gap;if(x==="vertical"&&u+y+E!==t||x==="horizontal"&&a+b+E!==o){switch(c.get("position")){case s:w=Math.min(t-(y+E),o),b=o,d=y+E,c.set(l,b);break;case n:w=Math.min(o-(b+E),t),y=t,v=b+E,c.set(f,y);break;case r:w=Math.min(t-(y+E),o),b=o,m=w+E,c.set(l,b);break;case i:w=Math.min(o-(b+E),t),y=t,g=w+E,c.set(f,y)}e.set(f,w),e.set(l,w)}else switch(c.get("position")){case s:d=y+E;break;case n:v=b+E;break;case r:m=u+E;break;case i:g=a+E}}else e.set(h,0),e.set(p,0),e.set(f,t),e.set(l,o);this._drawing=!1;if(this._callLater){this._redraw();return}e&&(e.set(h,d),e.set(p,v)),c&&(c.set(h,m),c.set(p,g))}},{ATTRS:{legend:m}}),e.PieChart=v,e.ChartLegend=e.Base.create("chartlegend",e.Widget,[e.Renderer],{initializer:function(){this._items=[]},renderUI:function(){var t=this.get("boundingBox"),n=this.get("contentBox"),r=this.get("styles").background,i=new e.Rect({graphic:n,fill:r.fill,stroke:r.border});t.setStyle("display","block"),t.setStyle("position","absolute"),this.set("background",i)},bindUI:function(){this.get("chart").after("seriesCollectionChange",e.bind(this._updateHandler,this)),this.get("chart").after("stylesChange",e.bind(this._updateHandler,this)),this.after("stylesChange",this._updateHandler),this.after("positionChange",this._positionChangeHandler),this.after("widthChange",this._handleSizeChange),this.after("heightChange",this._handleSizeChange)},syncUI:function(){var e=this.get("width"),t=this.get("height");isFinite(e)&&isFinite(t)&&e>0&&t>0&&this._drawLegend()},_updateHandler:function(){this.get("rendered")&&this._drawLegend()},_positionChangeHandler:function(){var e=this.get("chart"),t=this._parentNode;t&&e&&this.get("includeInChartLayout")?this.fire("legendRendered"):this.get("rendered")&&this._drawLegend()},_handleSizeChange:function(e){var t=e.attrName,o=this.get(c),u=o===s||o===r,a=o===i||o===n;(a&&t===f||u&&t===l)&&this._drawLegend()},_drawLegend:function(){if(this._drawing){this._callLater=!0;return}this._drawing=!0,this._callLater=!1,this.get("includeInChartLayout")&&this.get("chart")._itemRenderQueue.unshift(this);var t=this.get("chart"),n=this.get("contentBox"),r=t.get("seriesCollection"),i,s=this.get("styles"),o=s.padding,u=s.item,a,f=u.hSpacing,l=u.vSpacing,c=this.get("direction"),h=c==="vertical"?s.vAlign:s.hAlign,p=s.marker,d=u.label,v,m=this._layout[c],g,y,b,w,E,S,x,T,N,C,k,L,A=[],O=p.width,M=p.height,_=0-f,D=0-l,P=0,H=0,B,j;p&&p.shape&&(w=p.shape),this._destroyLegendItems();if(t instanceof e.PieChart){i=r[0],v=i.get("categoryAxis").getDataByKey(i.get("categoryKey")),a=i.get("styles").marker,C=a.fill.colors,k=a.border.colors,L=a.border.weight,g=0,y=v.length,E=w||e.Circle,b=e.Lang.isArray(E);for(;g<y;++g)E=b?E[g]:E,T={color:C[g]},N={colors:k[g],weight:L},v=t.getSeriesItems(i,g).category.value,x=this._getLegendItem(n,this._getShapeClass(E),T,N,d,O,M,v),B=x.width,j=x.height,P=Math.max(P,B),H=Math.max(H,j),_+=B+f,D+=j+l,A.push(x)}else{g=0,y=r.length;for(;g<y;++g)i=r[g],a=this._getStylesBySeriesType(i,E),w||(E=a.shape,E||(E=e.Circle)),S=e.Lang.isArray(E)?E[g]:E,x=this._getLegendItem(n,this._getShapeClass(E),a.fill,a.border,d,O,M,i.get("valueDisplayName")),B=x.width,j=x.height,P=Math.max(P,B),H=Math.max(H,j),_+=B+f,D+=j+l,A.push(x)}this._drawing=!1,this._callLater?this._drawLegend():(m._positionLegendItems.apply(this,[A,P,H,_,D,o,f,l,h]),this._updateBackground(s),this.fire("legendRendered"))},_updateBackground:function(e){var t=e.background,n=this._contentRect,r=e.padding,i=n.left-r.left,s=n.top-r.top,o=n.right-i+r.right,u=n.bottom-s+r.bottom;this.get("background").set({fill:t.fill,stroke:t.border,width:o,height:u,x:i,y:s})},_getStylesBySeriesType:function(t){var n=t.get("styles"),r;return t instanceof e.LineSeries||t instanceof e.StackedLineSeries?(n=t.get("styles").line,r=n.color||t._getDefaultColor(t.get("graphOrder"),"line"),{border:{weight:1,color:r},fill:{color:r}}):t instanceof e.AreaSeries||t instanceof e.StackedAreaSeries?(n=t.get("styles").area,r=n.color||t._getDefaultColor(t.get("graphOrder"),"slice"),{border:{weight:1,color:r},fill:{color:r}}):(n=t.get("styles").marker,{fill:n.fill,border:{weight:n.border.weight,color:n.border.color,shape:n.shape},shape:n.shape})},_getLegendItem:function(t,n,r,i,s,o,u,a){var f=e.Node.create("<div>"),l=e.Node.create("<span>"),h,p,v,m,g,y=n;return f.setStyle(c,"absolute"),l.setStyle(c,"absolute"),l.setStyles(s),l.set("text",a),f.appendChild(l),t.append(f),p=l.get("offsetHeight"),v=p-u,m=o+v+2,l.setStyle("left",m+d),f.setStyle("height",p+d),f.setStyle("width",m+l.get("offsetWidth")+d),h=new y({fill:r,stroke:i,width:o,height:u,x:v*.5,y:v*.5,w:o,h:u,graphic:f}),l.setStyle("left",p+d),g={node:f,width:f.get("offsetWidth"),height:f.get("offsetHeight"),shape:h,textNode:l,text:a},this._items.push(g),g},_getShapeClass:function(){var e=this.get("background").get("graphic");return e._getShapeClass.apply(e,arguments)},_getDefaultStyles:function(){var e={padding:{top:8,right:8,bottom:8,left:9},gap:10,hAlign:"center",vAlign:"top",marker:this._getPlotDefaults(),item:{hSpacing:10,vSpacing:5,label:{color:"#808080",fontSize:"85%",whiteSpace:"nowrap"}},background:{shape:"rect",fill:{color:"#faf9f2"},border:{color:"#dad8c9",weight:1}}};return e},_getPlotDefaults:function(){var e={width:10,height:10};return e},_destroyLegendItems:function(){var e;if(this._items)while(this._items.length>0)e=this._items.shift(),e.shape.get("graphic").destroy(),e.node.empty(),e.node.destroy(!0),e.node=null,e=null;this._items=[]},_layout:{vertical:y,horizontal:g},destructor:function(){var e=this.get("background"),t;this._destroyLegendItems(),e&&(t=e.get("graphic"),t?t.destroy():e.destroy())}},{ATTRS:{includeInChartLayout:{value:!1},chart:{setter:function(t){return this.after("legendRendered",e.bind(t._itemRendered,t)),t}},direction:{value:"vertical"},position:{lazyAdd:!1,value:"right",setter:function(e){return e===n||e===i?this.set("direction",u):(e===s||e===r)&&this
.set("direction",a),e}},width:{getter:function(){var e=this.get("chart"),t=this._parentNode;return t?e&&this.get("includeInChartLayout")||this._width?(this._width||(this._width=0),this._width):t.get("offsetWidth"):""},setter:function(e){return this._width=e,e}},height:{valueFn:"_heightGetter",getter:function(){var e=this.get("chart"),t=this._parentNode;return t?e&&this.get("includeInChartLayout")||this._height?(this._height||(this._height=0),this._height):t.get("offsetHeight"):""},setter:function(e){return this._height=e,e}},x:{lazyAdd:!1,value:0,setter:function(e){var t=this.get("boundingBox");return t&&t.setStyle(s,e+d),e}},y:{lazyAdd:!1,value:0,setter:function(e){var t=this.get("boundingBox");return t&&t.setStyle(n,e+d),e}},items:{getter:function(){return this._items}},background:{}}})},"3.17.2",{requires:["charts-base"]});