Method: Tk::BLT::PlotComponent::Axis.new

Defined in:
ext/lib/tkextlib/blt/component.rb

.new(chart, axis = nil, keys = {}) ⇒ Object



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'ext/lib/tkextlib/blt/component.rb', line 402

def self.new(chart, axis=nil, keys={})
  if axis.kind_of?(Hash)
    keys = axis
    axis = nil
  end
  if keys
    keys = _symbolkey2str(keys)
    not_create = keys.delete('without_creating')
  else
    not_create = false
  end

  obj = nil
  AxisID_TBL.mutex.synchronize{
    chart_path = chart.path
    AxisID_TBL[chart_path] ||= {}
    if axis && AxisID_TBL[chart_path][axis]
      obj = AxisID_TBL[chart_path][axis]
    else
      (obj = self.allocate).instance_eval{
        if axis
          @axis = @id = axis.to_s
        else
          OBJ_ID.mutex.synchronize{
            @axis = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
            OBJ_ID[1].succ!
          }
        end
        @path = @id
        @parent = @chart = chart
        @cpath = @chart.path
        Axis::AxisID_TBL[@cpath][@axis] = self
        unless not_create
          tk_call(@chart, 'axis', 'create', @axis, keys)
          return obj
        end
      }
    end
  }

  obj.configure(keys) if obj && ! keys.empty?
  obj
end