批量改观图片尺寸的photoshop,javascript使用smiple

小编:xiexienile来源:卡其色理想用于批量改成展开的图形的尺码的photoshop 脚本 (javascript)。用法: 把解压出来的 改变尺寸.jsx 文件复制到 ps安装目录预置本子 下,重新张开ps今后就可以在~[菜单- 文件-脚本] 里面找到 改换尺寸大概解压出来,在开着ps的气象下,直接双击也能够用。功效介绍:1. 足以把当前文书档案(包括未保存过的)直接修改尺寸并保存为jpg。(注意会停业当前文书档案!)2. 得以本着任何文件夹进行操作。(程序设定为不包罗掩盖文件,由此不想管理和不能够管理的公文能够先安装为[隐藏]本性)3. 可挑选另存jpg 、gif、psd、tiff至另贰个文书夹。4. 另存时支持文件名左右增加字符。5. 管理进度条,在大批量文件管理的时候对进程精通越来越好。(7月2日更正了藏匿文件导致进程条不准的bug)6. 更换了改观尺寸的算法,允许对不须要调整的尺码留空(小于1或不填写即为留空,留空值将依靠选项 不变还是等比总计)7. 水印增加效果—可以平铺或加多独个的水印;并得以行使ps众多的图层混合方式。8. 校订了1.2版本保存gif 格式时颜色位数错误的bug 。要是有对象问:想要半透明水印咋做?想要倾斜水印怎么做?答:把水印文件做成半晶莹剔透(保存为png可能psd 之类)和倾斜的就可以,脚本分界面就不另外放置参数了。分界面图示:

javascript使用smipleChart完成轻易图表,javascriptchart

支持 线性图 区域图 柱状图 饼图

补助多浏览器

用到的是svg  vml

