All pastes #505886 Raw Edit

Piechart

public text v1 · immutable
·published 2007-05-23 19:48 UTC
rendered paste body
; /piechart

; Description: Draws a percentage of strings by giving their ratio

; Install: just copy/paste the code in your remote editor (alt+r)

; Examples: /piechart mirc=60 chat=40

/piechart mirc=60 chat=15 people=25


; Notes: The ratio(s) must be equal or less than 100

; please if you find bugs contact me or send mail to upx@dynamicz.org , or you can find me /server -j mbc.wearab.net #regex


alias piechart {
  tokenize 32 $1-
  var %c = 1
  while %c <= $0 {
    var %t = $calc($gettok($($ $+ %c,2),2,$asc(=)) + %t)
    inc %c
  }
  if (%t > 100 || %t <= 0) { !echo 2 -a *** /piechart: must $!calc(n1 + n2 + ...nn) be 0 < $!calc(n1 + n2 + ...nn) <= 100 -> %t }
  else {
    window -aep $iif(!$window(@c),@c)
    var %c = 10
    while %c <= 300 {
      !drawdot -n @c 1 2 $calc($window(@c).x + 50) $calc(%c + 10)
      inc %c
    }
    var %c = 1
    while %c <= 10 {
      !set %pp $+ %c $calc($window(@c).x + 50) $calc(%c * 29)
      !drawdot -n @c 8 3 $calc($window(@c).x + 50) $calc(%c * 29)
      inc %c
    }
    var %c = 10
    while %c <= $calc($0 * 100) {
      !drawdot -n @c 1 2 $calc($window(@c).x + %c + 40) 310
      inc %c
    }
    var %c = 1
    while %c <= $0 {
      !set %i $+ %c $calc($window(@c).x + $calc(%c * 100)) 310
      !drawdot -n @c 8 5 $calc($window(@c).x + $calc(%c * 100)) 310
      !drawtext -np @c 1 Verdana 9 $calc($window(@c).x + $calc(%c * 100)) 310 $($ $+ %c,2)
      if ($len($gettok($($ $+ %c,2),2,$asc(=))) == 1) {
        !drawline -n @c $r(2,15) 2 45 $calc(310 - $calc($gettok($($ $+ %c,2),2,$asc(=)) + 2)) $var(%i*,%c).value
        inc %c
      }
      else {
        !drawline -n @c $r(2,15) 2 $calc($window(@c).x + $calc(%c * 100)) 310 $gettok($($+(%,pp,$calc(10 - $calc($left($gettok($($ $+ %c,2),2,$asc(=)),1))+1)),2),1,32) $calc($gettok($($+(%,pp,$calc(10 - $calc($left($gettok($($ $+ %c,2),2,$asc(=)),1))+1)),2),2,32) - $calc($right($gettok($($ $+ %c,2),2,$asc(=)),1) + 10)) 
        inc %c
      }
    }
    !drawdot @c
  }
}

; eof - have phun!