<commit_before><link rel="import" href="../polymer/polymer.html">
<link rel="import" href="nvd3-behavior.html">

<!--
An element to create donut chart using nvd3.

Example:

    <nvd3-donut
    data="[[data]]"
    height="300"
    width="400"
    auto-resize
    show-legend
    donut-ratio="0.25"></nvd3-donut>

Data Format:
```
[
  {
    "label": "label 1",
    "value": 69
  },
  {
    "label": "label 2",
    "value": 85
  }
]
```

@group NVD3 Elements
@element nvd3-donut
@demo demo/nvd3-donut.html
@hero hero.svg
-->

<dom-module id="nvd3-donut">
  <template>
    <style include="nvd3-shared-styles">
      #svg .nv-slice {
        transform: scale(1);
        transition: 0.1s ease-in-out;
      }

      #svg .nv-slice.selected {
        transform: scale(1.1);
      }

    </style>
    <!-- We need to put svg tag inside a div to set correct margins -->
    <div id="container">
      <svg id="svg" viewBox$="{{ getViewBox(viewBoxWidth, extraViewBoxWidth, viewBoxHeight, flexSize) }}"></svg>
    </div>
  </template>

  <script>
    Polymer({
      is: 'nvd3-donut',
      behaviors: [NVD3.ChartBehavior],
      properties: {
        /**
         * NVD3 chart object.
         */
        _chart: {
          type: Object,
          value: function() {
            var that = this;
            return nv.models.pieChart()
              .x(function(d) {
                return d[that.xProp];
              })
              .y(function(d) {
                return d[that.yProp];
              })
              .donut(true);
          }
        },

        /**
         * Configurable x-axis property key
         */
        xProp: {
          type: String,
          value: 'label'
        },

        /**
         * Configurable y-axis property key
         */
        yProp: {
          type: String,
          value: 'value'
        },

        /**
         * Configure how big you want the donut hole size to be.
         */
        donutRatio: {
          type: Number,
          value: 0.5
        },

        /**
         * Show labels for each slice
         */
        showLabels: {
          type: Boolean,
          value: false
        },

        /**
         * Whether to display the legend or not
         */
        showLegend: {
          type: Boolean,
          value: false
        },

        /**
         * Whether to increase slice radius on hover or not
         */
        growOnHover: {
          type: Boolean,
          value: false
        },

        /**
         * Text to include within the middle of a donut chart
         */
        title: {
          type: String
        },

        /**
         * Disable the tooltip
         */
        disableTooltip: {
          type: Boolean,
          value: false
        },

        /**
         * Whether the labels should be outside of donut
         */
        labelsOutside: {
          type: Boolean,
          value: false,
          observer: '_labelsOutsideChanged'
        },

        /**
        * Container for selected slices
        */
        selection: {
          type: Object,
          notify: true
        },

        /**
        * Whether possible to selected several slices
        */
        multiSelection: {
          type: Boolean,
          observer: '_multiSelectionChanged'
        }
      },
      /**
      * Fired when a slice is selected
      * @event slice-selected
      */

      observers: [
        '_setDonutRatio(donutRatio)',
        '_setTitle(title)',
        '_selectionChanged(selection.splices)'
      ],

      /**
       * Observer for setting donut ratio.
       */
      _setDonutRatio: function(donutRatio) {
        this._chart.donutRatio(this.donutRatio);
      },

      /**
       * Observer for setting title.
       */
      _setTitle: function(title) {
        this._chart.title(this.title);
      },

      /**
       * Observer for labelsOutside
       */
      _labelsOutsideChanged: function () {
        this._chart.labelsOutside(this.labelsOutside);
      },

      ready: function() {
        this._chart.pie.dispatch.on('elementClick', this._onSliceClick.bind(this));
      },

      /**
       * Listener for elementClick
       */
      _onSliceClick: function(item) {
        var previousElement = item.element.parentElement.querySelector('.nv-slice.selected');
        if (this.multiSelection) {
          if (this.selection.indexOf(item.data) > -1) {
            this.splice('selection', this.selection.indexOf(item.data), 1);
            item.element.classList.remove('selected');
          } else {
            this.push('selection', item.data);
            item.element.classList.add('selected');
          }
        } else {
          this.selection = item.data;
          if (previousElement !== null) {
            previousElement.classList.remove('selected');
          }
          item.element.classList.add('selected');
        }
      },

      /**
      * Observer for multiSelection
      */
      _multiSelectionChanged: function(newValue, oldValue) {
        if (newValue) {
          if (this.selection === undefined) {
            this.selection = [];
          } else if (!(this.selection instanceof Array)) {
            this.selection = [this.selection];
          }
        } else {
          if (this.selection instanceof Array) {
            var selectedSlices = this.svg.querySelectorAll('.nv-slice.selected'),
              i;
            for (i = 0; i < selectedSlices.length; i += 1) {
              selectedSlices[i].classList.remove('selected');
            }
            this.selection = [];
          }
        }
      },

      /**
      * Observer for selection
      */
      _selectionChanged: function() {
          this.fire('slice-selected', this.selection);
      },

      attached: function () {
        if (this.flexSize) {
          this._chart
            .height(this.viewBoxHeight)
            .width(this.viewBoxWidth);
        }
      }
    });
  </script>
</dom-module>
<commit_msg>Remove unnecessary id<commit_after><link rel="import" href="../polymer/polymer.html">
<link rel="import" href="nvd3-behavior.html">

<!--
An element to create donut chart using nvd3.