复制代码 代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ";
<html xmlns=";
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>smipleChart</title>
<style type="text/css">
.cc{
height:450px; width:800px; border:1px solid #999; position:relative; margin:20px;
}
</style>
</head>
<body>
<div id='t'></div>
<div id='t1'></div>
<div id='line' class="cc"></div>
<div id='area' class="cc"></div>
<div id='zhu' class="cc"></div>
<div id='zhu1' class="cc" style="height:600px;"></div>
<div id='segmentx' class="cc"></div>
<div id='segmenty' class="cc"></div>
<div id='pie' class="cc"></div>
<div id='pies' class="cc"></div>
<div id='vv' class="cc" style='height:300px; width:520px;'></div>
<script type="text/javascript">
(function(doc,undefined){
 var win       = this,
  uuuid     = -1, 
  hasSVG    = win.SVGAngle || doc.implementation.hasFeature("", "1.1"),
  isIE      = /msie/i.test(navigator.userAgent) && !win.opera,
  path      = hasSVG?'d':'path',
  seal      = hasSVG?'z':'e',
  math      = Math,
  mathRound = math.round,
  mathFloor = math.floor,
  mathCeil  = math.ceil,
  mathMax   = math.max,
  mathMin   = math.min,
  mathAbs   = math.abs,
  mathCos   = math.cos,
  mathSin   = math.sin,    
  M         = 'M',
  L         = 'L';
 win.$$ = function(Id){
  return document.getElementById(Id);
 };
 win.extend = function(){
  var target = arguments[0] || {}, i = 1, length = arguments.length, deep = true, options;
  if ( typeof target === "boolean" ) {
   deep = target;
   target = arguments[1] || {};
   i = 2;
  }
  if ( typeof target !== "object" && Object.prototype.toString.call(target)!="[object Function]")
   target = {};
  for(;i<length;i++){
   if ( (options = arguments[ i ]) != null )
    for(var name in options){
     var src = target[ name ], copy = options[ name ];
     if ( target === copy )
      continue;
     if ( deep && copy && typeof copy === "object" && !copy.nodeType ){
      target[ name ] = arguments.callee( deep, src || ( copy.length != null ? [ ] : { } ), copy );
     }  
     else if(copy !== undefined)
      target[ name ] = copy;                      
    }
 
  }
  return target;          
 };
 
 win.each =  function ( object, callback, args ) { 
  var name, i = 0, length = object.length; 
  if ( args ) {
   args = Array.prototype.slice.call(arguments).slice(2);
   if ( length === undefined ) { 
    for ( name in object ) 
     if ( callback.apply( object[ name ],[name,object[ name ]].concat(args) ) === false ) 
      break; 
   } else
    for ( ; i < length; i++) 
     if ( callback.apply( object[ i ],[i,object[ i ]].concat(args)) === false )   //
      break; 
  } else {    
   if ( length === undefined ) { 
    for ( name in object ) 
     if ( callback.call( object[ name ], name, object[ name ] ) === false ) 
      break; 
   } else
    for ( var value = object[0]; 
     i < length && callback.call( value, i, value ) !== false; value = object[++i] ){} 
  } 
  return object; 
 };
 
 win.contains = function(p,c){
  if(!p||!c)return false;
  if(p===c)return true;
  return isIE
   ? p.contains(c)
   : p.compareDocumentPosition(c)==20
    ? true
    : false;
 };
//---------------------------------------------------------------
 function processPoint( x ){
  return isIE ? x.toFixed(0) : ~~x.toFixed(0) + 0.5;
 };
 function calTextLen(txt, cssStr){
  var span = doc.createElement('span');
  if(cssStr){
   typeof cssStr === 'string'
    ? span.style.cssText = cssStr
    : extend(span.style,cssStr);
  }else{
   extend(span.style,{
    fontSiz    : '12px',
    fontFamily : '"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif'    
   });
  }
  span.innerHTML = txt || ''; 
  span.style.visibility = 'hidden';
  doc.body.appendChild(span);  
  var width  = span.offsetWidth,
   height = span.offsetHeight;
  doc.body.removeChild(span);
  return {w:width,h:height};
 };
 function angle(r,center,o,jingdu){
  var hudu = Math.PI*2*(o/360),
   x = center[0]+ r*Math.sin(hudu),
   y = center[1]+ -r*Math.cos(hudu);
  return [x.toFixed(jingdu||0),y.toFixed(jingdu||0)];  
 }
 function xx(a,b,lineNum){
  var t   = 1000,
   stf = ((b*t-a*t)/lineNum)/t,
   arr = [1,2,2.5,5,10],
   c   = 1,
   v;
//    分水岭的基数是 [1,2,2.5,5,10] 那么些手续是寻觅 间隔 属于哪个范围
  if(stf<arr[0]){
   while( stf<arr[0] ){
    c = c*10;
    arr[0]=arr[0]/c; 
   }
   each([1,2,2.5,5,10],function(i,o){
    arr[i]= o/c;
   });
  }else if(stf>arr[4]){
   while( stf>arr[4] ){
    c = c*10;
    arr[4] = arr[4]*c;
   }
   each([1,2,2.5,5,10],function(i,o){
   arr[i]= o*c;
   });
  }
 
//上边找到间隔后 找到间隔中最相近的二个 
  each(arr,function(i,o){
   if(stf<=o){
    v = o;
    return false;
   }
  });
  var bj  = (mathAbs(a)*t)/(v*t),
   ba  = 0,
   isZ = bj!==parseInt(bj);
  isZ
   &&a>0
    ? ba = -a%v*t
    : ba = (mathAbs(a)%v-v)*t;  
  
  
  a = (a*t+ba)/t;
  b = (b*t+(b%v===0?0:(v-b%v))*t)/t;
  
  //看看还剩几条线没有画
  var num = Math.max(0,lineNum - Math.round((b-a)/v));
  if(a>=0){
  
  //坐标相比较整数化 
   if(a!=0&&num!=0&&a%10!==0){
    while(a!=0&&num!=0){
     a = (a*t-v*t)/t;
     num--;
     if((a*t-v*num*t)/10000>0&&a%10===0)
     break;
    }
   }
   
   if(num!=0){
    while(num!==0){
    b = (b*t+v*t)/t
    num--;
    }
   }    
  
  }else{
   //坐标相比整数化 
   if(b<0&&num!=0){
    while(b!=0&&num!=0&&b%10!==0){
     b = (b*t+v*t)/t;
     num--;
     if((b*t+v*num*t)/t<0&&b%10===0)
     break;
    }
   }
   if(num!=0){
    while(num!==0){
     a = (a*t-v*t)/t
     num--;
    }
   }    
  }
  return {min:a,max:b,stf:v};
 } 
//---------------------------------------------------------------------------------------------------------------
//对svg vml成分的局地创办 修改属性 样式 删除 ==  一些的操作
 win.vector = function(){};
 vector.prototype = {
  $c : function(graphic,nodeName){
   this.element = this[0] = doc.createElementNS('', nodeName);   
   this.graphic = graphic;
   return this;
  },
  attr: function(hash,val){
   var elem    = this.element,
    key,
    value;
   if(typeof hash === 'string'){
    if(val === undefined){
     return elem.getAttribute(hash);
    }else{
     elem.setAttribute(hash, val);
     return this;
    }
   } else {
    for(key in hash){
     value = hash[key];
     if(key === path){
      value && value.join
       &&(value = value.join(' '));
      /(NaN|  |^$)/.test(value)
       &&(value = 'M 0 0');
     }
     elem.setAttribute(key, value)  
    }
   }
   return this;
  },
  css:  function(hash){
   for(var key in hash){
    isIE && key == "opacity"
     ? this[0].style['filter'] = "alpha(opacity="+ hash[key] * 100+")"
     : this[0].style[key] = hash[key];
   }
   return this;
  },
  on: function(eventName, handler){
   var self = this;
   /*this.element.addEventListener(eventName,function(){
    handler.call(self)
   },false);*/
   this.element['on' + eventName] = function(e){
    e = e || win.event;
    handler.call(self,e);
   }   
   return this;
  },
  appendTo: function(parent){
   if(parent){
    parent.element
     ? parent.element.appendChild(this.element)
     : parent.appendChild(this.element)
    
   } else {
    this.graphic.container.appendChild(this.element);
   }
   return this;
  },
  addText: function(str){
   var elem = this.element;
   if(elem.nodeName === 'text'){
    elem.appendChild(doc.createTextNode(str+''));
   }
   return this;
  },
  setOpacity : function(v){
   this.attr('fill-opacity',v);
   return this;
  },
  setSize : function(v){
   this[0].nodeName==='circle'
    ? this.attr('r',4+(v===0?0:2))
    : this.attr({'stroke-width':v});
   return this;
  },
  toFront: function() {
   this[0].parentNode.appendChild(this[0]);
   return this;
  },  
  show: function(){
   this[0].style.display = 'block';
   return this;
  },
  hide: function(){
   this[0].style.display = 'none';
   return this;    
  },
  destroy : function(){
   //销毁节点......................
   var node = this[0] || this;
   node.onmouseover = node.onmouseout = node.onclick = null;
   node.parentNode
    &&node.parentNode.removeChild(node);
   return this;
  }
 };
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
//即便是vml修改个中的部分艺术 
 if(!hasSVG){
//-------------创建vml环境----------------- 
  doc.createStyleSheet().addRule(".vml", "behavior:url(#default#VML);display:inline-block;position:absolute;left:0px;top:0px");
  !doc.namespaces.vml && !+"v1";
  doc.namespaces.add("vml", "urn:schemas-microsoft-com:vml");  
  
//-------------修改部分办法-----------------
  extend(vector.prototype,{
   $c : function(graphic,nodeName){
    var name = nodeName || 'shape'; 
    this.element= this[0] = (name === 'div' || name === 'span')
     ? doc.createElement(name)
     : doc.createElement('<vml:'+name+' class="vml">'); 
    this.graphic = graphic;
    return this;  
   },
   /*on : function(eventName, handler){
    var self = this;
    this.element.attachEvent("on" + eventName,function(){
     handler.call(self);
    });
    return this;
   },*/
   addText : function(txt){
    this[0].innerHTML = txt || '';
    return this;
   },
   setSize : function(v){
    this[0].strokeWeight = v;
    return this;
   },   
   setOpacity : function(v){
    this.opacity.opacity=v;
    return this;
   }  
  });
 }
//---------------------------------------------------------------------------------------------------
//画图类
//------------------------------------------------------------
 win.smipleChart = function(){
  this.init.apply(this,arguments);
 };
 smipleChart.list      = [];
 smipleChart.timer     = null;
 smipleChart.lazyLoad  = function(id){
  id  = id || '0'
  smipleChart.list[id]
   &&smipleChart.list[id].loadMe();
 };
 smipleChart.prototype = {
  options : {
   charts : {
    paddingRight : 20,
    radius : 200,
    style  : {
     fontFamily : '"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif',
     fontSize   : '12px',
     background : '#FFFFFF'
    }
   },
   title : {
    text  : '',
    y     : 10,
    style : {
     fontFamily:'Verdana,Arial,Helvetica,sans-serif',
     fontSize:'16px',
     fontWeight:'bold'
    }
   },
   subTitle : {
    text : '',
    y  : 30,
    style   : {
     fontFamily:'Verdana,Arial,Helvetica,sans-serif',
     fontSize:'12px',     
     color: '#111'   
    }
   },
   yUnit : {
    text  : '',
    style : {
     fontFamily:'Verdana,Arial,Helvetica,sans-serif',
     fontSize:'12px',      
     color: '#111'
    },
    lineNum :10
   }
  },
  init : function(container,options){
   clearTimeout(smipleChart.timer)
   var self      = this;
   this.width    = container.offsetWidth;
   this.height   = container.offsetHeight;
   this.currList = {};
   this.uuuid    = ++uuuid;
   this.timer    = null;
   //首要画图组的会集 格局
   //{id : {dom:xx,show:true}}
   this.mainGroup = {};
   //分段的时候要用到的  知道什么样是遮盖了的  因为要涉及到重绘
   this.hideList  = {};
   
   //svg 里面画图 必需有三个svg标签 vml就用div了
   this.container = hasSVG
    ? new vector().$c(1,'svg')
     .attr({
      xmlns   : '',
      version : '1.1',
      width : this.width,
      height : this.height
      
     })
     .css({fontSize : '12px'})
     .appendTo(container)
    : new vector().$c(1,'div')
     .css({
      fontSize : '12px',
      width    : this.width +'px',
      height   : this.height+'px'
     })
     .appendTo(container);
     
   this.loading = container.appendChild(doc.createElement('img'));
   this.loading.setAttribute('src','');
   this.loading.style.position = 'absolute';
   this.loading.style.top  = container.offsetHeight/2- this.loading.offsetHeight/2+'px';
   this.loading.style.left = container.offsetWidth/2- this.loading.offsetWidth/2+'px';
  
   var c     = extend(true,{},this.options),
    opts  = this.opts = extend(true,c,options),
    style = extend(opts.charts.style,{
     width  : this.width,
     height : this.height
    });
   
   smipleChart.list[this.uuuid] = this; 
   
   smipleChart.timer = setTimeout(function(){
    smipleChart.lazyLoad();
   },200);
      
  },
  loadMe : function(){
   var opts  = this.opts,
    self  = this,
    type  = opts.charts.type;
   this.container = this.container
    .on('mouseout',function(e){
     var elem = e.relatedTarget || e.toElement;
     if(!contains(this[0],elem)){
      self.hideTooltip();
      self.currList.dot
       &&self.currList.dot.setSize(0);
      self.currList.line
       &&self.currList.line.setSize(1.5);
      self.currList = {}; 
     }
    })
    .css({display:'none'})[0];
    
        
   //总括绘画盘子的时候须要的一些参数
   this.getDrawArea()
    .createTooltip()         //创设提示音讯的局面
    .drawTitle()             //画标题
                //画盘子
    
   'line,area,pie'.indexOf(type)>=0
    &&(opts.charts.panel = 'x');
   
   
   ' pie,pies'.indexOf(type)<0
    &&this.drawPanel();
   
     
   this.drawLegend(opts.legend.type);  //画色块条
   var type = {
    line    : 'drawLine',
    area    : 'drawArea',
    columns : 'drawColumns',
    pie     : 'drawPie',
    pies    : 'drawPies',
    segment : 'drawSegment'
   }[opts.charts.type];
   //开端画图..............
   this[type]();
   
   //删除节点
   this.loading.parentNode.removeChild(this.loading);
   //断开援引
   this.loading = null;
   
   this.container.style.display = '';
   setTimeout(function(){
    smipleChart.lazyLoad((++self.uuuid)+'');
   },10)
   
  },
  createElement : function(nodeName){
   return new vector().$c(this,nodeName);
  },
  group: function(name){
   return this.createElement(hasSVG?'g':'div').attr('mark',name);
  },
  getDrawArea : function(){
   var opts     = this.opts,
    width    = this.width,
    height   = this.height,
    title    = opts.title,
    subTitle = opts.subTitle,
    area     = {
     // 去掉坐标轴左侧的刻度文本宽度(预估) 80为定值 左侧只留80的间隔
     areaWidth  : width - 80, 
     // 去掉坐标轴底下的文件和标线的中度
     areaHeight : height - 40,
     //原点的X地点  下边会一个钱打二十七个结到
     startX : 0,
     //原点的Y地点  上面会图谋到
     startY : 0,
     //大旨的x坐标 画饼图的时候须要精通圆心的职位
     centerX: 0,
     //中央的y坐标 画饼图的时候需求通晓圆心的职责
     centerY: 0
    };
   //借使主标题存在 减去主题指标惊人 不然 减去10的高
   area.areaHeight -=(title.text !== '')
    ? title.y
    : 10;
    
   // 去掉副标题中度
   area.areaHeight -=(subTitle.text !== '')
    ? subTitle.y
    : 10
   
   area.startX = 80;
   area.startY = height - 40;
   
   //圆心的职分
   area.centerX = width / 2;
   area.centerY = height / 2;  
   
   //左侧留部分空隙
   area.areaWidth -=20;
   //上面也留部分区间
   area.areaHeight -=15;
   
   opts.area = area;   
   
   return this;
  },
  drawTitle : function(){   
   var opts   = this.opts,
    self   = this,
    arr    = [opts.title,opts.subTitle,opts.yUnit],
    //3个标题坐标的地点的基本参数
    config = [
     {
      x : this.width / 2,
      y : opts.title.y
     },
     {
      x : this.width / 2,
      y : opts.subTitle.y      
     },
     {
      x : opts.yUnit.x,
      y : this.height / 2 - 20      
     }      
    ],
    tpanel = this.group('title')
     .appendTo();
   each(arr,function(i,title){
    var text = title.text;
    if(text){
     var elem = self.baseDraw.span(self,{
       'text-anchor':'left',
       x : mathMax(config[i].x - calTextLen(text,title.style).w/2,10),
       y : config[i].y
      },calTextLen(title.text,title.style).h)
      .css(title.style)
      .addText(text)
      .appendTo(tpanel);
     
     //借使为2的时候 就印证是副标题  将它竖过来
     if(i===2){
      hasSVG
       ? elem.attr({transform : 'rotate(270, '+(opts.yUnit.x+10)+', ' + self.height / 2 + ')'})
       : (elem.element.style.filter ='progid:DXImageTransform.Microsoft.BasicImage(rotation=3)')      
     }
    } 
   }); 
   return this;
  },
//画盘子  相比劳碌
  drawPanel : function(type){
   var opts = this.opts,
    self = this,
    area = opts.area,
    chartsType = opts.charts.type,
    isSegment  = chartsType === 'segment',
    //盘子的品种 是股价整理子 如故纵盘子
    type = opts.charts.panel || 'x';
   // 底板
   var drawAreaWidth  = area.areaWidth,
    drawAreaHeight = area.areaHeight,
    //原点的坐标
    startX = area.startX,
    startY = area.startY;
   var allData  = [],
    minValue = 0,
    maxValue = 10,
    //线的条数 只好在1到10以内
    lineNum  = mathMin(10,mathMax(opts.yUnit.lineNum,1)),
    staff;
   
   //组合全部的数量
   each(opts.chartData,function(i,o){
    // 如若是柱状图 是对具备的数码求和
    isSegment
     ? each(o.data,function(j,d){
      allData[j]
       ? allData[j] = allData[j] + (
d)
       : allData[j] = d;
     })
     : allData = allData.concat(o.data)
   });
   
   //给具有的多寡排序  为了上边求最大值 最小值
   allData.sort(function(a,b){return a-b});
   
   //求出最大值 最小值
   maxValue = allData[allData.length - 1];
   
   each(allData,function(i,o){
    if(o!==null){
     minValue = o;
     return false;
    }    
   });    
       
   //主盘子容器
   var panel = this.group('panel').appendTo();
  
   var result = xx(minValue,maxValue,lineNum),
    min    = result.min,
    max    = result.max,
    f      = result.stf;
   isSegment
    &&(min = 0);   
   //表示画的是横坐标 或许是双坐标
   if(type.toLowerCase()==='x'){
    //横坐标单位距离
    var xPices = drawAreaWidth / opts.xUnit.units.length,
     //单位距离的中央点
     offset = xPices / 2,
     
     yPices = drawAreaHeight / lineNum;
   
 //--------------------------------画横向的点和文字---------------------------------------------------------
    var y = hasSVG?5:10,
     t = 1000,
     span;   
    each(opts.xUnit.units,function(i,d){       
     self.baseDraw.path(self,{
      border      : 1,
      borderColor : '#C0C0C0',
      isfill      : false,
      path        : [
       M,
       processPoint(startX + (i * xPices)),
       processPoint(startY),
       L,
       processPoint(startX + (i*xPices)),
       processPoint(startY + 5)
      ]
     }).
     appendTo(panel);
    
     span = self.baseDraw.span(self,{
       x   : startX + offset + (i * xPices),
       y   : startY+y,
       'text-anchor':'middle'
      })
      .css({
        fontFamily : 'Verdana,Arial,Helvetica,sans-serif',
        fontSize   : '12px'
      })
      .addText(opts.xUnit.units[i])
      .appendTo(panel)[0];
     
     !hasSVG
      &&(span.style.left = parseInt(span.style.left) - span.offsetWidth/2+'px');
      
    });
//--------------------------------画纵向的点和文字-----------------------------------------------------------------------    
    for(i=0;i<=lineNum;i++){
     self.baseDraw.path(self,{
      border      : 1,
      borderColor : '#C0C0C0',
      isfill      : false,
      path        : [M, startX, processPoint(startY - (i * yPices)), L, processPoint(startX + drawAreaWidth), processPoint(startY - (i *yPices))]
     })
     .css({zIndex:-10})   
     .appendTo(panel);
     
     var span = self.baseDraw.span(self,{
      x : startX - 15,
      y : startY - i * yPices-calTextLen(min+i*f+'').h/2,
      'text-anchor':'middle'
     })
     .css({
       'font-family' : 'Verdana,Arial,Helvetica,sans-serif',
       'font-size'   : '12px',
       width         : '40px',
       display       : 'block',
       textAlign     : 'right'
     })
     .addText((min*t+(i*t*f/t)*t)/t+'')
     .appendTo(panel)[0];
     if(!hasSVG){
      span.style.top  = parseInt(span.style.top) + span.offsetHeight/2 -5+'px';
      span.style.left = parseInt(span.style.left) -35+'px'
     }     
    }    
    
   }else{
    //横坐标单位距离
    var yPices = drawAreaHeight / (opts.xUnit.units.length),
     //单位距离的中央点
     offset = Math.round(yPices / 2),
     x      = hasSVG ? 25 : 70,
     y     = hasSVG ? 0 : 5,
     span
    
    each(opts.xUnit.units,function(i,d){          
     self.baseDraw.path(self,{
      border      : 1,
      borderColor : '#C0C0C0',
      isfill      : false,
      path        : [
       M,
       processPoint(startX-5),
       processPoint(startY-i * yPices),
       L,
       processPoint(startX),
       processPoint(startY-i * yPices),
      ]
     })
     .appendTo(panel);
     span = self.baseDraw.span(self,{
      x   : startX - x,
      y   : startY -i * yPices-offset-calTextLen(d).h/2 + y,
      'text-anchor':'middle'
     })
     .css({
       fontFamily:'Verdana,Arial,Helvetica,sans-serif',
       fontSize:'12px',
       width   : '60px',
       textAlign:'right'
     })
     .addText(d)
     .appendTo(panel)   
  
    });
    
    
    var xPices = drawAreaWidth / lineNum;
    
    for(var i=0;i<=lineNum;i++){
     self.baseDraw.path(self,{
      border      : 1,
      borderColor : '#C0C0C0',
      isfill      : false,
      path        : [
       M,
       processPoint(startX + (i * xPices)),
       processPoint(startY),
       L,
       processPoint(startX + (i*xPices)),
       processPoint(startY - drawAreaHeight)
      ]
     }).
     appendTo(panel);
     
     self.baseDraw.span(self,{
      x   : startX - calTextLen(min+i*f+'').w/2 + i * xPices,
      y   : startY,
      'text-anchor':'left'
     })
     .css({
       fontFamily:'Verdana,Arial,Helvetica,sans-serif',
       fontSize:'12px'
     })
     .addText(min+i*f+'')
     .appendTo(panel);   
    }
    
   }
//----------------------------------------------------------------------------------------------------- 
   //因为源点很只怕不是从0开端的  所以在起源的时候要要抬高到0那部分的值
   var jianju =0;
   if(min>0)jianju = min;
   if(max<0)jianju = max;
   
   startX = opts.charts.panel==='x' ? startX :startX-xPices*(min/f);
   startY = opts.charts.panel==='x' ? startY + yPices*(min/f) : startY;    
   opts.draw = {
     startX  : startX,  // X 轴起点
     startY  : startY ,  // Y 轴起点
     xPices  : xPices,  // X 轴每份的上升的幅度
     yPices  : yPices,  // Y 轴每份的大幅
     offset  : offset,  // X 单分中央点地点偏移量
     jianjuY : jianju*yPices/f,
     jianjuX : jianju*xPices/f,     
     feed    : f    // Y 轴的每份有微微 
   }
   return this;
  },
  createTooltip : function(){
   //一个组
   this.tipC = this.group('tip')
    .css({zIndex: 200,height:'20px',width:'20px',position:'absolute'})
    .appendTo()
    .hide()
   //画三个框框baseDraw 
   this.tipBox = this.baseDraw.rect(this,{arc:0.22,fill:'#fff',border:2,borderColor:'#606060'})
    .appendTo(this.tipC)
   
   //因为svg里面包车型大巴g能够直接固定 不过vml里面包车型客车group渲染异常慢 所以改div  所以这里的父不一洋
   var p = isIE ?this.tipBox :this.tipC;
   
   this.tipTxtContainer = this.baseDraw.text(this,{fill:'#000000',x:5,y:19,'text-anchor':'left'})
    .css({
      fontFamily:'Verdana,Arial,Helvetica,sans-serif',
      fontSize:'12px',
      background: '#FFF'
    })
    .appendTo(p);
    
   this.tipText = doc.createTextNode('');
   this.tipTxtContainer[0].appendChild(this.tipText);
   return this;
  },
  showTooltip : function(obj, x, y,data){
      
   /*var txt  = obj.name +':' + data,
    size = calTextLen(txt,this.tipTxtContainer[0].style.cssText),
    pos  = {x : x - (size.w + 5 * 2)/2 ,y : y - 32};
   this.tipC
    .toFront()
    .show();
   if(hasSVG){
    this.tipC.attr({transform:'translate('+pos.x+','+pos.y+')'});
    
    this.tipBox
     .attr({width  : size.w + 5 * 2,height : size.h + 5 * 2,stroke : obj.color||'#606060'});
   }else{
    this.tipC.css({left:pos.x,top:pos.y});
    
    this.tipBox
     .css({width:size.w + 5 * 2,height : size.h + 5 * 2})
    this.tipBox[0].strokeColor = obj.color||'#000';    
   }
   this.tipText.nodeValue = txt || '';*/
   clearTimeout(this.timer);
   var txt  = obj.name +':' + data,
    self = this,
    size = calTextLen(txt,this.tipTxtContainer[0].style.cssText),
    pos  = {x : x - (size.w + 5 * 2)/2 ,y : y - 32};
   if(hasSVG){          
    self.tipBox
     .attr({width  : size.w + 5 * 2,height : size.h + 5 * 2,stroke : obj.color||'#606060'});
   }else{          
    self.tipBox
     .css({width:size.w + 5 * 2,height : size.h + 5 * 2})
    self.tipBox[0].strokeColor = obj.color||'#000';    
   }
   this.tipText.nodeValue = txt || '';
   
   if(this.tipC[0].style.display === 'none'){
    hasSVG
     ? self.tipC.attr({transform:'translate('+pos.x+','+pos.y+')',pos:pos.x+'-'+pos.y})
     : self.tipC.attr({pos:pos.x+'-'+pos.y}).css({left:pos.x,top:pos.y});
    this.tipC
     .toFront()
     .show();
        
   }else{
    var move = function(t,b,c,d){
               return c*(t/=d)*t + b;
           },
     t = 0,
     b = self.tipC.attr('pos').split('-'),
     c = [pos.x,pos.y],
     d = 5;
    
    this.timer = setInterval(function(){
     if(t<d){
      t++;
      
     var x = move(t,
b[0],(c[0])-(b[0]),d),
      y = move(t,b[1],(c[1])-(b[1]),d);
     hasSVG
      ? self.tipC.attr({transform:'translate('+x+','+y+')',pos:x+'-'+y})
      : self.tipC.attr({pos:x+'-'+y}).css({left:x,top:y});
     }else{
      clearTimeout(self.timer);
     }
    },1);
   }; 
  },
  hideTooltip: function(){
   this.tipC.hide();
  },   
  drawLegend : function(type,redraw){
   var self   = this,
    opts   = this.opts,
    isLine = opts.charts.type === 'line',
    //颜色块的尺寸
    t_width  = 20,
    t_height = 20,
    //块之间的偏离
    t_space  = 5,     
    datas    = opts.chartData,
    len      = datas.length,
    css      = opts.legend.style,
    //最大尺寸 假若是纵着的 须求最大的尺寸
    maxWidth = 10,
    maxHeight= 30,
    //这么些东西的地点
    orig_pos = opts.legend.pos?opts.legend.pos:[2,2],
    
    //突显遮掩组的函数
    handle   = function(i){
     var g = self.mainGroup['chart'+i],
      issegment = opts.charts.type==='segment';
     
     if(g.show){
      g.chart.hide();
      g.show = false;
      hasSVG
       ? this.attr({fill:'#ccc'})
       : this[0].style.color = '#ccc';
      
      
      //假设是分段图  是会涉嫌到重画的
      if(issegment){
       self.hideList[i] ='';
       var mainGroup = self.mainGroup;
     
       for(var name in mainGroup){ 
        var parent = mainGroup[name].chart,
         nodes  = parent[0].childNodes,
         len    = nodes.length;
        //销毁图上面画的事物
        for(var i = len-1;i>=0;i--){
         vector.prototype.destroy.call(nodes[i])
        }  
       }
       //重画 
       self.drawSegment();
      } 
 
     }else{
      g.chart.show();
      g.show = true;
      hasSVG
       ? this.attr({fill:'#000'})
       : this[0].style.color = '#000'
       
      if(issegment){
       delete self.hideList[i];
       var mainGroup = self.mainGroup;
     
       for(var name in mainGroup){
        
        var parent = mainGroup[name].chart,
         nodes  = parent[0].childNodes,
         len    = nodes.length;
        for(var i = len-1;i>=0;i--){
         vector.prototype.destroy.call(nodes[i])
        } 
 
       }
       self.drawSegment();
      }        
     }
    },
    
    arr = [];
   type = type ||'lateral'; 
   var legendPanel = self.group('Legend')
    .appendTo();
   if(type==='lateral'){
    //即使是横着的
    var top  = orig_pos[1] + 5,
     th   = hasSVG?0:3,
     left = orig_pos[0] + 5;
    each(datas, function(i,d){          
     left = i===0 ? left : t_space+left;
     //总结有所left的地点
     //借使是线性图  按线性图的不二等秘书诀画图
     if(isLine){
      self.baseDraw.path(self,{
       border      : 1.5,
       borderColor : d.color,
       isfill      : false,
       path        : [
        M,
        left.toFixed(0),
        (top+10).toFixed(0),
        L,
        (left+25).toFixed(0),
        (top+10).toFixed(0)
       ]
        })
        .appendTo(legendPanel);
      self.baseDraw[d.dotType || 'circle'](self,{
       x : left+12,     
       y : top+10,
       r : 4,
       fillColor : d.color
      })
      .appendTo(legendPanel);
     }else{
      self.baseDraw.rect(self,{
       arc         : 0.1,
       fill        : d.color,
       border      : 1,
       borderColor : d.color,
       left        : left,
       top         : top,
       width       : t_width+'px',
       height      : t_height+'px'   
      })
      .appendTo(legendPanel)
     }
 
     left = left + t_width+2 + t_space;
     var w = calTextLen(d.name,css).w
     self.baseDraw.span(self,{
      'text-anchor':'left',
      x : left,
      y : top+th
     })
     .css(extend(css,{cursor:'pointer'}))
     .on('click',function(){
      handle.call(this,i);
     })
     .addText(d.name)
     .appendTo(legendPanel);
     left = left + w;
    });
    this.baseDraw.rect(this,{
      arc         : 0.1,
      fill        : 'none',
      border      : 1.5,
      borderColor : '#666666',
      width       : left+ t_space- orig_pos[0],
      height      : maxHeight,
      left        : orig_pos[0],
      top         : orig_pos[1]
     })
     .appendTo(legendPanel);
   }else{
    var top  = orig_pos[1] + 5,
     th   = hasSVG?0:3,
     left = orig_pos[0] + 5;
    each(datas, function(i,d){
     top = i===0 ? top : t_space + top;
     self.baseDraw.rect(self,{
      arc         : 0.1,
      fill        : d.color,
      border      : 1,
      borderColor : d.color,
      left        : left,
      top         : top,
      width       : t_width+'px',
      height      : t_height+'px'   
     })
     .appendTo(legendPanel);
     var h = calTextLen(d.name,css).h;
     
     self.baseDraw.span(self,{
      'text-anchor':'left',
      x : left+t_width+2+t_space,
      y : top+th
     })
     .css(extend(css,{cursor:'pointer'}))
     .addText(d.name)
     .on('click',function(){
      //假使是多层饼图 不行进掩盖    
      if(opts.charts.type==='pies')return;
      handle.call(this,i);     
     })
     .appendTo(legendPanel); 
     top = top + h+ t_space;
     maxWidth = Math.max(maxWidth,calTextLen(d.name,css).w);
    }); 
    this.baseDraw.rect(this,{
      arc         : 0.1,
      fill        : 'none',
      border      : 1.5,
      borderColor : '#666666',
      width       : maxWidth+22+15,
      height      : top+t_space-orig_pos[1],
      left        : orig_pos[0],
      top         : orig_pos[1]
     })
     .appendTo(legendPanel);    
   }
   return this;
  },
  drawLine  : function(){
   var self = this,
    opts = this.opts,
    draw = opts.draw;
   each(opts.chartData,function(i,o){
    var id = 'chart'+i,
     lineGroup = self.group(id)
      .appendTo();
    self.mainGroup[id]={
     chart : lineGroup,
     show  : true
    }; 
    var path = [M],
     data = o.data,
     line;
     
    for(var i = 0,l = data.length; i < l ; i++){
     if( data[i] == null){
      //借使那个数目不设有 并且不是首先个数据 路线上加 M
      if(path[path.length - 1] !== M)
       path.push(M);
     }else{
      //纵然不是首先个数据 路径增添L
      i !== 0 && path.push("L");
      //借使后边二个是null 况且不是率先个  把特别L去掉
      if(i > 0 && data[i - 1] == null)
       path.pop();
      //计算出 点的x,y的位置 
      var x = draw.startX + draw.offset + (i * draw.xPices),
       y = draw.startY - data[i] * (draw.yPices / draw.feed);
      if(isIE){
       x = parseInt(x);
       y = parseInt(y);
      }
      path.push(x);
      path.push(y);
      //画点
      var dotType = o.dotType||'circle';
      self.baseDraw[dotType](self,{
       x : x,     
       y : y,
       r : 4,
       fillColor : o.color
      })
      .attr({data:data[i],pos:x+'-'+(y-5)})
      .css({zIndex:10,cursor:'pointer'})
      .on('mouseover',(function(o,x,y){
       return function(){
        if(self.currList.dot){
         if(self.currList.dot[0] === this[0])
          return;
         self.currList.dot.setSize(0);
         self.currList.line.setSize(1.5);
        }
        this.setSize(2);
        line.setSize(2.5);
        var pos = this.attr('pos').split('-');
        self.showTooltip(o,pos[0],pos[1],this.attr('data'));
        self.currList.dot  = this;
        self.currList.line = line;
       }                  
      })(o,x,y))
      /*.on('mouseout',function(){    
       this.setSize(0);
       line.setSize(1.5);
      })*/
      .on('click',function(){lineGroup.toFront(); })
      .appendTo(lineGroup);
     }
    };
    //画折线
    line = self.baseDraw.path(self,{
     border      : 1.5,
     borderColor : o.color,
     isfill      : false,
     path        : path
    })
    .css({zIndex:5})
    /*.on('mouseover',function(){
     this.setSize(2.5);
    })
    .on('mouseout',function(){          
     this.setSize(1.5);
    })*/
    .on('click',function(){lineGroup.toFront();})
    .appendTo(lineGroup);
   });
   return this;
  },
  drawArea  : function(){
   var self = this,
    opts = this.opts,
    draw = opts.draw;
   each(opts.chartData,function(i,o){
    var id = 'chart' + i,
     areaGroup = self.group(id).appendTo();
    self.mainGroup[id] = {chart : areaGroup,show : true};
    //有2个路线 多少个是区域的路线 一个是线的渠道
    var areaPath = [M, (draw.startX + draw.offset).toFixed(0), (draw.startY-draw.jianjuY).toFixed(0)],
     path     = [M],
     data     = o.data,
     line;
    for(var n=0,l = data.length;n<l;n++){
     //倘使数据是空的
     var len = areaPath.length;
     if( data[n] === null){
      //假如前边的多少个不是m 就再一次画 所以加上 M
      if(path[path.length - 1] !== M)
       path.push(M);
      
      //若是第4个 或然前边的都为null 修改起源坐标
      len===3
       &&(areaPath[1] = (draw.startX +(n+1)*draw.xPices + draw.offset).toFixed(0));
      
      //即使前者不是得了标记符  区域图截至 假使第三个数据是null 则不开展上面包车型大巴操作
      if(areaPath[len - 1] !== seal&&n!==0){
       areaPath=areaPath.concat([
        areaPath[len - 2],
        (draw.startY-draw.jianjuY).toFixed(0),
        seal
       ]);
      }
     }else{
       n !== 0 && path.push(L);
       areaPath.push(L);
       //若是前面包车型大巴丰裕数据是null 把前面包车型客车足够L去掉
       if(n > 0 && data[n - 1] == null){
        path.pop();
        //假使是率先个为null 不删除L
        n!==1&&areaPath.pop();
       }
        
       var x = draw.startX + draw.offset + (n * draw.xPices),
        y = draw.startY - data[n] * (draw.yPices / draw.feed);
       if(isIE){
        x = parseInt(x);
        y = parseInt(y);
       }        
       path.push(x);
       path.push(y);
       
       if(areaPath[len - 1] === seal){
        areaPath = areaPath.concat([
         M,
         x,
         parseInt(draw.startY-draw.jianjuY),
         L,
         x,
         y         
        ]);
       }else{
        areaPath.push(x);
        areaPath.push(y);
       }
       
       //如若是最终多个点
       if(n === l - 1){ 
        areaPath.push(x);
        areaPath.push(parseInt(draw.startY-draw.jianjuY));
       }
       //画点
       self.baseDraw[o.dotType || 'circle'](self,{
        x : x,     
        y : y,
        r : 4,
        fillColor : o.color
       })
       .attr({data:data[n],pos:x+'-'+(y-5)})
       .on('mouseover',(function(o,x,y){
        return function(){
         if(self.currList.dot){
          if(self.currList.dot[0] === this[0])
           return;
          self.currList.dot.setSize(0);
          self.currList.line.setSize(1.5);
         }
         this.setSize(2);
         line.setSize(2.5);
         var pos = this.attr('pos').split('-');
         self.showTooltip(o,pos[0],pos[1],this.attr('data'));
         self.currList.dot  = this;
         self.currList.line = line;
        }            
       
       })(o,x,y))
       /*.on('mouseout',function(){
        this.setSize(0);
        line.setSize(1.5);
        //self.hideTooltip()
       })*/
       .on('click',function(){areaGroup.toFront(); }) 
       .css({zIndex:10,cursor:'pointer'})
       .appendTo(areaGroup);
       
     }
    }
    areaPath.push(seal)
    self.baseDraw.path(self,{
     border      : 0,
     isfill      : true,
     fillColor   : o.color,
     opacity     : 0.5,
     path        : areaPath
    })
    .css({zIndex:5})
    .appendTo(areaGroup);
    
    line = self.baseDraw.path(self,{
     border      : 1.5,
     borderColor : o.color,
     isfill      : false,
     path        : path
    })
    /*.on('mouseover',function(){
     hasSVG
      ? this.attr({'stroke-width':2.5})
      : (this[0].strokeWeight = 2.5);
    })
    .on('mouseout',function(){
     hasSVG
      ? this.attr({'stroke-width':1.5})
      : (this[0].strokeWeight = 1.5);
    })*/
    .on('click',function(){areaGroup.toFront(); })    
    .css({zIndex:-1})
    .appendTo(areaGroup);
   });
   return this;
  },
  drawColumns : function(){
   var self = this,
    opts = this.opts,
    draw = opts.draw,
    chartData     = opts.chartData,
    dataLen       = chartData.length,
    //五个柱子之间的间隔
    columnSpace   = 3,
    //多个职位中 全数的间隔之和
    columnPadding = columnSpace * dataLen + columnSpace,
    //每个柱子的幅度
    columnSize    = self.opts.charts.panel==='x'
     ? Number(((draw.xPices - columnPadding) / dataLen).toFixed(0))
     : Number(((draw.yPices - columnPadding) / dataLen).toFixed(0));
   each(chartData, function(i,o){
    var data     = o.data,
     id       = 'chart' + i,
     isX      = opts.charts.panel==='x',
     colGroup = self.group(id).appendTo(),
     //每一种点起来的地方
     start    = self.opts.charts.panel==='x'
      ? draw.startX + columnSpace + i*(columnSize+columnSpace)
      : draw.startY + columnSpace + i*(columnSize+columnSpace)
    self.mainGroup[id] = {chart:colGroup,show:true};
    for(var j = 0,l=data.length; j < l ; j++){
     if(data[j]===null) continue;
     //假诺是横盘子
     if(isX){
      var x      = Number((start + j *draw.xPices ).toFixed(0)),
       y      = Number((draw.startY-draw.jianjuY).toFixed(0)),
       height = Number((data[j] * (draw.yPices / draw.feed)-draw.jianjuY).toFixed(0)),
       path   = [
        M,
        x,
        y,
        L,
        x,
        y -height,
        L,
        x + columnSize,
        y - height,
        L,
        x + columnSize,
        y,
        seal
       ];
      var pos = [x+columnSize/2,data[j]>0?y-height:draw.startY-draw.jianjuY];
     }else{
       var x     = Number((draw.startX+draw.jianjuX).toFixed(0)),
         width = Number((data[j]*((draw.xPices / draw.feed))-draw.jianjuX).toFixed(0)),
         y     = Number((start - (j+1) *draw.yPices ).toFixed(0)),
        path  = [
        M,
        x,
        y,
        L,
        x+ width,
        y ,
        L,
        x + width,
        y + columnSize,
        L,
        x ,
        y+ columnSize,
        seal
       ];
      var pos = [draw.startX+draw.jianjuX+width/2,y];
     }
     self.baseDraw.path(self,{
      border      : 0,
      isfill      : true,
      fillColor   : o.color,
      opacity     : 1,
      path        : path
     })
     .attr({data:data[j],pos:pos[0]+'-'+pos[1]})
     .css({zIndex:5,cursor:'pointer'})    
     .on('mouseover',(function(d){
            
       return function(){         
         this.setOpacity(0.85); 
         var pos= this.attr('pos').split('-')
         self.showTooltip(o,pos[0],pos[1],this.attr('data'));        
       }
       
      })(data[j])
     )
     .on('mouseout',function(){
      this.setOpacity(1); 
     })
     .appendTo(colGroup);
     
    }
   });
   return this;
  },
  drawPie   : function(){
   var self  = this,
    opts  = this.opts,
    area  = opts.area,
    rx    = area.centerX,
    ry    = area.centerY,
    inc   = 0,
    total = 0,
    data  = [],
    cumulative = -0.25, // start at top;
    circ  = 2 * Math.PI,
    radiu = mathMin(opts.charts.radius,mathMin(area.areaWidth/2,area.areaHeight/2)),
    fraction,
    half_fraction;
   
   each(opts.chartData,function(i,o){
    typeof o.data ==='object'
     ? (data.push((function(o){
      var all =0;
      for(var i in o)
       all+=
o[i]
      return all 
      })(o.data)))
     :data.push(mathAbs(o.data))
   });
   each(data,function(i,o){
    total = total + o;
   });
   
   each(data,function(i,o){
    var pieGroup = self.group('chart'+i).appendTo(),
     s    = inc/total*360,
     e    = (inc + o)/total*360,
     name = opts.chartData[i].name,
     size = calTextLen(name),
     dot  = angle(radiu,[rx,ry],s+(e-s)/2,2),
     x    = rx + (dot[0]-rx)/2 - size.w/2,
     y    = ry + (dot[1]-ry)/2 - size.h/2,
     len  = Math.sqrt((x-rx)*(x-rx)+(y-ry)*(y-ry)),
     moveDisplacement = ((x-rx)*8/len)+','+((y-ry)*8/len);
    inc = inc + o;
    var value = Number(o);
    fraction = total ? value / total : 0;
    half_fraction = total ? (value / 2) / total : 0;
    
    var start = cumulative * circ;
    half_cumulative = cumulative + half_fraction;
    cumulative += fraction;
    var end = cumulative * circ;
    self.baseDraw.pie(self,{
     config  : opts.chartData[i],
     s       : start,
     e       : end,
     r       : radiu,
     innerR  : 0
    })    
    .css({zIndex:5,cursor:'pointer'})
    .attr({move:moveDisplacement,pos:dot[0]+'-'+dot[1]})
    .on('mouseover',function(){     
     this.setOpacity(0.85);
     var pos = this.attr('pos').split('-');
     self.showTooltip(opts.chartData[i],pos[0],pos[1],((e-s)/360*100).toFixed(0)+'%')
    })
    .on('mouseout',function(e){
     var elem = e.toElement || e.relatedTarget;
     //借使境遇里面包车型客车文本 也许是提醒框  不收敛
     if(!elem||contains(this[0].parentNode,elem)||contains(self.tipC[0],elem))
      return;
     self.hideTooltip(); 
     this.setOpacity(1);
    })
    .on('click',function(){
     var m = this.attr('move') 
     if(m.indexOf('+')>0){
      hasSVG
       ? this.attr({
        transform: 'translate(0,0)'
       })
       : this.css({
        left : '0px',
        top  : '0px'
       })
      this.attr({move:m.replace('+','')});   
      
     }else{
      var s= m.split(',');
      hasSVG
       ? this.attr({
        transform: 'translate('+m+')'
       })
       : this.css({
        left : s[0]+'px',
        top  : s[1]+'px'
       })
 
      this.attr({move:m+'+'});
     }                 
    })
    .appendTo(pieGroup); 
    
    self.mainGroup['chart'+i] = {
     chart : pieGroup,
     show  : true
    };
    
    self.baseDraw.span(self,{
      x    : x,
      y    : y,
      fill : '#fff',
      'text-anchor':'left'
     })
     .css({
       fontFamily : 'Verdana,Arial,Helvetica,sans-serif',
       fontSize   : '12px',
       position   : 'absolute',
       color      : '#fff',
       cursor     : 'pointer',
       zIndex     : 10
     })
     .addText(name)
     .appendTo(pieGroup);
   });
  },
  drawPies  : function(){
   var self  = this,
    opts  = this.opts,
    area  = opts.area,
    rx    = area.centerX,
    ry    = area.centerY,
    total = 0,
    data  = [],
    chartData  = opts.chartData,
    cumulative = -0.25, // start at top;
    circ  = 2 * Math.PI,
    radiu = mathMin(opts.charts.radius,mathMin(area.areaWidth/2,area.areaHeight/2)),
    fraction,
    half_cumulative,
    half_fraction;  
   
   each(chartData,function(i,o){
    each(o.data,function(j,d){
     data[j]
      ? data[j] +=mathAbs(d)
      : data[j] =mathAbs(d)
    });
   
   });
   //看有稍许个数据来生成来生成内半径
   var len = data.length,
    innerSpace = radiu / 10;
    Rpice = (radiu - innerSpace) / len;
   each(data,function(i,d){
    var inc = 0;
    if(d===0) return;     
    each(chartData,function(j,o){
     if(~~o.data[i]===0)return;
     var outR   = radiu - Rpice * i,
      innerR = radiu - Rpice * (i + 1),
      value  = ~~o.data[i],
      fraction = value / d;
      half_fraction = (value/2)/d ,
      start = cumulative * circ,      
      s     = inc/d*360,
      e     = (inc + value)/d*360,
      id    = 'chart'+j,
      piesGroup = self.mainGroup[id]?self.mainGroup[id].chart:self.group(id).appendTo();      
     !self.mainGroup[id]
      &&(self.mainGroup[id] = {chart:piesGroup,show:true});        
     inc = inc + value;
     var name = o.name,
      size = calTextLen(name),
      dot  = angle(radiu,[rx,ry],s+(e-s)/2,2),
      showDot = angle(radiu- Rpice * i,[rx,ry],s+(e-s)/2,2),
      px   = dot[0]>rx?1:-1,
      py   = dot[1]>ry?1:-1;
     var x    = rx + px*innerSpace + ((dot[0]-rx-px*innerSpace)/len)*(len-i-1)+((dot[0]-rx-px*innerSpace)/len)/2- size.w/2,
      y    = ry + py*innerSpace +((dot[1]-ry-py*innerSpace)/len)*(len-i-1)+((dot[1]-ry-py*innerSpace)/len)/2- size.h/2;   
      
     half_cumulative = cumulative + half_fraction,
     cumulative += fraction,
     end = cumulative * circ;
     self.baseDraw.pie(self,{
      config  :  o,
      s       :  start,
      e       :  end,
      r       :  outR,
      innerR  :  innerR
     })
     .attr({m :  i+'-'+j,data:((e-s)/360*100).toFixed(0)+'%',pos:showDot[0]+'-'+showDot[1]})
     .css({zIndex:5,cursor:'pointer'})
     .on('mouseover',function(){
      this.setOpacity(0.85);
      var pos = this.attr('pos').split('-');
      self.showTooltip(o,pos[0],pos[1],this.attr('data'))
     })
     .on('mouseout',function(e){
      var elem = e.toElement || e.relatedTarget;
      if(!elem||elem.getAttribute('m')===this[0].getAttribute('m'))
       return;           
      this.setOpacity(1);
     })     
     .appendTo(piesGroup);
     self.baseDraw.span(self,{
       x    : x,
       y    : y,
       fill : '#fff',
       'text-anchor':'left'
      })
      .attr({m :  i+'-'+j})
      .css({
        fontFamily : 'Verdana,Arial,Helvetica,sans-serif',
        fontSize   : '12px',
        position   : 'absolute',
        color      : '#fff',
        cursor     : 'pointer',
        zIndex     : 10
      })
      .addText(name)
      .appendTo(piesGroup);
    });
  
   });
  },
  drawSegment  : function(){
 
   var self = this,
    opts = this.opts,
    draw = opts.draw,
    chartData  = opts.chartData,
    typeIsX    = opts.charts.panel==='x',
    columnPad  = 5,
    prev       = [],
    columnSize = ~~(typeIsX?draw.xPices:draw.yPices) - columnPad * 2;
   each(chartData,function(i,c){
    if(i in self.hideList)
     return;
     
    var id    = 'chart' + i,
     segmentGroup = self.mainGroup[id]?self.mainGroup[id].chart:self.group(id).appendTo();
     
    self.mainGroup[id] = {chart : segmentGroup,show : true};
    
    each(c.data,function(j,d){
     if(d===null||d===0)
      return;
     
     if(typeIsX){
      var start  = draw.startX + columnPad,
       x      = ~~(start + j*draw.xPices).toFixed(0),
       y      = ~~(draw.startY-(prev[j]?prev[j]:0)).toFixed(0),
       size   = ~~(d*draw.yPices / draw.feed ).toFixed(0),
       path   = [
        M,
        x,
        y,
        L,
        x,
        y - size,
        L,
        x + columnSize,
        y - size,
        L,
        x + columnSize,
        y,
        seal
       ];
      var pos = [x + columnSize/2,y-size]; 
     }else{
      var start  = draw.startY - columnPad,
       x      = ~~(draw.startX+(prev[j]?prev[j]:0)).toFixed(0) ,
       y      = ~~(start- j*draw.yPices).toFixed(0),
       size   = ~~(d*draw.xPices / draw.feed ).toFixed(0),
       path   = [
        M,
        x,
        y,
        L,
        x + size,
        y ,
        L,
        x + size,
        y - columnSize,
        L,
        x ,
        y - columnSize,
        seal
       ];
      var pos = [x+size/2,y - columnSize]; 
     }
     self.baseDraw.path(self,{
      border      : 0,
      isfill      : true,
      fillColor   : c.color,
      opacity     : 1,
      path        : path
     })
     .attr({data:d,pos:pos[0]+'-'+pos[1]})
     .on('mouseover',function(){           
      this.setOpacity(0.85);
      var pos = this.attr('pos').split('-');
      self.showTooltip(chartData[i],pos[0],pos[1],this.attr('data'))      
     })
     .on('mouseout',function(){
      this.setOpacity(1);
     })      
     .css({zIndex:5,cursor:'pointer',left:'0px',top:'0px'})    
     .appendTo(segmentGroup);
     prev[j]
      ? prev[j] = prev[j] + size
      : prev[j] = size;
    });
   });
  },
  baseDraw  : {
   rect : function(o,config){
    return o.createElement('rect')
     .attr({
      rx             : config.arc*30 || 5,
      ry             : config.arc*30 || 5,
      width          : config.width  || 50,
      height         : config.height || 50,
      fill           : config.fill   || '#fff',
      'fill-opacity' : config.opacity || 0.85,
      'stroke-width' : config.border  || 2,
      stroke         : config.borderColor  || '#606060',
      transform      : 'translate('+(config.left||0)+','+(config.top||0)+')'
     });
   },
   text : function(o,config){
    return o.createElement('text')
     .attr(config);
   },
   span : function(o,config,v){
    return o.createElement('text')
     .attr(config)
     .attr({
      y : config.y+(v||15)
     });
   },
   path : function(o,config){
    var set = {};
    set['stroke-width'] = config.border;
    set.stroke = config.borderColor || '#C0C0C0';
    set.fill   = config.isfill?config.fillColor:'none';
    set.d      = config.path;
    config.opacity
     &&(set['fill-opacity'] = config.opacity);
     
    return o.createElement('path')
     .attr(set);
   },
   circle : function(o,config){
    var set  = {};
    set.cx   = config.x;
    set.cy   = config.y;
    set['stroke-width'] = 0;
    set.stroke = config.borderColor || '#C0C0C0';
    set.r    = config.r;
    set.fill = config.fillColor;
    return o.createElement('circle')
     .attr(set); 
   },
   square : function(o,config){  
    var x    = config.x,
     y    = config.y,
     r    = config.r,
     color= config.fillColor,
     len  = r,
     path = [
      M,
      (x-len).toFixed(0),
      (y-len).toFixed(0),
      L,
      (x+len).toFixed(0),
      (y-len).toFixed(0),
      (x+len).toFixed(0),
      (y+len).toFixed(0),
      (x-len).toFixed(0),
      (y+len).toFixed(0),
      seal
     ];
     return o.baseDraw.path(o,{
      border      : 1,
      borderColor : color,
      isfill      : true,
      fillColor   : color,
      path        : path     
     });    
   },
   triangle : function(o,config){
    var x     = config.x,
     y     = config.y,
     r     = config.r+0.1,
     color = config.fillColor,
     path  = [
      M,
      x.toFixed(0),
      (y-1.33*r).toFixed(0),
      L,
      (x+r).toFixed(0),
      (y+0.67*r).toFixed(0),
      (x-r).toFixed(0),
      (y+0.67*r).toFixed(0),
      seal
     ];
    return o.baseDraw.path(o,{
     border      : 1,
     borderColor : color,
     isfill      : true,
     fillColor   : color,
     path        : path     
    });       
   },
   diamond : function(o,config){
    var x     = config.x,
     y     = config.y,
     r     = 1.35*config.r,
     color = config.fillColor,
     path  = [
      M,
      x.toFixed(0),
      (y-r).toFixed(0),
      L,
      (x+r).toFixed(0),
      y.toFixed(0),
      x.toFixed(0),
      (y+r).toFixed(0),
      (x-r).toFixed(0),
      y.toFixed(0),
      seal
     ];
    return o.baseDraw.path(o,{
     border      : 1,
     borderColor : color,
     isfill      : true,
     fillColor   : color,
     path        : path     
    });       
   },
   pie    : function(o,config){
    //config,s,e,r,index
    var opts     = o.opts,
     s        = config.s,
     r        = config.r,
     e        = config.e - 0.000001,
     id       = 'chart'+config.index,
     area     = opts.area,
     rx       = area.centerX,
     ry       = area.centerY,
     cosStart = mathCos(s),
     sinStart = mathSin(s),
     cosEnd   = mathCos(e),
     sinEnd   = mathSin(e),    
     color    = config.config.color,
     innerR   = config.innerR,           
     longArc  = e - s < Math.PI ? 0 : 1,
     path  = [
      M,
      rx + r * cosStart,
      ry + r * sinStart,
      'A',
      r,
      r,
      0,
      longArc,
      1,
      rx + r * cosEnd,
      ry + r * sinEnd,
      L,
      rx + innerR * cosEnd,
      ry + innerR * sinEnd,
      'A', // arcTo
      innerR, // x radius
      innerR, // y radius
      0, // slanting
      longArc, // long or short arc
      0, // clockwise
      rx + innerR * cosStart,
      ry + innerR * sinStart,
      'Z'
     ];
  
    return o.baseDraw.path(o,{
     border      : 1,
     border      : '#fff',
     isfill      : true,
     fillColor   : color,
     opacity     : 1,
     path        : path
  
    })
  
   } 
  }
 };
 
//---------------------------------------------------------------------------------------------------
//要是是vml 修改smipleChart.prototype中的一些艺术
 !hasSVG 
  &&extend(smipleChart.prototype.baseDraw,{
   rect : function(o,config){  
    var attr = {},
     css  = {};
    attr.arcsize       = config.arc || 0.2 +'';
    if(config.fill==='none'){
     attr.filled    = 'f'
    }else{
     attr.filled    = 't';   
     attr.fillcolor = config.fill || '#fff';
    }
  
    attr.strokeWeight  = config.border  || 2;
    attr.strokeColor   = config.borderColor  || '#606060';
    css.width   = config.width || 50 +'px';
    css.height  = config.height || 50 +'px';
    css.zIndex  = 10;
    css.left    = config.left||0+'px';
    css.top     = config.top ||0+'px';
    
    return o.createElement('roundrect')
     .attr(attr)
     .css(css);
   },
   text : function(o,config){
    return o.createElement('TextBox')
     .attr({inset : "2px,2px,2px,2px" })
     .css({zIndex:200})
   },
   span : function(o,config){
    return o.createElement('span').
     css({
      position:'absolute',
      left : config.x+'px',
      top  : config.y+'px'
     })
   },
   path : function(o,config){   
    var attr   = {},
     width  = o.width,
     height = o.height,
     css    = {
       width    : width+'px',
       height   : height+'px'
     };
    
    if(config.border===0){
     attr.Stroked = 'f';
     attr.strokeWeight =0;
    }else{
     attr.strokeWeight = config.border||1 ;
    }
    attr.strokeColor  = config.borderColor || "#C0C0C0";
    attr.filled       = config.isfill?'t':'f';
    attr.filled==='t'
     &&(attr.fillcolor=config.fillColor||"#C0C0C0");
    attr.coordsize    = width+','+height;
    attr.path         = config.path;
    var elem = o.createElement()
     .attr(attr)
     .css(css);
    if(config.opacity){
     var fill =  o.createElement('fill')
      .attr({
       type     : 'fill',
       color    : config.fillColor||"#C0C0C0",
       opacity  : config.opacity
      })
      .appendTo(elem);
     //那这些指标的壹性情能援引设置透明的成分 未来会用到
     elem.opacity = fill[0];
    }      
    return elem;
     
   },
   circle : function(o,config){
    var width  = o.width,
     height = o.height,
     attr   = {
      strokeWeight : 1,
      coordsize    : width+','+height,
      filled   : 't'
     },
     css  ={
       width    : width+'px',
       height   : height+'px'
     }
     x = config.x,
     y = config.y,
     r = config.r;
    attr.strokeColor=attr.fillcolor = config.fillColor
    
    attr.path =[
     'wa', // clockwisearcto
     x - r, // left
     y - r, // top
     x + r, // right
     y + r, // bottom
     x + r, // start x
     y,     // start y
     x + r, // end x
     y,     // end y
     'e' // close        
    ];
    return o.createElement()
     .attr(attr)
     .css(css) 
   },
   pie   : function(o,config){
    ////config,s,e,r,index
    
    var opts  = o.opts,
     area  = opts.area,
     r     = config.r,
     rx    = area.centerX,
     ry    = area.centerY,
     innerR= config.innerR||0,
     sDot  = angle(r,[rx,ry],s,2),
     eDot  = angle(r,[rx,ry],e,2),
     color = config.config.color,
     s     = config.s,
     e     = config.e,
     e     = e - s == 2 * Math.PI ? e - 0.001 : e,
     cosStart = mathCos(s),
     sinStart = mathSin(s),
     cosEnd = mathCos(e),
     sinEnd = mathSin(e),       
     
     
     path  = [
      'wa', // clockwisearcto
      (rx - r).toFixed(0), // left
      (ry - r).toFixed(0), // top
      (rx + r).toFixed(0), // right
      (ry + r).toFixed(0), // bottom
      (rx + r * cosStart).toFixed(0), // start x
      (ry + r * sinStart).toFixed(0), // start y
      (rx + r * cosEnd).toFixed(0), // end x
      (ry + r * sinEnd).toFixed(0), // end y        
      
      'at', // clockwisearcto
      (rx - innerR).toFixed(0), // left
      (ry - innerR).toFixed(0), // top
      (rx + innerR).toFixed(0), // right
      (ry + innerR).toFixed(0), // bottom
      (rx + innerR * cosEnd).toFixed(0), // start x
      (ry + innerR * sinEnd).toFixed(0), // start y
      (rx + innerR * cosStart).toFixed(0), // end x
      (ry + innerR * sinStart).toFixed(0), // end y
      
      'x', // finish path
      'e' // close         
     ];
  
    return o.baseDraw.path(o,{
     border      : 1,
     border      : '#fff',
     isfill      : true,
     fillColor   : color,
     opacity     : 1,
     path        : path     
    })
    
   } 
  });
//---------------------------------------------------------------------------------------------------
})(document);
 window.onload = function(){
  var t = new Date().getTime();
 var config = {
   charts : {
    type   : 'line',
    radius : 150,
    panel  : 'x',
    style: {
     fontFamily: '"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif', // default font
     fontSize: '12px'
    }
   },
   title : {
    text : '线性图表' ,
    y  : 10,
    style : {
     color: 'black',
     fontSize: '16px'
    }
   },
   subTitle : {
    text : '线性图表副标题',
    y  : 35,
    style: {
     color: '#111',
     fontSize: '12px'
    }
   },
   legend : {
    enable : true,
    //type : 'lateral', // lateral 横向 或 lengthwise 纵向
    type : 'lateral',
    pos  : [10,10],
    style:{
     fontFamily : '"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif', // default font
     fontSize   : '12px',
     magin      : '0px'
    }
   },
   yUnit : {
    text  : '线性图表侧标题',
    x     : 20,
    style : {
     color    : '#111',
     fontSize : '12px'
    }
   },
   xUnit : {
    units: [
     '一月',
     '二月',
     '三月',
     '四月',
     '五月',
     '六月',
     '七月',
     '八月',
     '九月',
     '十月',
     '十一月',
     '十二月'
    ] 
   },
   chartData : [
   {
    name    : 'xcv',
    color   : '#4572A7',
    dotType : 'square',
    //data    : [11,12,13,15,16,18,17,14,10]
    //[1,2,3,5,6,8,7,4,10]
    data: [44,-12,-78,100,-13,-4,-26,34]
   }, {
 
    name: 'frfr',
    color: '#AA4643',
    dotType : 'triangle',    
    data: [-44,12,78,-100,13,4,-56,-34]
   }, {
    name: 'AAAAA',
    color: '#89A54E',
    dotType : 'diamond',
    data: [null,78,83,null,22,-78,2,44,78]
   }, {
    name: 'BBBB',
    color: '#80699B',
    data: [null, 58, 35, null, 52, 47, 26, -55, 39, 123,15,66]
   }
   ]
  };
  new smipleChart($$('line'),config);
  config.charts.type ='area';
  config.title.text ='区域图表'
  config.subTitle.text='区域图表副标题'
  config.yUnit.text ='区域图表侧标题'
  config.chartData = [
   {
    name    : 'xcv',
    color   : '#4572A7',
    //data    : [0,3,4,5,6,7,8,9,10,11]
    data    : [11,12,13,14,15,16,-17,18,19,0]
   }, {
 
    name: 'frfr',
    color: '#AA4643',   
    data: [44,12,78,100,13,44,56,34]
   }, {
    name: 'AAAAA',
    color: '#89A54E',
    data: [null,101,83,null,22,78,88,44,78]
   }, {
    name: 'BBBB',
    color: '#80699B',
    data: [null, 58, 35, null, 52, 47, 26, 55, 39, 123,15,66]
   }
   ]
  
  new smipleChart($$('area'),config);
  config.title.text ='柱状图表'
  config.subTitle.text='柱状图表副标题'
  config.yUnit.text ='柱状图表侧标题'  
  config.charts.type ='columns';
  config.chartData =[
   {
    name  : 'xcv',
    color : '#4572A7',
    //data  : [2,3,4,5,6,7,8,9,10,11]
    data  : [-0.01,-0.62,0,0.55,null,0.78,-0.63,-0.82,null,null,0.33]
   }, {
    name: 'frfr',
    color: '#AA4643',
    data: [-0.22,0.82,0.55,1.32,0.33,0.95,null,1,0.65,null,0.78]
   }, {
    name: 'AAAAA',
    color: '#89A54E',
    data: [null,0.62,0.34,null,0.63,0,-0.23,-1,0.62,0.45,null,-0.56]
   }
   ]
  
  new smipleChart($$('zhu'),config);
  config.charts.panel='y'
  new smipleChart($$('zhu1'),config);
  config.charts.type ='pie';
  config.title.text ='饼图图表'
  config.subTitle.text='饼图图表副标题'
  config.yUnit.text =''
  config.legend.type='lengthwise';
  config.chartData =[
   {
    name  : 'aaa',
    color : '#4572A7',
    data  : [433,123,null,66]
   }, {
    name: 'bbb',
    color: '#AA4643',
    data: [45,33,33,411]
   }, {
    name: 'ccc',
    color: '#89A54E',
    data: [55,null,75,233]
   }, {
    name: 'ddd',
    color: '#80699B',
    data: [63,null,100,333]
   }
   ] 
  config.legend.pos= [680,30]
  new smipleChart($$('pie'),config);
  config.charts.type ='pies';
  config.title.text ='多层饼图图表'
  config.subTitle.text='多层饼图图表副标题' 
   config.legend.type='lateral';
  config.legend.pos= [290,400]  
  new smipleChart($$('pies'),config);  
  config.chartData =[
   {
    name  : 'xcv',
    color : '#4572A7',
    data  : [111,222,333,null,444,555,56,57,84]
   }, {
    name: 'frfr',
    color: '#AA4643',
    data: [845,666,100,null,666,677,56,88,633,55,555]
   }, {
    name: 'AAAAA',
    color: '#89A54E',
    data: [555,162,75,null,364,0,637,112,163,615]
   }
   ]
  
  config.charts.type ='line';
  config.legend.pos= [10,10]
  //
  config.yUnit.lineNum = 10;
  config.charts.panel = 'x';
  config.title.text ='分段图表'
  config.subTitle.text='分段图表副题目'
  config.yUnit.text ='分段图表侧标题'  
  config.charts.type ='segment';
  new smipleChart($$('segmentx'),config);
  config.charts.panel = 'y';
  new smipleChart($$('segmenty'),config);
  config.yUnit.lineNum = 2;
  config.title.text ='非常小的'
  config.subTitle.text='只设置了2条线'
  config.yUnit.text ='小测标题' ; 
  new smipleChart($$('vv'),config);
  //alert(new Date().getTime()-t)
 }
