~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to ext/tk/lib/tkextlib/tcllib/plotchart.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2006-05-08 22:23:12 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060508222312-w2wqeaz030ifi59j
Tags: 1.9.0+20060423-3ubuntu1
* Resynchronized with Debian.
* Only change from Debian is the addition of
  debian/patches/903_sparc_fix_define.patch to fix illegal instructions
  at runtime on sparc. (change from 1.9.0+20050921-1ubuntu1)

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
require 'tkextlib/tcllib.rb'
62
62
 
63
63
# TkPackage.require('Plotchart', '0.9')
 
64
# TkPackage.require('Plotchart', '1.1')
64
65
TkPackage.require('Plotchart')
65
66
 
66
67
module Tk
272
273
      self
273
274
    end
274
275
 
 
276
    def contourlines(xcrd, ycrd, vals, clss=None)
 
277
      xcrd = array2tk_list(xcrd) if xcrd.kind_of?(Array)
 
278
      ycrd = array2tk_list(ycrd) if ycrd.kind_of?(Array)
 
279
      vals = array2tk_list(vals) if vals.kind_of?(Array)
 
280
      clss = array2tk_list(clss) if clss.kind_of?(Array)
 
281
 
 
282
      tk_call_without_enc(@chart, 'contourlines', xcrd, ycrd, vals, clss)
 
283
      self
 
284
    end
 
285
 
 
286
    def contourfill(xcrd, ycrd, vals, klasses=None)
 
287
      xcrd = array2tk_list(xcrd) if xcrd.kind_of?(Array)
 
288
      ycrd = array2tk_list(ycrd) if ycrd.kind_of?(Array)
 
289
      vals = array2tk_list(vals) if vals.kind_of?(Array)
 
290
      clss = array2tk_list(clss) if clss.kind_of?(Array)
 
291
 
 
292
      tk_call_without_enc(@chart, 'contourfill', xcrd, ycrd, vals, clss)
 
293
      self
 
294
    end
 
295
 
 
296
    def contourbox(xcrd, ycrd, vals, klasses=None)
 
297
      xcrd = array2tk_list(xcrd) if xcrd.kind_of?(Array)
 
298
      ycrd = array2tk_list(ycrd) if ycrd.kind_of?(Array)
 
299
      vals = array2tk_list(vals) if vals.kind_of?(Array)
 
300
      clss = array2tk_list(clss) if clss.kind_of?(Array)
 
301
 
 
302
      tk_call_without_enc(@chart, 'contourbox', xcrd, ycrd, vals, clss)
 
303
      self
 
304
    end
 
305
 
 
306
    def color_map(colors)
 
307
      colors = array2tk_list(colors) if colors.kind_of?(Array)
 
308
 
 
309
      tk_call_without_enc(@chart, 'colorMap', colors)
 
310
      self
 
311
    end
 
312
 
 
313
    def grid_cells(xcrd, ycrd)
 
314
      xcrd = array2tk_list(xcrd) if xcrd.kind_of?(Array)
 
315
      ycrd = array2tk_list(ycrd) if ycrd.kind_of?(Array)
 
316
 
 
317
      tk_call_without_enc(@chart, 'grid', xcrd, ycrd)
 
318
      self
 
319
    end
 
320
 
275
321
    def dataconfig(series, key, value=None)
276
322
      if key.kind_of?(Hash)
277
323
        tk_call_without_enc(@chart, 'dataconfig', series, *hash_kv(key, true))
479
525
      self
480
526
    end
481
527
 
 
528
    def plot_funcont(conts, cmd=Proc.new)
 
529
      conts = array2tk_list(conts) if conts.kind_of?(Array)
 
530
      Tk.ip_eval("proc #{@path}_#{@chart} {x y} {#{install_cmd(cmd)} $x $y}")
 
531
      tk_call_without_enc(@chart, 'plotfuncont', "#{@path}_#{@chart}", conts)
 
532
      self
 
533
    end
 
534
 
482
535
    def grid_size(nxcells, nycells)
483
536
      tk_call_without_enc(@chart, 'gridsize', nxcells, nycells)
484
537
      self
633
686
      # time_end   := String of time format (e.g. "1 january 2004")
634
687
      # items := Expected/maximum number of items
