<commit_before><script lang="coffee">
import svg from 'svg.js'
import AppConfig from '@/shared/services/app_config'
import { sum, values, compact, keys, each } from 'lodash'
import { optionColors, optionImages } from '@/shared/helpers/poll'

export default
  props:
    stanceData: Object
    diameter: Number
  data: ->
    svgEl: null
    shapes: []
    pollColors: AppConfig.pollColors
    positionColors: optionColors()
  computed:
    radius: ->
      @diameter / 2.0

  methods:
    arcPath: (startAngle, endAngle) ->
      rad = Math.PI / 180
      x1 = @radius + (@radius * Math.cos(-startAngle * rad))
      x2 = @radius + (@radius * Math.cos(-endAngle * rad))
      y1 = @radius + (@radius * Math.sin(-startAngle * rad))
      y2 = @radius + (@radius * Math.sin(-endAngle * rad))
      ["M", @radius, @radius, "L", x1, y1, "A", @radius, @radius, 0, +(endAngle - startAngle > 180), 0, x2, y2, "z"].join(' ')
    draw: ->
      @shapes.forEach (shape) -> shape.remove()
      start = 90

      switch values(@stanceData).filter((v) -> v > 0).length
        when 0
          @shapes.push @svgEl.circle(@diameter).attr
            'stroke-width': 0
            fill: '#aaa'
        when 1
          each @stanceData, (count, position) =>
            return unless count > 0
            @shapes.push @svgEl.circle(@diameter).attr
              'stroke-width': 0
              fill: @positionColors[position]
        else
          each @stanceData, (count, position) =>
            return unless count > 0
            angle = 360/sum(values(@stanceData))*count
            @shapes.push @svgEl.path(@arcPath(start, start + angle)).attr
              'stroke-width': 0
              fill: @positionColors[position]
            start += angle
  watch:
    stanceData: -> @draw()

  mounted: ->
    @svgEl = svg(@$el).size('100%', '100%')
    @draw()

  beforeDestroy: ->
    @svgEl.clear()
    delete @shapes
</script>

<template lang="pug">
.poll-proposal-chart
</template>
<style lang="sass">
.poll-proposal-chart
	border: 0
	margin: 0
	padding: 0
	svg
		height: 100%
		width: 100%

</style>
<commit_msg>basic fix for proposal legend<commit_after><script lang="coffee">
import svg from 'svg.js'
import AppConfig from '@/shared/services/app_config'
import { sum, values, compact, keys, each } from 'lodash'
import { optionColors, optionImages } from '@/shared/helpers/poll'

export default
  props:
    stanceData: Object
    diameter: Number
  data: ->
    svgEl: null
    shapes: []
    pollColors: AppConfig.pollColors
    positionColors: optionColors()
  computed:
    radius: ->
      @diameter / 2.0

  methods:
    arcPath: (startAngle, endAngle) ->
      rad = Math.PI / 180
      x1 = @radius + (@radius * Math.cos(-startAngle * rad))
      x2 = @radius + (@radius * Math.cos(-endAngle * rad))
      y1 = @radius + (@radius * Math.sin(-startAngle * rad))
      y2 = @radius + (@radius * Math.sin(-endAngle * rad))
      ["M", @radius, @radius, "L", x1, y1, "A", @radius, @radius, 0, +(endAngle - startAngle > 180), 0, x2, y2, "z"].join(' ')
    draw: ->
      @shapes.forEach (shape) -> shape.remove()
      start = 90

      switch values(@stanceData).filter((v) -> v > 0).length
        when 0
          @shapes.push @svgEl.circle(@diameter).attr
            'stroke-width': 0
            fill: '#aaa'
        when 1
          each @stanceData, (count, position) =>
            return unless count > 0
            @shapes.push @svgEl.circle(@diameter).attr
              'stroke-width': 0
              fill: @positionColors[position]
        else
          each @stanceData, (count, position) =>
            return unless count > 0
            angle = 360/sum(values(@stanceData))*count
            @shapes.push @svgEl.path(@arcPath(start, start + angle)).attr
              'stroke-width': 0
              fill: @positionColors[position]
            start += angle
  watch:
    stanceData: -> @draw()

  mounted: ->
    @svgEl = svg(@$el).size('100%', '100%')
    @draw()

  beforeDestroy: ->
    @svgEl.clear()
    delete @shapes
</script>

<template lang="pug">
.poll-proposal-chart
</template>
<style lang="sass">
.poll-proposal-chart
  border: 0
  margin: 0
  padding: 0
  max-width: 200px
  svg
    height: 100%
    width: 100%

</style>

{'fraction_non_alphanumeric': 0.15261798544259217, 'fraction_numerical': 0.022305705564686546, 'mean_word_length': 2.3385579937304075, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 45, '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': '5314232', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1378, 'n_words': 352}