<commit_before>D3.mekko =
  # This represents a carrier within a sector, ie a chart rectangle
  #
  Node: class extends Backbone.Model
    initialize: =>
      @view = @get 'view'
      @sector  = @view.sector_list.find((s) => s.get('key') == @get('sector'))
      @carrier = @view.carrier_list.find((s) => s.get('key') == @get('carrier'))
      @sector.nodes.push this
      @carrier.nodes.push this

    val:   => @get('gquery').safe_future_value()
    label: => @get('label') || @get('gquery')
    key:   => "#{@get 'carrier'}_#{@get 'sector'}"

  View: class extends D3ChartView
    initialize: ->
      @series = @model.series.models
      @initialize_defaults()

    tableOptions:
      labelFormatter: -> (s) -> "#{ s.get('label') } - #{ s.get('group') }"

    can_be_shown_as_table: -> true

    # To render the mekko we need three collections:
    # - sectors  (~= the column, if you want to see it this way)
    # - carriers (used for legend only)
    # - nodes    (all the rectangles of the chart)
    # This methods builds them using the chart series.
    #
    prepare_data: =>
      @sector_list  = new D3.mekko.GroupCollection()
      @carrier_list = new D3.mekko.GroupCollection()
      @node_list    = new D3.mekko.NodeList()

      # Intermediate objects we use later to build the Backbone collections
      #
      sectors  = []
      carriers = []
      for s in @series
        sectors.push s.get('group_translated')
        carriers.push
          label: s.get('label')
          color: s.get('color')
          view: this

      # Build sector and carrier collections
      #
      sectors = _.uniq sectors
      for sector in sectors
        @sector_list.add
          key: sector
          view: this

      carriers = _.uniq(carriers, false, (c) -> c.label)
      for carrier in carriers
        @carrier_list.add
          key: carrier.label
          label: carrier.label # used by the legend
          color: carrier.color
          view: this

      # Add all nodes to the global collection
      #
      for s in @series
        @node_list.add
          sector: s.get('group_translated')
          carrier: s.get('label')
          gquery: s.get('gquery')
          color: s.get('color')
          view: this

    margins:
      top: 10
      bottom: 10
      left: 35
      right: 10

    col_value_scaler: =>
      max_y_value = _.max(@sector_list.map((a) -> a.total_value()))
      Quantity.scaleAndFormatBy(max_y_value, @model.get('unit'))

    draw: =>
      @prepare_data()
      [@width, @height] = @available_size()

      legend_columns = if @carrier_list.length > 9 then 3 else 2
      legend_rows = @carrier_list.length / legend_columns
      legend_height = legend_rows * @legend_cell_height
      @label_height = 80 # rotated labels
      @label_margin = 25

      @series_height  = @height - legend_height - @label_height - @label_margin
      @label_offset   = @series_height + @label_margin

      @svg = @create_svg_container @width, @series_height + @label_height, @margins

      @draw_legend
        series: @carrier_list.models
        width: @width
        vertical_offset: @series_height + @label_height
        columns: legend_columns

      @x = d3.scale.linear().range([0, @width])
      @y = d3.scale.linear().range([0, @series_height])

      y_scale = d3.scale.linear().domain([100,0]).range([0, @series_height])

      # axis
      @y_axis = d3.svg.axis().scale(y_scale).ticks(4).orient("left")
        .tickFormat((x) -> "#{x}%")<commit_msg>Make height sufficient enough to fit the word 'Households'<commit_after>D3.mekko =
  # This represents a carrier within a sector, ie a chart rectangle
  #
  Node: class extends Backbone.Model
    initialize: =>
      @view = @get 'view'
      @sector  = @view.sector_list.find((s) => s.get('key') == @get('sector'))
      @carrier = @view.carrier_list.find((s) => s.get('key') == @get('carrier'))
      @sector.nodes.push this
      @carrier.nodes.push this

    val:   => @get('gquery').safe_future_value()
    label: => @get('label') || @get('gquery')
    key:   => "#{@get 'carrier'}_#{@get 'sector'}"

  View: class extends D3ChartView
    initialize: ->
      @series = @model.series.models
      @initialize_defaults()

    tableOptions:
      labelFormatter: -> (s) -> "#{ s.get('label') } - #{ s.get('group') }"

    can_be_shown_as_table: -> true

    # To render the mekko we need three collections:
    # - sectors  (~= the column, if you want to see it this way)
    # - carriers (used for legend only)
    # - nodes    (all the rectangles of the chart)
    # This methods builds them using the chart series.
    #
    prepare_data: =>
      @sector_list  = new D3.mekko.GroupCollection()
      @carrier_list = new D3.mekko.GroupCollection()
      @node_list    = new D3.mekko.NodeList()

      # Intermediate objects we use later to build the Backbone collections
      #
      sectors  = []
      carriers = []
      for s in @series
        sectors.push s.get('group_translated')
        carriers.push
          label: s.get('label')
          color: s.get('color')
          view: this

      # Build sector and carrier collections
      #
      sectors = _.uniq sectors
      for sector in sectors
        @sector_list.add
          key: sector
          view: this

      carriers = _.uniq(carriers, false, (c) -> c.label)
      for carrier in carriers
        @carrier_list.add
          key: carrier.label
          label: carrier.label # used by the legend
          color: carrier.color
          view: this

      # Add all nodes to the global collection
      #
      for s in @series
        @node_list.add
          sector: s.get('group_translated')
          carrier: s.get('label')
          gquery: s.get('gquery')
          color: s.get('color')
          view: this

    margins:
      top: 10
      bottom: 10
      left: 35
      right: 10

    col_value_scaler: =>
      max_y_value = _.max(@sector_list.map((a) -> a.total_value()))
      Quantity.scaleAndFormatBy(max_y_value, @model.get('unit'))

    draw: =>
      @prepare_data()
      [@width, @height] = @available_size()

      legend_columns = if @carrier_list.length > 9 then 3 else 2
      legend_rows = @carrier_list.length / legend_columns
      legend_height = legend_rows * @legend_cell_height
      @label_height = 85 # rotated labels
      @label_margin = 25

      @series_height  = @height - legend_height - @label_height - @label_margin
      @label_offset   = @series_height + @label_margin

      @svg = @create_svg_container @width, @series_height + @label_height, @margins

      @draw_legend
        series: @carrier_list.models
        width: @width
        vertical_offset: @series_height + @label_height
        columns: legend_columns

      @x = d3.scale.linear().range([0, @width])
      @y = d3.scale.linear().range([0, @series_height])

      y_scale = d3.scale.linear().domain([100,0]).range([0, @series_height])

      # axis
      @y_axis = d3.svg.axis().scale(y_scale).ticks(4).orient("left")
        .tickFormat((x) -> "#{x}%")
{'fraction_non_alphanumeric': 0.1299106509714934, 'fraction_numerical': 0.009076726705431854, 'mean_word_length': 2.3596950929013816, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, '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': '114955', 'n_tokens_mistral': 2315, 'n_tokens_neox': 2191, 'n_words': 545}