635
688
      #          ( This determines the vertical spacing. )
636
 
      if args[0].kind_of?(Array)
 
689
      if args[0].kind_of?(String)
637
690
        @time_begin = args.shift
638
691
        @time_end   = args.shift
639
692
        @items      = args.shift
680
733
  end
681
734
 
682
735
  ############################
 
736
  class Gnattchart < TkCanvas
 
737
    include ChartMethod
 
738
 
 
739
    TkCommandNames = [
 
740
      'canvas'.freeze,
 
741
      '::Plotchart::createGnattchart'.freeze
 
742
    ].freeze
 
743
 
 
744
    def initialize(*args)
 
745
      # args := ([parent,] time_begin, time_end, items [, text_width] [, keys])
 
746
      # time_begin := String of time format (e.g. "1 january 2004")
 
747
      # time_end   := String of time format (e.g. "1 january 2004")
 
748
      # items := Expected/maximum number of items
 
749
      #          ( This determines the vertical spacing. )
 
750
      if args[0].kind_of?(String)
 
751
        @time_begin = args.shift
 
752
        @time_end   = args.shift
 
753
        @items      = args.shift
 
754
 
 
755
        if args[0].kind_of?(Fixnum)
 
756
          @text_width = args.shift
 
757
        else
 
758
          @text_width = None
 
759
        end
 
760
 
 
761
        super(*args) # create canvas widget
 
762
      else
 
763
        parent = args.shift
 
764
 
 
765
        @time_begin = args.shift
 
766
        @time_end   = args.shift
 
767
        @items      = args.shift
 
768
 
 
769
        if args[0].kind_of?(Fixnum)
 
770
          @text_width = args.shift
 
771
        else
 
772
          @text_width = None
 
773
        end
 
774
 
 
775
        if parent.kind_of?(TkCanvas)
 
776
          @path = parent.path
 
777
        else
 
778
          super(parent, *args) # create canvas widget
 
779
        end
 
780
      end
 
781
 
 
782
      @chart = _create_chart
 
783
    end
 
784
 
 
785
    def _create_chart
 
786
      p self.class::TkCommandNames[1] if $DEBUG
 
787
      tk_call_without_enc(self.class::TkCommandNames[1], @path, 
 
788
                          @time_begin, @time_end, @items, @text_width)
 
789
    end
 
790
    private :_create_chart
 
791
 
 
792
    def task(txt, time_begin, time_end, completed=0.0)
 
793
      list(tk_call_without_enc(@chart, 'task', txt, time_begin, time_end, 
 
794
                               completed)).collect!{|id|
 
795
        TkcItem.id2obj(self, id)
 
796
      }
 
797
    end
 
798
 
 
799
    def milestone(txt, time, col=None)
 
800
      tk_call_without_enc(@chart, 'milestone', txt, time, col)
 
801
      self
 
802
    end
 
803
 
 
804
    def vertline(txt, time)
 
805
      tk_call_without_enc(@chart, 'vertline', txt, time)
 
806
      self
 
807
    end
 
808
 
 
809
    def connect(from_task, to_task)
 
810
      from_task = array2tk_list(from_task) if from_task.kind_of?(Array)
 
811
      to_task   = array2tk_list(to_task)   if to_task.kind_of?(Array)
 
812
 
 
813
      tk_call_without_enc(@chart, 'connect', from_task, to_task)
 
814
      self
 
815
    end
 
816
 
 
817
    def summary(txt, tasks)
 
818
      tasks = array2tk_list(tasks) if tasks.kind_of?(Array)
 
819
      tk_call_without_enc(@chart, 'summary', tasks)
 
820
      self
 
821
    end
 
822
 
 
823
    def color_of_part(keyword, newcolor)
 
824
      tk_call_without_enc(@chart, 'color', keyword, newcolor)
 
825
      self
 
826
    end
 
827
 
 
828
    def font_of_part(keyword, newfont)
 
829
      tk_call_without_enc(@chart, 'font', keyword, newfont)
 
830
      self
 
831
    end
 
832
  end
 
833
 
 
834
  ############################
683
835
  class PlotSeries < TkObject
684
836
    SeriesID_TBL = TkCore::INTERP.create_table
685
837
    Series_ID = ['series'.freeze, '00000'.taint].freeze