UNPKG

@fusioncharts/core

Version:

JavaScript Data Visualisation Library

1 lines 15.3 kB
"use strict";exports.__esModule=true;exports.default=_default;var _lib=require("../../../lib");function _default(R){var win=window,userAgent=win.navigator.userAgent,UNDEF,isIE=/msie/i.test(userAgent)&&!win.opera,math=Math,mathMin=math.min,mathRound=math.round,toFloat=win.parseFloat,toStr=String,OBJECT="object",BLANK="",NONE="none",STROKE="stroke",TRACKER_FILL="rgba(192,192,192,"+(isIE?.002:1e-6)+")",buttonDisabledAttrs={enabled:false,false:false,0:false,disabled:true,true:true,1:true};R.define&&R.define([{name:"button",button:function button(_x,_y,_labelText,_symbolName,_options,_actualparent){var x=_x,y=_y,labelText=_labelText,symbolName=_symbolName,options=_options,actualparent=_actualparent,paper=this,parent=y,o=paper.group("button",parent),a,labelFill=x.labelFill,symbolFill=x.symbolFill,fill=x.fill,fontSize=x.button[5],fontFamily=x.button[6],hoverFill=x.hoverFill,stroke=x.stroke,symbolStroke=x["symbol-stroke"],strokeWidth=x["stroke-width"],symbolStrokeWidth=x["symbol-stroke-width"],config=x.config;if(typeof x==="object"&&x.button){var _x$button=x.button;x=_x$button[0];y=_x$button[1];labelText=_x$button[2];symbolName=_x$button[3];options=_x$button[4];parent=_x$button[5]}parent=parent||actualparent;o._.button={bound:paper.rect(o),tracker:paper.rect(o).attr({fill:TRACKER_FILL,stroke:TRACKER_FILL,cursor:"pointer"}).data("compositeButton",o)};!R.is(options,OBJECT)&&(options={});for(a in R.fn.button.fn){o[a]=R.fn.button.fn[a]}for(a in R.fn.button.ca){o.ca[a]=R.fn.button.ca[a]}config&&o.attr({config:config});return o.attr({"button-padding":[options.horizontalPadding,options.verticalPadding],"button-label":labelText,"button-label-size":fontSize,"button-label-family":fontFamily,"button-symbol":symbolName,"button-disabled":options.disabled||"false","button-symbol-position":options.symbolPosition,"button-symbol-padding":options.symbolPadding}).attr("button-repaint",[x,y,options.width,options.height,options.r]).attr({labelFill:labelFill,symbolFill:symbolFill,fill:fill,hoverFill:hoverFill,stroke:stroke,"symbol-stroke":symbolStroke,"stroke-width":strokeWidth,"stroke-linecap":"round","symbol-stroke-width":symbolStrokeWidth})},data:{hoverin:function hoverin(){var o=this,button=o._.button,callback=button.hoverbackIn,hover=o._hover||{};if(hover.fill||hover["fill-symbol"]||hover.stroke||hover["stroke-width"]||hover.cursor||hover.labelFill||hover["symbol-stroke"]){hover.fill&&o.bottom.attr("fill",hover.fill)&&!hover["fill-symbol"]&&button.symbol.attr("fill",hover.fill);hover["fill-symbol"]&&button.symbol.attr("fill",hover["fill-symbol"]);hover.stroke&&o.bottom.attr("stroke",hover.stroke)&&button.symbol.attr("stroke",hover.stroke);hover["stroke-width"]&&o.bottom.attr("stroke-width",hover["stroke-width"])&&button.symbol.attr("stroke-width",hover["stroke-width"]);hover.cursor&&button.tracker.attr("cursor",hover.cursor);hover.labelFill&&button.label&&button.label.attr("fill",hover.labelFill);hover["symbol-stroke"]&&button.symbol.attr("stroke",hover["symbol-stroke"]);callback&&callback()}else{callback&&callback(arguments)===false||o.attr("fill","hover")}o.hovered=true},hoverout:function hoverout(){var o=this,button=o._.button,callback=button.hoverbackOut,normal=o._normal||{};if(normal.fill||normal["fill-symbol"]||normal.stroke||normal["stroke-width"]||normal.cursor||normal.labelFill||normal["symbol-stroke"]){normal.fill&&o.bottom.attr("fill",normal.fill)&&!normal["fill-symbol"]&&button.symbol.attr("fill",normal.fill);normal.stroke&&o.bottom.attr("stroke",normal.stroke)&&button.symbol.attr("stroke",normal.stroke);normal["fill-symbol"]&&button.symbol.attr("fill",normal["fill-symbol"]);normal["stroke-width"]&&o.bottom.attr("stroke-width",normal["stroke-width"])&&button.symbol.attr("stroke-width",normal["stroke-width"]);normal["symbol-stroke"]&&button.symbol.attr("stroke",normal["symbol-stroke"]);normal.labelFill&&button.label&&button.label.attr("fill",normal.labelFill);normal.cursor&&button.tracker.attr("cursor",normal.cursor);callback&&callback()}else{callback&&callback(arguments)===false||o.attr("fill",(o.pressed||o.active)&&"active"||"normal")}o.hovered=false},mousedown:function mousedown(){var o=this,button=o._.button,pressed=o._pressed||{};if(pressed.fill||pressed["fill-symbol"]||pressed.stroke||pressed["stroke-width"]||pressed.cursor||pressed.labelFill||pressed["symbol-stroke"]){pressed.fill&&o.bottom.attr("fill",pressed.fill)&&!pressed["fill-symbol"]&&button.symbol.attr("fill",pressed.fill);pressed.stroke&&o.bottom.attr("stroke",pressed.stroke)&&button.symbol.attr("stroke",pressed.stroke);pressed["fill-symbol"]&&button.symbol.attr("fill",pressed["fill-symbol"]);pressed["stroke-width"]&&o.bottom.attr("stroke-width",pressed["stroke-width"])&&button.symbol.attr("stroke-width",pressed["stroke-width"]);pressed.labelFill&&button.label&&button.label.attr("fill",pressed.labelFill);pressed["symbol-stroke"]&&button.symbol.attr("stroke",pressed["symbol-stroke"]);pressed.cursor&&button.tracker.attr("cursor",pressed.cursor)}else{o.attr("fill","active")}o.pressed=true},mouseup:function mouseup(){var o=this,button=o._.button,callback=button.callback,normal=o._normal||{};if(normal.fill||normal["fill-symbol"]||normal.stroke||normal["stroke-width"]||normal.cursor||normal.labelFill||normal["symbol-stroke"]){normal.fill&&o.bottom.attr("fill",normal.fill)&&!normal["fill-symbol"]&&button.symbol.attr("fill",normal.fill);normal.stroke&&o.bottom.attr("stroke",normal.stroke)&&button.symbol.attr("stroke",normal.stroke);normal["fill-symbol"]&&button.symbol.attr("fill",normal["fill-symbol"]);normal["stroke-width"]&&o.bottom.attr("stroke-width",normal["stroke-width"])&&button.symbol.attr("stroke-width",normal["stroke-width"]);normal.labelFill&&button.label&&button.label.attr("fill",normal.labelFill);normal["symbol-stroke"]&&button.symbol.attr("stroke",normal["symbol-stroke"]);normal.cursor&&button.tracker.attr("cursor",normal.cursor)}else{o.attr("fill",o.hovered&&"hover"||o.active&&"active"||"normal")}o.pressed=false;callback&&callback(arguments)},mousemove:function mousemove(){var o=this,button=o._.button,callback=button.mousemove;callback&&callback(arguments)}},fn:{tooltip:function tooltip(){R.el.tooltip&&R.el.tooltip.apply(this._.button.tracker,arguments);return this},buttonclick:function buttonclick(callback,_scope){var scope=_scope,o=this,button=o._.button;scope=scope||o;button.callback=function(){return callback.apply(scope,arguments)};return o},labelcss:function labelcss(){var button=this._.button,label=button.label;button.cssArg=arguments;label&&label.css.apply(label,arguments);return this.attr("button-repaint",this.attrs["button-repaint"])},buttonhover:function buttonhover(callbackIn,callbackOut,_scopeIn,_scopeOut,callbackMove,_scopeMove){var o=this,button=o._.button,scopeIn=_scopeIn||o,scopeOut=_scopeOut||o,scopeMove=_scopeMove||o;callbackMove&&(button.mousemove=function(){return callbackMove.apply(scopeMove,arguments)});button.hoverbackIn=function(){return callbackIn.apply(scopeIn,arguments)};button.hoverbackOut=function(){return callbackOut.apply(scopeOut,arguments)};return o},remove:function remove(){var o=this,button=o._.button,key;o.attr("button-disabled","true");for(key in button){button[key]&&button[key].remove&&button[key].remove();button[key]=null}delete o._.button;R.el.remove.apply(o,arguments)}},ca:{"button-active":function buttonActive(value){var o=this;o.attr("fill",(o.active=!!value)?"active":o.hovered&&"hover"||"normal")},"button-disabled":function buttonDisabled(_value){var o=this,value=_value,paper=o.paper,button=o._.button,tracker=button.tracker,attr=o.attrs["button-disabled"],events=paper.button.data,disabled=o._disabled||{};value=buttonDisabledAttrs[value];attr=buttonDisabledAttrs[attr];if(value===UNDEF||value===attr){return}switch(value){case true:if(disabled.fill||disabled.stroke||disabled["stroke-width"]||disabled.cursor){disabled.fill&&o.bottom.attr("fill",disabled.fill)&&button.symbol.attr("fill",disabled.fill);disabled.stroke&&o.bottom.attr("stroke",disabled.stroke)&&button.symbol.attr("stroke",disabled.stroke);disabled["stroke-width"]&&o.bottom.attr("stroke-width",disabled["stroke-width"]&&button.symbol.attr("fill",disabled.fill));disabled.cursor&&button.tracker.attr("cursor",disabled.cursor)}else{tracker.attr("fill","rgba(204,204,205,.5)")}tracker.off("fc-mousedown",events.mousedown).off("fc-unmouseup",events.mouseup).unhover(events.hoverin,events.hoverout).unmousemove(events.mousemove);break;case false:tracker.attr("fill",TRACKER_FILL).on("fc-mousedown",events.mousedown,o).on("fc-mouseup",events.mouseup,o).hover(events.hoverin,events.hoverout,o,o).mousemove(events.mousemove,o);break}},"button-label":function buttonLabel(_text){var o=this,button=o._.button,attrs=o.attrs,text=_text,label=button.label,cssArg=button.cssArg,repaint=o.attrs["button-repaint"];text=toStr(text||BLANK);if(text===NONE){label&&(button.label=label.remove())}else if(text){!label&&(label=button.label=o.paper.text(o).insertBefore(button.tracker));label.attr({text:text,"text-anchor":"middle","vertical-align":"middle"});cssArg&&cssArg.length&&label.css.apply(label,cssArg)}if(repaint&&attrs["button-label"]!==text){o.attr("button-repaint",repaint)}},"button-label-size":function buttonLabelSize(size){var o=this,button=o._.button,attrs=o.attrs,label=button.label,repaint=o.attrs["button-label-size"];label&&label.attr({"font-size":size});if(repaint&&attrs["button-label-size"]!==size){o.attr("button-label-size",repaint)}},"button-label-family":function buttonLabelFamily(_family){var o=this,button=o._.button,attrs=o.attrs,family=_family,label=button.label,repaint=o.attrs["button-label-family"];if(!label){return}if(family===UNDEF){family="sans-serif"}label.attr({"font-family":family});if(repaint&&attrs["button-label-family"]!==family){o.attr("button-label-family",repaint)}},"button-symbol":function buttonSymbol(_name){var o=this,button=o._.button,name=_name,symbol=button.symbol,repaint=o.attrs["button-repaint"];name=toStr(name||BLANK);if(name===NONE){symbol&&(button.symbol=symbol.remove());delete button.symbol}else if(name&&!symbol){symbol=button.symbol=o.paper.symbol(o).insertAfter(button.bound)}if(repaint){o.attr("button-repaint",repaint)}},"button-symbol-position":function buttonSymbolPosition(position){return{"button-symbol-position":{top:"top",right:"right",bottom:"bottom",left:"left",none:"none"}[toStr(position).toLowerCase()]||NONE}},"button-symbol-padding":function buttonSymbolPadding(value){return{"button-symbol-padding":toFloat(value)}},"button-padding":function buttonPadding(_px,_py){var px=_px,py=_py;return{"button-padding":[(px===null||px===UNDEF)&&(px=5)||toFloat(px),(py===null||py===UNDEF)&&px||toFloat(py)]}},"button-repaint":function buttonRepaint(_x,_y,_w,_h,_r){var o=this,button=o._.button,x=_x,y=_y,w=_w,h=_h,r=_r,bound=button.bound,label=button.label,symbol=button.symbol,attrs=o.attrs,attrPads=attrs["button-padding"],padX=attrPads[0],padY=attrPads[1],symX,symY,symD,symR,padSym,bbox,obj;x===UNDEF&&(x=0);y===UNDEF&&(y=0);if(w===UNDEF||h===UNDEF){bbox=label&&label.getBBox()||{width:0,height:0};w===UNDEF&&(w=padX*2+bbox.width);h===UNDEF&&(h=padY*2+bbox.height)}obj=R.crispBound(x,y,w,h,bound.attr("stroke-width"));obj.r=r=(0,_lib.pluck)(r,mathRound(mathMin(h,w)*.1));x=obj.x;y=obj.y;w=obj.width;h=obj.height;label&&label.attr({x:x+w/2,y:y+h/2});if(symbol){!R.is(padSym=attrs["button-symbol-padding"],"finite")&&(padSym=h*.2);symD=h-padY;symR=symD*.5;switch(attrs["button-symbol-position"]+(label&&"+"||"-")){case"right+":w+=symR*2+padY;symX=x+w-symR-padX;symY=y+h*.5;label.attr("transform",["t",-(symD+padSym),0]);break;case"left+":w+=symR*2+padY;symX=x+padX+symR;symY=y+h*.5;label.attr("transform",["t",symD+padSym,0]);break;case"top+":h+=symR*2+padSym;symX=x+w*.5;symY=y+attrPads[1]+symR;label.attr("transform",["t",0,symD+padSym]);break;case"bottom+":h+=symR*2+padSym;symX=x+w*.5;symY=y+h-padY-symR;label.attr("transform",["t",0,-(symD+padSym)]);break;default:symX=x+w*.5;symY=y+h*.5}symbol.attr("symbol",[attrs["button-symbol"],symX,symY,symR,w,h])}button.bound.attr(obj);button.tracker.attr(obj)},fill:function fill(_color,disableGradient){if(disableGradient===void 0){disableGradient=true}var o=this,button=o._.button,bound=button.bound,color=_color,state={normal:button.gradient,active:button.gradientActive,hover:button.gradientHover}[color];if(!state){if(!disableGradient){color=R.getRGB(color);color.error&&(color=R.color("#cccccc"));color="opacity"in color?"rgba("+[color.r,color.g,color.b,color.opacity]+")":"rgb("+[color.r,color.g,color.b]+")"}button.gradient=disableGradient?color:[90,R.tintshade(color,-.8).rgba+":0",R.tintshade(color,.8).rgba+":100"].join("-");button.gradientActive=[270,R.tintshade(color,-.8).rgba+":0",R.tintshade(color,.8).rgba+":100"].join("-");state=(o.pressed||o.active)&&button.gradientActive||o.hovered&&button.gradienthover||button.gradient}bound.attr("fill",state);return false},hoverFill:function hoverFill(_hover){var o=this,button=o._.button,hover=_hover;hover=R.getRGB(hover);hover="opacity"in hover?"rgba("+[hover.r,hover.g,hover.b,hover.opacity]+")":"rgb("+[hover.r,hover.g,hover.b]+")";button.gradientHover=hover;return false},labelFill:function labelFill(color){var o=this,button=o._.button,label=button.label;if(label&&color){button.labelFill=color;label.attr("fill",color)}return false},symbolFill:function symbolFill(color){var o=this,button=o._.button,symbol=button.symbol;if(symbol&&color){button.symbolFill=color;symbol.attr("fill",color)}return false},stroke:function stroke(_color){var button=this._.button,color=_color;color=R.color(color);color.error&&(color=R.color("#999999"));button.bound.attr(STROKE,color);return false},"symbol-stroke":function symbolStroke(stroke){var button=this._.button,symbol=button.symbol;symbol&&stroke&&symbol.attr(STROKE,stroke);return false},"stroke-width":function strokeWidth(value){var button=this._.button;button.bound.attr("stroke-width",value);button.tracker.attr("stroke-width",value);return false},"symbol-stroke-width":function symbolStrokeWidth(value){var button=this._.button,symbol=button.symbol;symbol&&value&&symbol.attr("stroke-width",value);return false},config:function config(obj){var o=this;obj.hover&&(o._hover={fill:obj.hover.fill,stroke:obj.hover.stroke,"stroke-width":obj.hover["stroke-width"],cursor:obj.hover.cursor,"fill-symbol":obj.hover["fill-symbol"],"symbol-stroke":obj.hover["symbol-stroke"],labelFill:obj.hover.labelFill});obj.disabled&&(o._disabled={fill:obj.disabled.fill,stroke:obj.disabled.stroke,"stroke-width":obj.disabled["stroke-width"],"symbol-stroke":obj.disabled["symbol-stroke"],cursor:obj.disabled.cursor,labelFill:obj.disabled.labelFill});obj.pressed&&(o._pressed={fill:obj.pressed.fill,stroke:obj.pressed.stroke,"stroke-width":obj.pressed["stroke-width"],cursor:obj.pressed.cursor,"fill-symbol":obj.pressed["fill-symbol"],"symbol-stroke":obj.pressed["symbol-stroke"],labelFill:obj.pressed.labelFill});obj.normal&&(o._normal={fill:obj.normal.fill,stroke:obj.normal.stroke,"stroke-width":obj.normal["stroke-width"],cursor:obj.normal.cursor,"fill-symbol":obj.normal["fill-symbol"],"symbol-stroke":obj.normal["symbol-stroke"],labelFill:obj.normal.labelFill});obj.symbol&&(obj.symbol={stroke:obj.normal.stroke,"stroke-width":obj.normal["stroke-width"]})}}}])}