 #
 # The pros and cons can be filtered to specific opinion regions
 # (individual and collective). 
+#
+# TODO: 
+#   - is it correct to store selected_opinion, selected_opinions, 
+#     highlighted_users at the histogram's key? 
+#   - reconsider how "selection" is incorporated. Selection seems 
+#     almost like a mixin. Now it is baked in, with the option to
+#     opt out if necessary, but the code wouldn't be very nice
+#     to work with to extend in a different direction other than
+#     selection. 
 #
 ##
 # Props

      y: y
    }



  # Called after the simulation stops
  end = ->
    total_energy = calculate_global_energy()

      else 
        highlighted_users = (fetch(o).user for o in selected_users)


    # There are a few avatar styles that might be applied depending on state:
    # 1) Regular, for when no user is selected
    regular_avatar_style =
      width: @local.avatar_size
      height: @local.avatar_size
      position: 'absolute'
      cursor: if @props.enable_selection then 'pointer' else 'auto'

    # 2) The style of a selected avatar
    selected_avatar_style = _.extend {}, regular_avatar_style, 
      zIndex: 9
      backgroundColor: focus_blue
    css.crossbrowserify selected_avatar_style
    # 3) The style of an unselected avatar when some other avatar(s) is selected
    unselected_avatar_style = css.grayscale _.extend {}, regular_avatar_style, 
      opacity: .2
    # 4) The style of the avatar when the histogram is backgrounded 
    #    (e.g. on the crafting page)
    backgrounded_page_avatar_style = _.extend {}, unselected_avatar_style, 
      opacity: .1

    # Draw the avatars in the histogram. Placement will be determined later
    # by the physics sim
    DIV 
      ref: 'histo'
      style: 
        height: @props.height
        position: 'relative'
        top: -1
        cursor: if !@props.backgrounded && 
                    @props.enable_selection then 'pointer'

      for opinion in @props.opinions
        user = opinion.user
        fetch(opinion) # subscribe to changes so physics sim will get rerun...

        if @props.backgrounded
          avatar_style = if fetch('/current_user').user == user 
                           _.extend({}, regular_avatar_style, {opacity: .25}) 
                         else 
                           backgrounded_page_avatar_style
        else if highlighted_users
          if _.contains(highlighted_users, opinion.user)   
            avatar_style = selected_avatar_style
          else
            avatar_style = unselected_avatar_style
        else
          avatar_style = regular_avatar_style

        Avatar 
          key: user
          user: user
          hide_tooltip: @props.backgrounded
          style: avatar_style

  onClick: (ev) -> 

