Method: CDK::GRAPH#initialize

Defined in:
lib/cdk/dialog.rb

#initialize(cdkscreen, xplace, yplace, height, width, title, xtitle, ytitle) ⇒ GRAPH

Returns a new instance of GRAPH.



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'lib/cdk/dialog.rb', line 345

def initialize(cdkscreen, xplace, yplace, height, width,
    title, xtitle, ytitle)
  super()
  parent_width = cdkscreen.window.getmaxx
  parent_height = cdkscreen.window.getmaxy

  self.setBox(false)

  box_height = CDK.setWidgetDimension(parent_height, height, 3)
  box_width = CDK.setWidgetDimension(parent_width, width, 0)
  box_width = self.setTitle(title, box_width)
  box_height += @title_lines
  box_width = [parent_width, box_width].min
  box_height = [parent_height, box_height].min

  # Rejustify the x and y positions if we need to
  xtmp = [xplace]
  ytmp = [yplace]
  CDK.alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height)
  xpos = xtmp[0]
  ypos = ytmp[0]

  # Create the widget pointer
  @screen = cdkscreen
  @parent = cdkscreen.window
  @win = Ncurses::WINDOW.new(box_height, box_width, ypos, xpos)
  @box_height = box_height
  @box_width = box_width
  @minx = 0
  @maxx = 0
  @xscale = 0
  @yscale = 0
  @count = 0
  @display_type = :LINE

  if @win.nil?
    self.destroy
    return nil
  end
  @win.keypad(true)

  # Translate the X axis title string to a chtype array
  if !(xtitle.nil?) && xtitle.size > 0
    xtitle_len = []
    xtitle_pos = []
    @xtitle = CDK.char2Chtype(xtitle, xtitle_len, xtitle_pos)
    @xtitle_len = xtitle_len[0]
    @xtitle_pos = CDK.justifyString(@box_height,
        @xtitle_len, xtitle_pos[0])
  else
    xtitle_len = []
    xtitle_pos = []
    @xtitle = CDK.char2Chtype("<C></5>X Axis", xtitle_len, xtitle_pos)
    @xtitle_len = title_len[0]
    @xtitle_pos = CDK.justifyString(@box_height,
        @xtitle_len, xtitle_pos[0])
  end

  # Translate the Y Axis title string to a chtype array
  if !(ytitle.nil?) && ytitle.size > 0
    ytitle_len = []
    ytitle_pos = []
    @ytitle = CDK.char2Chtype(ytitle, ytitle_len, ytitle_pos)
    @ytitle_len = ytitle_len[0]
    @ytitle_pos = CDK.justifyString(@box_width, @ytitle_len, ytitle_pos[0])
  else
    ytitle_len = []
    ytitle_pos = []
    @ytitle = CDK.char2Chtype("<C></5>Y Axis", ytitle_len, ytitle_pos)
    @ytitle_len = ytitle_len[0]
    @ytitle_pos = CDK.justifyString(@box_width, @ytitle_len, ytitle_pos[0])
  end

  @graph_char = 0
  @values = []

  cdkscreen.register(:GRAPH, self)
end