</script>
</body>
</html>

js浮点精度难题 倒霉化解 求助。。。。。。。。。

水平有限 难免难点多多 望赐教。。。。。。。

协理 线性图 区域图 柱状图 饼图 帮衬多浏览器 用到的是svg vml 复制代码 代码如下: !DOCTY...

图片 1

本子下载其余旧版本及切实版本更新境况请到论坛调换:#target photoshopapp.bringToFront();// 带自动判别横竖的联结宽高操作。私下认可是一向保存关闭,原来的文章件要留意备份! v2.0 - 二零零六.3.29// 原发:bbs.blueidea.com- Photoshop版var nowTime=new Date();var PRESOLUTION = 72; var startRulerUnits = app.preferences.rulerUnits;var startTypeUnits = app.preferences.typeUnits;app.preferences.rulerUnits = Units.PIXELS;app.preferences.typeUnits = TypeUnits.PIXELS;var title="批量尺寸调度 v2.0 - " res ="dialog { text:'"+title+"直接保存并关闭', group: Group{orientation: 'column',alignChildren:'left', top:StaticText{text:'默感到一直覆盖保存

  • 请小心选用或做好备份'}, timeline:Progressbar{bounds:[0,0,300,10] , minvalue:0,maxvalue:100} corrdination: Panel { orientation: 'row', text: '须求尺寸', x: Group { orientation: 'row', s: StaticText { text:'宽:' }, e: EditText { preferredSize: [50, 20] } , p: StaticText { text:'px' }, }, y: Group { orientation: 'row', s: StaticText { text:'高:' }, e: EditText { preferredSize: [50, 20] }, p: StaticText { text:'px' }, } , }, a:Group{ orientation: 'row', c: Checkbox { text:' 保持原图宽高比,新尺寸仅作外框限定',helpTip:'原图比例不改变,调度后宽/高均小于等于输入值'} , }, b:Group{ orientation: 'row', c: Checkbox { text:' 不推断原图横竖',helpTip:'不依靠原图的左右自动对应尺寸,宽/高均以输入为准'} , }, now:Group{ orientation: 'row', c: Checkbox { text:' 对文件夹实行操作(不然管理全数前段时间张开的文书档案)'} , }, folderO:Group{ orientation: 'row', b: Button {text:'待管理公事夹', properties:{name:'open'} ,helpTip:'选取你要求处理的文书所在的文本夹'}, s: EditText{ text:'', preferredSize: [180, 20] }, }, shui:Group{ orientation: 'row', c: Checkbox { text:' 为图片增多水印'} , g: Group { one:RadioButton {text:'单一' ,helpTip:'只增加三个水印图,可决定加多位置'}, fill:RadioButton {text:'平铺' ,helpTip:'多少个水印图平铺分布画面,可决定间距'}, } }, shuiSet: Panel {orientation: 'row', text: '水印设置', position:Group{ orientation: 'column',alignChildren:'left', po1:Group{ orientation: 'row', c1:Checkbox { helpTip:'以左上角为基准', preferredSize: [14, 14]} , c2:Checkbox { helpTip:'以上中式茶食为基准', preferredSize: [14, 14]} , c3:Checkbox { helpTip:'以右上角为基准', preferredSize: [14, 14]} , }, po2:Group{ orientation: 'row', c4:Checkbox { helpTip:'以左中式点心为基准', preferredSize: [14, 14]} , c5:Checkbox { helpTip:'以正着力为基准', preferredSize: [14, 14]} , c6:Checkbox { helpTip:'以右中式点心为基准', preferredSize: [14, 14]} , }, po3:Group{ orientation: 'row', c7:Checkbox { helpTip:'以左下角为基准', preferredSize: [14, 14]} , c8:Checkbox { helpTip:'以下中式茶食为基准', preferredSize: [14, 14]} , c9:Checkbox { helpTip:'以右下角为基准', preferredSize: [14, 14]} , }, }, other:Group{ orientation: 'column',alignChildren:'left', dis:Group{ orientation: 'row', s1: StaticText { text:'平距:'}, e1: EditText { preferredSize: [55, 20], helpTip:'距离参照点的水平距离;平铺状态下为间距(单位:像素)' } , s2: StaticText { text:'垂距:'}, e2: EditText { preferredSize: [55, 20], helpTip:'距离参照点的垂直距离;平铺状态下为间距(单位:像素)' } , }, hun:Group{ orientation: 'row', s: StaticText { text:'混合:'}, d:DropDownList { alignment:'left', itemSize: [50,16] }, s2: StaticText { text:'缩放:'}, e:EditText{ preferredSize: [38, 20], text:'1',helpTip:'水印与原有水印文件的缩放比例'}, }, open:Group{ orientation: 'row', b: Button {text:'采纳水印文件', properties:{name:'open'} ,helpTip:'请确认保障文件为常用图片格式,且非gif动画'}, e: EditText{ text:'', preferredSize: [86, 20] }, }, }, }, other:Group{ orientation: 'row', c: Checkbox {text:' 启用另存'} , g: Group { jpeg:RadioButton {text:'JPEG'}, gif:RadioButton {text:'GIF'}, psd:RadioButton {text:'PSD'}, tiff:RadioButton {text:'TIFF'}, } }, otherSet: Panel {orientation: 'column',alignChildren:'left', text: '另存设置', Quality: Group { orientation: 'row', c: Checkbox { text:'调换 ICC 配置',helpTip:'在积累前将 ICC 配置文件转变为 s凯雷德GB'} , s: StaticText { text:'压缩品质:' }, d: DropDownList { alignment:'left', itemSize: [26,14] }, c2:Checkbox {text:'透明',helpTip:'富含基于颜色不发光度的透明性'}, }, head: Group { orientation: 'row', s: StaticText { text:'在文书名前增多字符:' }, e: EditText { preferredSize: [50,20] } , s2: StaticText { text:'勿含违规字符' , enabled:flase }, }, foot: Group { orientation: 'row', s: StaticText { text:'在文书名后增多字符:' }, e: EditText { preferredSize: [50, 20] }, s2: StaticText { text:'勿含违规字符' , enabled:flase}, } , otherF:Group{ orientation: 'row', c: Checkbox { text:' 另存至别的文件夹'} , }, folderS:Group{ orientation: 'row', b: Button {text:'另存至', properties:{name:'save'} ,helpTip:'采取你管理好的文书要封存至的文书夹'}, s: EditText{ text:'', preferredSize: [180, 20] }, }, icc: Checkbox { text:' 积攒时饱含ICC 配置文件',helpTip:'存为 GIF 格式时此选项无效'}, }, }, buttons: Group { orientation: 'row', alignment: 'right', s:StaticText {text:'[ABOUT]'}, Btnok: Button { text:'确定', properties:{name:'ok'} }, Btncancel: Button { text:'取消', properties:{name:'cancel'} } }, }"; win = new Window (res);win.buttons.Btncancel.onClick = function () { //放弃 app.preferences.rulerUnits = startRulerUnits; app.preferences.typeUnits = startTypeUnits; this.parent.parent.close();}win.buttons.s.onClick = function () {alert("首发:bbs.blueidea.comPhotoshop专栏rn鸣谢:作者爱洋蓟绿、银子、蛋蛋、clz8206、洛辰妃嫔、Wonton",title+"关于");}function lock_b(){//要是勾选了a,则b被锁定 if(win.group.a.c.value){ win.group.b.c.value=true; } }win.group.a.c.onClick =function() { lock_b()}; win.group.b.c.onClick =function() { lock_b()};// 展开文件夹的操作var folderOpen=win.group.folderOvar folderSave=win.group.otherSet.folderSfolderOpen.b.onClick = function() { var defaultFolder = folderOpen.s.text; var testFolder = new Folder(defaultFolder); if (!testFolder.exists) { defaultFolder = "~"; } var selFolder = Folder.selectDialog("选用待管理文件夹", defaultFolder); if ( selFolder != null ) { folderOpen.s.text = selFolder.fsName; folderOpen.s.helpTip = selFolder.fsName.toString(); }}folderSave.b.onClick = function() { var defaultFolder = folderSave.s.text; var testFolder = new Folder(defaultFolder); if (!testFolder.exists) { defaultFolder = "~"; } var selFolder = Folder.selectDialog("采取要积累至的文件夹", defaultFolder); if ( selFolder != null ) { folderSave.s.text = selFolder.fsName; folderSave.s.helpTip = selFolder.fsName.toString(); }}win.group.shuiSet.other.open.b.onClick= function() //打热水印文件{ var selFile = File.saveDialog('选拔水印文件'); if ( selFile != null ) { win.group.shuiSet.other.open.e.text = selFile.fsName; }}// 初步化选项if (app.documents.length == 0){ win.group.now.c.value = true; win.group.folderO.enabled =true;}else{ win.group.folderO.enabled =false;}win.group.other.g.enabled =false;win.group.otherSet.enabled =false;win.group.other.g.jpeg.value = true; //暗许保存为jpgwin.group.otherSet.icc.value =true; //暗许保存iccvar saveType = "jpeg";win.group.otherSet.Quality.c2.hide(); //掩盖第二选框for (i=0;i<13;i++){ //开端化jpeg品质下拉 win.group.otherSet.Quality.d.add("item", i );}win.group.otherSet.Quality.d.items[7].selected=true;win.group.otherSet.Quality.d.helpTip ='JPEG 压缩品质 (值越大压缩后品质越高)';win.group.shuiSet.enabled =false;win.group.shui.g.enabled =false;win.group.shui.g.one.value =true; //默许叁个水印win.group.shuiSet.position.po3.c9.value=true; //默许右下角var jiaShui =false; //暗许不增多水印var sBlend=new Array();sBlend[0]= "正常,NORMAL";sBlend[1]= "溶解,DISSOLVE";sBlend[2]= "变暗,DARKEN";sBlend[3]= "正片叠底,MULTIPLY";sBlend[4]= "颜色加深,COLORBULANDN";sBlend[5]= "线性加深,LINEARBUEvoqueN";sBlend[6]= "变亮,LIGHTEN";sBlend[7]= "滤色,SCREEN";sBlend[8]= "颜色减淡,COLOOdysseyDODGE";sBlend[9]= "线性减淡,LINEA奥迪Q7DODGE";sBlend[10]= "叠加,OVERLAY";sBlend[11]= "柔光,SOFTLIGHT";sBlend[12]= "强光,HARDLIGHT";sBlend[13]= "亮光,VIVIDLIGHT";sBlend[14]= "线性光,LINEARLIGHT";sBlend[15]= "点光,PINLIGHT";sBlend[16]= "实色混合,HAEscortDMIX";sBlend[17]= "差值,DIFFERENCE";sBlend[18]= "排除,EXCLUSION";sBlend[19]= "色相,HUE";sBlend[20]= "饱和度,SATURATION";sBlend[21]= "颜色,COLORBLEND";sBlend[22]= "明度,LUMINOSITY";//sBlend[23]= "深色,DARKERCOLOR";//sBlend[24]= "浅色,LIGHTERCOLOR";for (i=0;i<23;i++) { win.group.shuiSet.other.hun.d.add("item",sBlend.substring(0,sBlend.indexOf(",")));}win.group.shuiSet.other.hun.d.items[0].selected=true;//操作文件夹开关win.group.now.c.onClick =function(){ if (win.group.folderO.enabled) { win.group.folderO.enabled =false; }else{ win.group.folderO.enabled =true; }}//另存按键win.group.other.c.onClick =function(){ if (win.group.otherSet.enabled) { win.group.other.g.enabled =false; win.group.otherSet.enabled =false; win.text=title+'直接保存并关闭'; }else{ win.group.other.g.enabled = true; win.group.otherSet.enabled =true; win.text=title+'另存为并关闭'; if (!win.group.otherSet.otherF.c.value) {win.group.otherSet.folderS.enabled =false} }}//另存至文件夹开关win.group.otherSet.otherF.c.onClick =function(){ if (win.group.otherSet.folderS.enabled) { win.group.otherSet.folderS.enabled =false; }else{ win.group.otherSet.folderS.enabled =true; }}//水印开关win.group.shui.c.onClick =function(){ if (win.group.shui.g.enabled) { win.group.shui.g.enabled =false; win.group.shuiSet.enabled =false; }else{ win.group.shui.g.enabled =true; win.group.shuiSet.enabled =true; }}//定位按键var allp=win.group.shuiSet.position;function pointClear(nowP) { allp.po1.c1.value =false; allp.po1.c2.value =false; allp.po1.c3.value =false; allp.po2.c4.value =false; allp.po2.c5.value =false; allp.po2.c6.value =false; allp.po3.c7.value =false; allp.po3.c8.value =false; allp.po3.c9.value =false; nowP.value =true; }allp.po1.c1.onClick =function() {pointClear(this)}allp.po1.c2.onClick =function() {pointClear(this)}allp.po1.c3.onClick =function() {pointClear(this)}allp.po2.c4.onClick =function() {pointClear(this)}allp.po2.c5.onClick =function() {pointClear(this)}allp.po2.c6.onClick =function() {pointClear(this)}allp.po3.c7.onClick =function() {pointClear(this)}allp.po3.c8.onClick =function() {pointClear(this)}allp.po3.c9.onClick =function() {pointClear(this)}//格式选项调换win.group.other.g.jpeg.onClick =function() { changeType("jpeg");}win.group.other.g.gif.onClick =function() { changeType("gif");}win.group.other.g.psd.onClick =function() { changeType("psd");}win.group.other.g.tiff.onClick =function() { changeType("tiff");}//格式选项调节function changeType(type){ saveType=type; var don=win.group.otherSet.Quality; switch (type) { case "jpeg" : don.c.text ='调换 ICC 配置' ; don.c.helpTip ='在蕴藏前将 ICC 配置文件转变为 s宝马X5GB' don.c.value =false; don.s.text ='压缩质量:'; don.d.helpTip ='JPEG 压缩品质(值越大减价扣后品质越高)'; don.d.removeAll(); for (i=0;i<13;i++){ don.d.add("item", i ); } don.d.items[7].selected=true; don.s.show(); don.d.show(); don.c2.hide(); win.text=title+'另存为 JPG 格式'; break; case "gif" : don.c.text ='启用扩散仿色' ; don.c.helpTip ='积存为 GIF 格式时行使扩散防色算法' don.c.value =true; don.s.text ='颜色位数:'; don.d.helpTip ='GIF 颜色位数 (值越大减价扣后品质越高)'; don.d.removeAll(); for (i=2;i<257;i=i*2){ don.d.add("item",i); } don.d.items[7].selected=true; don.c2.value =true; don.s.show(); don.d.show(); don.c2.show(); win.text=title+'另存为 GIF 格式'; break; case "psd" : don.c.text='最大包容' ; don.c.helpTip ='积累为 PSD 格式是贯彻最大兼容' don.c.value =true; don.s.hide(); don.d.hide(); don.c2.hide(); win.text=title+'另存为 PSD 格式'; break; case "tiff" : don.c.text='LZW压缩' ; don.c.helpTip ='用 TIFF 格式储存时使用 LZW 压缩' don.c.value =false; don.s.hide(); don.d.hide(); don.c2.hide(); win.text=title+'另存为 TIFF 格式'; } win.reload(); }function fillPattern(name,id,opacity) {//填充图案 var desc4 = new ActionDescriptor(); desc4.putEnumerated( charIDToTypeID( "Usng" ), charIDToTypeID( "FlCn" ), charIDToTypeID( "Ptrn" ) ); var desc5 = new ActionDescriptor(); desc5.putString( charIDToTypeID( "Nm" ), name ); //desc5.putString(charIDToTypeID( "Idnt" ), id ); desc4.putObject( charIDToTypeID( "Ptrn" ), charIDToTypeID( "Ptrn" ), desc5 ); desc4.putUnitDouble( charIDToTypeID( "Opct" ), charIDToTypeID( "#Prc" ), opacity ); desc4.putEnumerated( charIDToTypeID( "Md" ), charIDToTypeID( "BlnM" ), charIDToTypeID( "Nrml" ) ); executeAction( charIDToTypeID( "Fl" ), desc4, DialogModes.NO );};function setPattern(name) { //定义图案 var desc13 = new ActionDescriptor(); var ref7 = new ActionReference(); ref7.putClass( charIDToTypeID("Ptrn") ); desc13.putReference( charIDToTypeID("null"), ref7 ); var ref8 = new ActionReference(); ref8.putProperty( charIDToTypeID("Prpr"),charIDToTypeID("fsel") ); ref8.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); desc13.putReference( charIDToTypeID("Usng"), ref8 ); desc13.putString( charIDToTypeID("Nm"), name );executeAction( charIDToTypeID("Mk"), desc13, DialogModes.NO ); }function delPattern(){ //删除图案 var desc92 = new ActionDescriptor(); var ref53 = new ActionReference(); ref53.putIndex( charIDToTypeID( "Ptrn" ), 178 ); desc92.putReference( charIDToTypeID( "null" ), ref53 );executeAction( charIDToTypeID( "Dlt " ), desc92, DialogModes.NO );}// 实际管理起来function newsize(docRef,a,b,x,y){ //退换图象尺寸函数 var PW=x; var PH=y; if (x<1 || y<1) b=true; //有二个值空缺的时候,不剖断横竖 if (!b && x<y){//确保PW>=PH PW=y; PH=x; } var dw = docRef.width; var dh = docRef.height; var fw = PW; var fh = PH; if(!b && dh>dw){ fw = PH; fh = PW; } if (x<1) fw=dw; //尺寸小于1则为 不做改换 if (y<1) fh=dh; if(a){ w1 =dw/fw; h1 =dh/fh; if(w1>h1){ fh =dh/w1; }else{ fw =dw/h1; } if (x<1 && y>=1) {fw=dw/h1;fh=y;} //有1个值不做限定的情景 if (y<1 && x>=1) {fh =dh/w1;fw=x;} } docRef.resizeImage(fw, fh, PRESOLUTION, ResampleMethod.BICUBIC);}function shui(){ //水印管理函数 if (!win.group.shuiSet.other.open.e.text) { alert("您未有采用水印文件"); }else{ var shuiFlie = File(win.group.shuiSet.other.open.e.text); docShui= open(shuiFlie); docShui.changeMode(ChangeMode.EscortGB); if (docShui.layers.length>1) docShui.mergeVisibleLayers(); //合併可见层 var shuiLayer = docShui.activeLayer; if (parseInt(shuiLayer.bounds.toString().replace(/D/g,"")) == 0) { docShui.close(SaveOptions.DONOTSAVECHANGES); if(confirm("水印文件内容为空,继续操作将不会增加另外水印")) go(false);//继续操作,只是不加多水印 }else{ //拷贝水印 var suo=Number(win.group.shuiSet.other.hun.e.text); if (!suo) suo=1; //容错 if (suo<0) suo=1; docShui.resizeImage(docShui.width*suo,docShui.height*suo,PRESOLUTION, ResampleMethod.BICUBIC); //转变水印大小 var sW=Number(shuiLayer.bounds[2]-shuiLayer.bounds[0]); var sH=Number(shuiLayer.bounds[3]-shuiLayer.bounds[1]); docShui.selection.selectAll(); docShui.selection.copy(); docShui.close(SaveOptions.DONOTSAVECHANGES); //新建文书档案定义水印为雕塑 if (win.group.shui.g.fill.value){ var newD奥迪Q5 = app.documents.add(Number(win.group.shuiSet.other.dis.e1.text)+sW, Number(win.group.shuiSet.other.dis.e2.text)+sH, 72, "ShuiTu", NewDocumentMode.3 WheelerGB, DocumentFill.TRANSPARENT); newD锐界.paste(); newD凯雷德.selection.selectAll(); set帕特tern("BlueIdea-Script-Watermark-"+nowTime.toString()); newDTucson.close(SaveOptions.DONOTSAVECHANGES); newD昂Cora= null; } go(true,sW,sH); } }}function pasteShui(nWidth,nHeight,moveX,moveY,sW,sH,sHun){ //粘远期贴水印及偏移or 填充 app.activeDocument.changeMode(ChangeMode.HavalGB); if(win.group.shui.g.one.value){ switch (true) { case (allp.po1.c1.value||allp.po2.c4.value||allp.po3.c7.value): NowMX=moveX-nWidth/2+sW/2; break; case (allp.po1.c2.value||allp.po2.c5.value||allp.po3.c8.value): NowMX=moveX; break; case (allp.po1.c3.value||allp.po2.c6.value||allp.po3.c9.value): NowMX=nWidth/2-moveX-sW/2; break; default : NowMX=0; } switch (true) { case (allp.po1.c1.value||allp.po1.c2.value||allp.po1.c3.value): NowMY=moveY-nHeight/2+sH/2; break; case (allp.po2.c4.value||allp.po2.c5.value||allp.po2.c6.value): NowMY=moveY; break; case (allp.po3.c7.value||allp.po3.c8.value||allp.po3.c9.value): NowMY=nHeight/2-moveY-sH/2; break; default : NowMY=0; } app.activeDocument.paste(); app.activeDocument.activeLayer.translate (NowMX,NowMY); }else{ app.activeDocument.artLayers.add(); app.activeDocument.selection.selectAll(); fillPattern("BlueIdea-Script-Watermark-"+nowTime.toString(),"id",100); } app.activeDocument.activeLayer.blendMode =eval("BlendMode."+sHun);}function save(docRef) { //积累函数 if (win.group.other.c.value){ //剖断是不是另存 var don=win.group.otherSet.Quality; var inEmbedICC=win.group.otherSet.icc.value; var saveOptions; switch (saveType) { case "jpeg" : docRef.flatten() ;//合并图层,以积累jpg docRef.changeMode(ChangeMode.RAV4GB); // 退换为rgb格局,防止其余形式无法积累 docRef.bitsPerChannel = BitsPerChannelType.EIGHT; saveOptions = new JPEGSaveOptions(); saveOptions.quality = don.d.selection.index; //获取压缩品质 if (don.c.value) { docRef.convertProfile("s奥德赛GB IEC61969-2.1", Intent.RELATIVECOLOCR-VIMETRubiconIC, true, true); } saveOptions.embedColorProfile = inEmbedICC; var typeName="jpg"; //定义后缀 break; case "gif" : if (docRef.artLayers.length>1)docRef.mergeVisibleLayers(); //合并可知层 docRef.changeMode(ChangeMode.LANDGB); saveOptions = new GIFSaveOptions(); saveOptions.colors = Math.pow(2,don.d.selection.index+1); if (don.c.value){ saveOptions.dither = Dither.DIFFUSION; //扩散仿色 }else{ saveOptions.dither = Dither.NONE; } ; if (don.c2.value) { saveOptions.transparency=1; }else{ saveOptions.transparency=0; }; //saveOptions.matte = MatteType.NONE; //杂边无,不然为乌紫saveOptions.interlaced = 0; //不交错 var typeName="gif"; break; case "psd" : saveOptions = new PhotoshopSaveOptions(); saveOptions.embedColorProfile = inEmbedICC; var typeName="psd"; break; case "tiff" : docRef.flatten() ; saveOptions = new TiffSaveOptions(); saveOptions.embedColorProfile = inEmbedICC; if (don.c.value) { saveOptions.imageCompression = TIFFEncoding.TIFFLZW; } else { saveOptions.imageCompression = TIFFEncoding.NONE; } var typeName="tif"; break; default : alert ("-_-!!! SaveType"); } // 获取另存文件夹及左右追加字段 var headWord = win.group.otherSet.head.e.text; var footWord = win.group.otherSet.foot.e.text; if (win.group.otherSet.otherF.c.value){ //倘使选中另存至文件夹 if (win.group.otherSet.folderS.s.text){ var saveFolder = win.group.otherSet.folderS.s.text+"/"; }else{ var saveFolder = docRef.path+"/newsize_";//容错,幸免未有现实选择另存到足够文件夹 } }else{ if (headWord || footWord){ var saveFolder = docRef.path+"/"; }else{ var saveFolder = docRef.path+"/newsize_"; //容错,幸免没有增加前后缀而保留在本文件夹 } } if (docRef.name.lastIndexOf('.')==-1){//依据原版的书文件名有否后缀,决断是不是去掉后缀 var oldname=docRef.name; }else{ var oldname=docRef.name.substring(0,docRef.name.lastIndexOf('.')); } docRef.saveAs(new File(saveFolder + headWord + oldname + footWord + "."+ typeName),saveOptions, true,Extension.LOWERCASE); //设定输出文件名称 }else{ docRef.save(); } docRef.close(SaveOptions.DONOTSAVECHANGES); //关闭当前文书档案 }function go(shuiOK,sW,sH) { //最终循环管理及倒闭 var x=Number(win.group.corrdination.x.e.text); var y=Number(win.group.corrdination.y.e.text); var a=win.group.a.c.value; var b=win.group.b.c.value; //选中则不颠倒横竖,以输入值为准 if (saveType=="psd"){ //改动首荐项 var remember马克西姆ize = app.preferences.maximizeCompatibility; //psd格式最大包容 原始选项 --记录 var need马克西姆ize = win.group.otherSet.Quality.c.value? QueryStateType.ALWAYS : QueryStateType.NEVE宝马X5; if ( app.preferences.maximizeCompatibility != need马克西姆ize ) { app.preferences.maximizeCompatibility = need马克西姆ize; } } if (shuiOK){ //获取水印偏移量及混合格局 var mdis =win.group.shuiSet.other.dis; var moveX=Number(mdis.e1.text),moveY=Number(mdis.e2.text); for (i=0;i<23;i++) { if (win.group.shuiSet.other.hun.d.items.selected==true){ var sHun=sBlend.substring(sBlend.indexOf(",")+1); break; } } } if (!win.group.now.c.value) {// 当前移动文书档案为操作对象 var k=100/app.documents.length; //定义每一种文件所占进度比例 while (app.documents.length){ var docRef = app.activeDocument; newsize(docRef,a,b,x,y); if(shuiOK) pasteShui(Number(docRef.width),Number(docRef.height),moveX,moveY,sW,sH,sHun); save(docRef); win.group.timeline.value =win.group.timeline.value+k; } }else{ // 文件夹为操作对象 var openFolder = Folder(win.group.folderO.s.text); var fileList = openFolder.getFiles() //获取open文件夹下全体文件 var k=100/fileList.length; for (i=0;i<fileList.length;i++){ if (fileList instanceof File && fileList.hidden == false){ //不管理隐敝文件 open(fileList); var docRef = app.activeDocument; newsize(docRef,a,b,x,y); if(shuiOK) pasteShui(Number(docRef.width),Number(docRef.height),moveX,moveY,sW,sH,sHun); save(docRef); } win.group.timeline.value =win.group.timeline.value+k; } } if ( rememberMaximize != undefined )app.preferences.maximizeCompatibility = remember马克西姆ize;//psd格式最大包容选项还原 app.preferences.rulerUnits = startRulerUnits; app.preferences.typeUnits = startTypeUnits; if (shuiOK && win.group.shui.g.fill.value) delPattern(); //清除图案定义 this.parent.parent.close();}win.buttons.Btnok.onClick = function () { if (win.group.shui.c.value) { shui(); //管理水印及最后实现 }else{ go(false); }}win.center();win.show();**

本文由7m足球比分7m发布于关于生活,转载请注明出处:批量改观图片尺寸的photoshop,javascript使用smiple

相关阅读