Branch: Tag:

2005-11-15

2005-11-15 15:45:04 by Martin Nilsson <mani@lysator.liu.se>

["x"] => ->x

Rev: lib/modules/Graphics.pmod/Graph.pmod/create_graph.pike:1.14
Rev: lib/modules/Graphics.pmod/Graph.pmod/create_pie.pike:1.12

1:   //! Graph sub-module for drawing pie-charts. - // $Id: create_pie.pike,v 1.11 2005/11/15 00:43:17 nilsson Exp $ + // $Id: create_pie.pike,v 1.12 2005/11/15 15:45:04 nilsson Exp $   //   // These functions were written by Henrik "Hedda" Wallin (hedda@roxen.com)   // Create_pie can draw pie charts in different forms.
13:   mapping(string:mixed) create_pie(mapping(string:mixed) diagram_data)   {    //Only tested with xsize>=100 -  int si=diagram_data["fontsize"]; +  int si=diagram_data->fontsize;       string where_is_ax;       Image.Image piediagram;       init_bg(diagram_data); -  piediagram=diagram_data["image"]; +  piediagram=diagram_data->image;    setinitcolors(diagram_data);       set_legend_size(diagram_data);    -  diagram_data["ysize"]-=diagram_data["legend_size"]; +  diagram_data->ysize-=diagram_data->legend_size;       //Do the standard init (The init function is in create_graph)    init(diagram_data);       //Initiate values -  int|void size=diagram_data["xsize"]; -  array(int|float) numbers=diagram_data["data"][0]; -  void | array(string) names=diagram_data["xnames"]; -  void|int twoD=diagram_data["drawtype"]=="2D"; -  void|array(array(int)) colors=diagram_data["datacolors"]; -  array(int)bg=diagram_data["bgcolor"]; -  array(int)fg=diagram_data["textcolor"]; -  int tone=diagram_data["tone"]; +  int|void size=diagram_data->xsize; +  array(int|float) numbers=diagram_data->data[0]; +  void | array(string) names=diagram_data->xnames; +  void|int twoD=diagram_data->drawtype=="2D"; +  void|array(array(int)) colors=diagram_data->datacolors; +  array(int)bg=diagram_data->bgcolor; +  array(int)fg=diagram_data->textcolor; +  int tone=diagram_data->tone;       for(int i; i<sizeof(numbers); i++)    if ((float)numbers[i]<0.0)
84:    if (names)    text=allocate(sizeof(names));    -  if (diagram_data["3Ddepth"]>diagram_data["ysize"]/5) -  diagram_data["3Ddepth"]=diagram_data["ysize"]/5; +  if (diagram_data["3Ddepth"]>diagram_data->ysize/5) +  diagram_data["3Ddepth"]=diagram_data->ysize/5;       notext=GETFONT(xnamesfont);    if (names)
94:    {    if ((names[i]!=0) && (names[i]!=""))    text[i]=notext -  ->write(UNICODE((string)(names[i]),diagram_data["encoding"])) -  ->scale(0,diagram_data["fontsize"]); +  ->write(UNICODE((string)(names[i]),diagram_data->encoding)) +  ->scale(0,diagram_data->fontsize);    else -  text[i]=Image.Image(diagram_data["fontsize"], -  diagram_data["fontsize"]); +  text[i]=Image.Image(diagram_data->fontsize, +  diagram_data->fontsize);       if (text[i]->xsize()<1) -  text[i]=Image.Image(diagram_data["fontsize"], -  diagram_data["fontsize"]); +  text[i]=Image.Image(diagram_data->fontsize, +  diagram_data->fontsize);    -  if (text[i]->xsize()>diagram_data["xsize"]/5+diagram_data["3Ddepth"]) -  text[i]=text[i]->scale((int)diagram_data["xsize"]/5, 0); +  if (text[i]->xsize()>diagram_data->xsize/5+diagram_data["3Ddepth"]) +  text[i]=text[i]->scale((int)diagram_data->xsize/5, 0);    -  if (text[i]->ysize()>diagram_data["ysize"]/5-diagram_data["3Ddepth"]) -  text[i]=text[i]->scale(0, (int)diagram_data["ysize"]/5- +  if (text[i]->ysize()>diagram_data->ysize/5-diagram_data["3Ddepth"]) +  text[i]=text[i]->scale(0, (int)diagram_data->ysize/5-    diagram_data["3Ddepth"]);       if (xmaxtext<(text[i]->xsize()))
125:    //Some calculations    if (twoD)    { -  xc=diagram_data["xsize"]/2; -  yc=diagram_data["ysize"]/2+nameheight/2; -  xr=(int)min(xc-xmaxtext-ymaxtext-1-diagram_data["linewidth"], +  xc=diagram_data->xsize/2; +  yc=diagram_data->ysize/2+nameheight/2; +  xr=(int)min(xc-xmaxtext-ymaxtext-1-diagram_data->linewidth,    yc-2*ymaxtext- -  1-diagram_data["linewidth"]-nameheight); +  1-diagram_data->linewidth-nameheight);    yr=xr;    }    else    { -  xc=diagram_data["xsize"]/2; -  yc=diagram_data["ysize"]/2-diagram_data["3Ddepth"]/2+nameheight/2; +  xc=diagram_data->xsize/2; +  yc=diagram_data->ysize/2-diagram_data["3Ddepth"]/2+nameheight/2;    yr=(int)(min(xc-xmaxtext-ymaxtext-1-diagram_data["3Ddepth"]/2,    yc-2*ymaxtext-1-nameheight) -  -diagram_data["linewidth"]); +  -diagram_data->linewidth);    xr=(int)(min(xc-xmaxtext-ymaxtext-1,    yc+diagram_data["3Ddepth"]/2-    2*ymaxtext-1-nameheight)- -  diagram_data["linewidth"]); +  diagram_data->linewidth);    } -  float w=diagram_data["linewidth"]; +  float w=diagram_data->linewidth;       if (xr<2)    error("Image to small for this pie-diagram.\n"
190:       //Initiate the piediagram!    float FI=0; -  if (diagram_data["center"]) +  if (diagram_data->center)    {    //If to great center integer is given, module is used.    // Center should not be greater than sizeof(data[0]). -  diagram_data["center"]%=(1+sizeof(numbers)); -  FI=(400-`+(0,@pnumbers[0..diagram_data["center"]-2]) -  -pnumbers[diagram_data["center"]-1]*0.5)*2.0*PI/400.0; +  diagram_data->center%=(1+sizeof(numbers)); +  FI=(400-`+(0,@pnumbers[0..diagram_data->center-2]) +  -pnumbers[diagram_data->center-1]*0.5)*2.0*PI/400.0;    }    else -  if (diagram_data["rotate"]) -  FI=((float)(diagram_data["rotate"])*2.0*PI/360.0)%(2*PI); +  if (diagram_data->rotate) +  FI=((float)(diagram_data->rotate)*2.0*PI/360.0)%(2*PI);    float most_down=yc+yr+w;    float most_right=xc+xr+w;    float most_left=xc-xr-w;
216:    }       //Draw the slices -  if (sizeof(diagram_data["datacolors"])> -  sizeof(diagram_data["data"][0])) -  diagram_data["datacolors"]=diagram_data["datacolors"] -  [0..sizeof(diagram_data["data"][0])-1]; +  if (sizeof(diagram_data->datacolors)> +  sizeof(diagram_data->data[0])) +  diagram_data->datacolors=diagram_data->datacolors +  [0..sizeof(diagram_data->data[0])-1];    -  int t=sizeof(diagram_data["datacolors"]); +  int t=sizeof(diagram_data->datacolors);       float miniwxr;    float miniwyr;
288:    for(i=0; i<t; i++)    {    piediagram->setcolor( -  @diagram_data["datacolors"][i] +  @diagram_data->datacolors[i]    );       if (pnumbers[i])
307:       piediagram->setcolor(0,0,0);    piediagram->polyfill( -  make_polygon_from_line(diagram_data["linewidth"], +  make_polygon_from_line(diagram_data->linewidth,    ({    xc+(xr+w/2.0),    yc})+
321:    edge_nr=0;    for(i=0; i<t; i++)    { -  piediagram=piediagram->setcolor(@diagram_data["datacolors"][i]); +  piediagram=piediagram->setcolor(@diagram_data->datacolors[i]);    if (pnumbers[i])    piediagram=piediagram->polyfill(({(float)xc,(float)yc})+    arr[2*edge_nr..2*(edge_nr+pnumbers[i]+2)+1]);
333:    edge_nr=pnumbers[0];       //black borders -  if (diagram_data["linewidth"]>LITET) +  if (diagram_data->linewidth>LITET)    { -  piediagram->setcolor(@diagram_data["axcolor"]); +  piediagram->setcolor(@diagram_data->axcolor);    piediagram->polygone( -  make_polygon_from_line(diagram_data["linewidth"], +  make_polygon_from_line(diagram_data->linewidth,    ({    xc,    yc,
352:    {    piediagram->    polygone( -  make_polygon_from_line(diagram_data["linewidth"], +  make_polygon_from_line(diagram_data->linewidth,    ({xc    ,yc,    arr[2*(edge_nr)],
382:       object tbild;    -  int imxsize=piediagram->xsize(); //diagram_data["xsize"]; -  int imysize=piediagram->ysize(); //diagram_data["ysize"]+diagram_data["legendsize"]; +  int imxsize=piediagram->xsize(); //diagram_data->xsize; +  int imysize=piediagram->ysize(); //diagram_data->ysize+diagram_data->legendsize;       if(tone)    {
427:    +(miniwyr-w/2.0)*sin(-PI/2+edge_nr*2.0*PI/400.0);    piediagram=piediagram->    polygone( -  make_polygon_from_line(diagram_data["linewidth"], +  make_polygon_from_line(diagram_data->linewidth,    ({    x1,y1,    x2,y2
475:    piediagram=piediagram->paste_alpha_color(text[i], @fg, x, y);    }    -  diagram_data["ysize"]-=diagram_data["legend_size"]; -  diagram_data["image"]=piediagram; +  diagram_data->ysize-=diagram_data->legend_size; +  diagram_data->image=piediagram;    return diagram_data;   }