lib/scrivstats/scriven.rb
# Answer a bargraph rendering of the document structure.
# This gives a quick visual of the relative sizes of chapters and scenes.
Answer a bargraph rendering of the document structure.
This gives a quick visual of the relative sizes of chapters and scenes.
Answer a bargraph rendering of the document structure . This gives a quick visual of the relative sizes of chapters and scenes .
def stats_bargraph
      bar_graph = ''
      total_words = @wc
      chapters.each do |chapter|
        chapter.fraction_of_total(total_words)
        chapter.scenes.each { |scene| scene.fraction_of_total(chapter.wc) }
      end
      bar_length = 100
      longest_chapter = chapters.max_by(&:wc)
      words_per_chart_segment = longest_chapter.wc / bar_length
      chapter_bar_scale_factor = bar_length / longest_chapter.fraction
      chapters.each do |chapter|
        chapter_bar_length = chapter_bar_scale_factor * chapter.fraction
        bar = chapter.scenes.collect do |scene|
          bar_len = chapter_bar_length * scene.fraction
          "*" * bar_len
        end
        bar_graph += format("[%-10s] %s\n", chapter.title, bar.join("_"))
      end
      bar_graph += format("\n  * = %d words (min)",words_per_chart_segment)
      bar_graph
    end
def stats_bargraph bar_graph = '' total_words = @wc chapters . each do | chapter | chapter . fraction_of_total ( total_words ) chapter . scenes . each { | scene | scene . fraction_of_total ( chapter . wc ) } end bar_length = 100 longest_chapter = chapters . max_by ( & :wc ) words_per_chart_segment = longest_chapter . wc / bar_length chapter_bar_scale_factor = bar_length / longest_chapter . fraction chapters . each do | chapter | chapter_bar_length = chapter_bar_scale_factor * chapter . fraction bar = chapter . scenes . collect do | scene | bar_len = chapter_bar_length * scene . fraction "*" * bar_len end bar_graph += format ( "[%-10s] %s\n" , chapter . title , bar . join ( "_" ) ) end bar_graph += format ( "\n  * = %d words (min)" , words_per_chart_segment ) bar_graph end
Answer a bargraph rendering of the document structure.
Answer a bargraph rendering of the document structure .
# Traverse the structure and compute percentage: #   - of each chapter relative to the whole #   - of each scene relative to its chapter # Largest chapter renders a bar of this length # Longest chapter gets full bar length. # Other chapters are scaled relative to longest # Compute a bar graph showing relative sizes of chapter (to the whole) and # relative sizes of scenes (to the chapter) # Show length of chapter relative to its percentage of the document # Show length of each scene relative to relative size of chapter # bar_graph += format("[%-10s] %s\n", chapter.title, bar.join("\u2581"))