Example:

    <nvd3-donut
    data="[[data]]"
    height="300"
    width="400"
    auto-resize
    show-legend
    donut-ratio="0.25"></nvd3-donut>

Data Format:
```
[
  {
    "label": "label 1",
    "value": 69
  },
  {
    "label": "label 2",
    "value": 85
  }
]
```

@group NVD3 Elements
@element nvd3-donut
@demo demo/nvd3-donut.html
@hero hero.svg
-->

<dom-module id="nvd3-donut">
  <template>
    <style include="nvd3-shared-styles">
      #svg .nv-slice {
        transform: scale(1);
        transition: 0.1s ease-in-out;
      }

      #svg .nv-slice.selected {
        transform: scale(1.1);
      }

    </style>
    <!-- We need to put svg tag inside a div to set correct margins -->
    <div>
      <svg id="svg" viewBox$="{{ getViewBox(viewBoxWidth, extraViewBoxWidth, viewBoxHeight, flexSize) }}"></svg>
    </div>
  </template>

  <script>
    Polymer({
      is: 'nvd3-donut',
      behaviors: [NVD3.ChartBehavior],
      properties: {
        /**
         * NVD3 chart object.
         */
        _chart: {
          type: Object,
          value: function() {
            var that = this;
            return nv.models.pieChart()
              .x(function(d) {
                return d[that.xProp];
              })
              .y(function(d) {
                return d[that.yProp];
              })
              .donut(true);
          }
        },

        /**
         * Configurable x-axis property key
         */
        xProp: {
          type: String,
          value: 'label'
        },

        /**
         * Configurable y-axis property key
         */
        yProp: {
          type: String,
          value: 'value'
        },

        /**
         * Configure how big you want the donut hole size to be.
         */
        donutRatio: {
          type: Number,
          value: 0.5
        },

        /**
         * Show labels for each slice
         */
        showLabels: {
          type: Boolean,
          value: false
        },

        /**
         * Whether to display the legend or not
         */
        showLegend: {
          type: Boolean,
          value: false
        },

        /**
         * Whether to increase slice radius on hover or not
         */
        growOnHover: {
          type: Boolean,
          value: false
        },

        /**
         * Text to include within the middle of a donut chart
         */
        title: {
          type: String
        },

        /**
         * Disable the tooltip
         */
        disableTooltip: {
          type: Boolean,
          value: false
        },

        /**
         * Whether the labels should be outside of donut
         */
        labelsOutside: {
          type: Boolean,
          value: false,
          observer: '_labelsOutsideChanged'
        },

        /**
        * Container for selected slices
        */
        selection: {
          type: Object,
          notify: true
        },

        /**
        * Whether possible to selected several slices
        */
        multiSelection: {
          type: Boolean,
          observer: '_multiSelectionChanged'
        }
      },
      /**
      * Fired when a slice is selected
      * @event slice-selected
      */

      observers: [
        '_setDonutRatio(donutRatio)',
        '_setTitle(title)',
        '_selectionChanged(selection.splices)'
      ],

      /**
       * Observer for setting donut ratio.
       */
      _setDonutRatio: function(donutRatio) {
        this._chart.donutRatio(this.donutRatio);
      },

      /**
       * Observer for setting title.
       */
      _setTitle: function(title) {
        this._chart.title(this.title);
      },

      /**
       * Observer for labelsOutside
       */
      _labelsOutsideChanged: function () {
        this._chart.labelsOutside(this.labelsOutside);
      },

      ready: function() {
        this._chart.pie.dispatch.on('elementClick', this._onSliceClick.bind(this));
      },

      /**
       * Listener for elementClick
       */
      _onSliceClick: function(item) {
        var previousElement = item.element.parentElement.querySelector('.nv-slice.selected');
        if (this.multiSelection) {
          if (this.selection.indexOf(item.data) > -1) {
            this.splice('selection', this.selection.indexOf(item.data), 1);
            item.element.classList.remove('selected');
          } else {
            this.push('selection', item.data);
            item.element.classList.add('selected');
          }
        } else {
          this.selection = item.data;
          if (previousElement !== null) {
            previousElement.classList.remove('selected');
          }
          item.element.classList.add('selected');
        }
      },

      /**
      * Observer for multiSelection
      */
      _multiSelectionChanged: function(newValue, oldValue) {
        if (newValue) {
          if (this.selection === undefined) {
            this.selection = [];
          } else if (!(this.selection instanceof Array)) {
            this.selection = [this.selection];
          }
        } else {
          if (this.selection instanceof Array) {
            var selectedSlices = this.svg.querySelectorAll('.nv-slice.selected'),
              i;
            for (i = 0; i < selectedSlices.length; i += 1) {
              selectedSlices[i].classList.remove('selected');
            }
            this.selection = [];
          }
        }
      },

      /**
      * Observer for selection
      */
      _selectionChanged: function() {
          this.fire('slice-selected', this.selection);
      },

      attached: function () {
        if (this.flexSize) {
          this._chart
            .height(this.viewBoxHeight)
            .width(this.viewBoxWidth);
        }
      }
    });
  </script>
</dom-module>

{'fraction_non_alphanumeric': 0.12649444026419196, 'fraction_numerical': 0.006353983780620349, 'mean_word_length': 1.423419773095624, 'pattern_counts': {'":': 8, '<': 41, '<?xml version=': 0, '>': 41, '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': '456580', 'n_tokens_mistral': 3442, 'n_tokens_neox': 3339, 'n_words': 715}