<commit_before>module MotionPlot
  class Pie < Base

    def add_series
      pie                 = CPTPieChart.alloc.init
      pie.dataSource      = self
      pie.delegate        = self
      pie.pieRadius       = pie_radius
      pie.startAngle      = Math::PI/4
      pie.sliceDirection  = CPTPieDirectionCounterClockwise #CPTPieDirectionClockwise

      animate(pie)
      @graph.addPlot(pie)
    end

    def numberOfRecordsForPlot(plot)
      series_data.size
    end

    def numberForPlot(plot, field: fieldEnum, recordIndex: index)
      fieldEnum == CPTPieChartFieldSliceWidth ? series_data[index][:y] : index
    end

    def sliceFillForPieChart(plot, recordIndex: index)
      CPTFill.alloc.initWithColor Series::COLORS[index].to_color.to_cpt_color
    end

    def radialOffsetForPieChart(plot, recordIndex: index)
      offset = 0.0

      if(series_data[index][:selected])
        offset = pie_radius / 25.0
      end

      offset
    end

    protected
    def plot_type
      "pie"
    end

    def pie_radius
      [
        0.8 * (@layer_hosting_view.frame.size.height - 2 * @graph.paddingLeft) / 2.0,
        0.8 * (@layer_hosting_view.frame.size.width - 2 * @graph.paddingTop) / 2.0
      ].min
    end

    def series_data<commit_msg>Added radial offset to pie chart<commit_after>module MotionPlot
  class Pie < Base

    attr_accessor :selected_index

    def add_series
      pie                 = CPTPieChart.alloc.init
      pie.dataSource      = self
      pie.delegate        = self
      pie.pieRadius       = pie_radius
      pie.startAngle      = Math::PI/4
      pie.sliceDirection  = CPTPieDirectionCounterClockwise #CPTPieDirectionClockwise

      animate(pie)
      @graph.addPlot(pie)
    end

    def numberOfRecordsForPlot(plot)
      series_data.size
    end

    def numberForPlot(plot, field: fieldEnum, recordIndex: index)
      fieldEnum == CPTPieChartFieldSliceWidth ? series_data[index][:y] : index
    end

    def sliceFillForPieChart(plot, recordIndex: index)
      CPTFill.alloc.initWithColor Series::COLORS[index].to_color.to_cpt_color
    end

    def radialOffsetForPieChart(plot, recordIndex: index)
      offset = 0.0

      @selected_index = series_data[index][:selected] if(@selected_index.nil?)
      if(@selected_index)
        offset = pie_radius / 25.0
      end

      offset
    end

    def pieChart(plot, sliceWasSelectedAtRecordIndex: index)
      @selected_index = index
      pie.reloadData
    end

    protected
    def plot_type
      "pie"
    end

    def pie_radius
      [
        0.8 * (@layer_hosting_view.frame.size.height - 2 * @graph.paddingLeft) / 2.0,
        0.8 * (@layer_hosting_view.frame.size.width - 2 * @graph.paddingTop) / 2.0
      ].min
    end

    def series_data
{'fraction_non_alphanumeric': 0.08333333333333333, 'fraction_numerical': 0.011594202898550725, 'mean_word_length': 2.3629719853836786, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2742897', 'n_tokens_mistral': 909, 'n_tokens_neox': 862, 'n_words': 175}