<commit_before>require "rsvg2"
require "rubyvis"
require "irb/ruby-lex"

module SciRuby
  class << self
    def Rubyvis
      ::Rubyvis
    end
  end

  class Plotter
    # Create a new plotter app.
    def initialize script_or_handle
      update = false
      handle = begin
        if script_or_handle.is_a?(RSVG::Handle)
          script_or_handle
        else
          update = File.mtime(script_or_handle)
          handle = SciRuby::Plotter.create_handle script_or_handle
        end
      end

      Shoes.app :title => "Plotter - SciRuby", :width => handle.width+20, :height => handle.height+20 do
        icon SciRuby::ICON_PATH
        strokewidth 1
        fill white
        r   = rect 10, 10, handle.width+2, handle.height+2
        img = image(:data => handle).tap { |i| i.move(11, 11) }
<commit_msg>Added documentation for creating a Plotter<commit_after>require "rsvg2"
require "rubyvis"
require "irb/ruby-lex"

module SciRuby
  class << self
    def Rubyvis
      ::Rubyvis
    end
  end

  class Plotter
    # Create a new plotter app.
    #
    # == Argument
    #
    # +script_or_handle+:: either a script filename which SciRuby::Plotter should
    #                      watch, or an RSVG::Handle which you have already created.
    #
    # == Examples
    #
    # Let's say you're in a Rails console and you want to use Plotter. You could do
    # something like this:
    #
    #     vis = Rubyvis::Panel.new do
    #       # your plot code here
    #     end
    #     vis.render
    #     svg_string = vis.to_svg
    #     svg_handle = RSVG::Handle.new_from_data svg_string
    #     SciRuby::Plotter.new svg_handle
    #
    # But you could also load a script as follows:
    #
    #    SciRuby::Plotter.new 'plot_xy.rb'
    #
    # If you take this route, you don't need to include a +render+ or a +to_svg+; these
    # are handled automatically when the script is evaluated.
    #
    # If you don't have your script saved, there's an additional option for static plots:
    #
    #    SciRuby::Plotter.new(SciRuby::Plotter.create_handle('(editor)', <<-ENDPLOT))
    #      Rubyvis::Panel.new do
    #        # plot code here
    #      end
    #    ENDPLOT
    #
    # Again, no +to_svg+ or +render+ is needed here.
    #
    def initialize script_or_handle
      update = false
      handle = begin
        if script_or_handle.is_a?(RSVG::Handle)
          script_or_handle
        else
          update = File.mtime(script_or_handle)
          handle = SciRuby::Plotter.create_handle script_or_handle
        end
      end

      Shoes.app :title => "Plotter - SciRuby", :width => handle.width+20, :height => handle.height+20 do
        icon SciRuby::ICON_PATH
        strokewidth 1
        fill white
        r   = rect 10, 10, handle.width+2, handle.height+2
        img = image(:data => handle).tap { |i| i.move(11, 11) }

{'fraction_non_alphanumeric': 0.0944386149003148, 'fraction_numerical': 0.011192724728926198, 'mean_word_length': 2.181312569521691, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6681418', 'n_tokens_mistral': 978, 'n_tokens_neox': 899, 'n_words': 259}