<commit_before># chart.js charting attribute directive.
angular
  .module('impac.components.chart',[])
  .directive('impacChart', ($timeout, $log) ->
    return {
      restrict: 'A',
      scope: {
        drawTrigger: '='
        deferred: '='
      },
      template: '<canvas></canvas>',
      link: (scope,elem,attr) ->
        options = {
          bezierCurve: true,
          pointDotRadius : 3,
          responsive: true,
          scaleShowLabels : true,
          scaleShowLabelBackdrop : true,
          scaleBeginAtZero: true,
          scaleShowGridLines: true,
        }

        # Draw a chart in the canvas
        # (ChartJs way of drawing a chart is to create a new Chart() element in the canvas context)
        # ------------------------------------
        scope.draw = (data) ->
          # $timeout will wait for the DOM to be rendered before drawing the chart
          $timeout ->
            if !_.isEmpty(data.options)
              angular.extend(options,data.options)

            canvas = elem.children().get(0)
            ctx = canvas.getContext("2d")

            switch data.chartType
              when 'Bar'
                new Chart(ctx).Bar(data.data,options)
              when 'Line'
                new Chart(ctx).Line(data.data,options)
              when 'Pie'
                angular.extend(options, {tooltipFixed: true})
                new Chart(ctx).Pie(data.data,options)


        # Triggered by widget.format()
        # ------------------------------------
        scope.drawTrigger.then(
          (success) ->
            $log.warn('chart promise has been resolved: use notify instead')<commit_msg>fix charts superposition<commit_after># chart.js charting attribute directive.
angular
  .module('impac.components.chart',[])
  .directive('impacChart', ($timeout, $log) ->
    return {
      restrict: 'A',
      scope: {
        drawTrigger: '='
        deferred: '='
      },
      template: '<canvas></canvas>',
      link: (scope,elem,attr) ->
        options = {
          bezierCurve: true,
          pointDotRadius : 3,
          responsive: true,
          scaleShowLabels : true,
          scaleShowLabelBackdrop : true,
          scaleBeginAtZero: true,
          scaleShowGridLines: true,
        }

        # Draw a chart in the canvas
        # (ChartJs way of drawing a chart is to create a new Chart() element in the canvas context)
        # ------------------------------------
        scope.draw = (data) ->
          # $timeout will wait for the DOM to be rendered before drawing the chart
          $timeout ->
            if !_.isEmpty(data.options)
              angular.extend(options,data.options)

            # canvas has to be removed/appended to be redrawned without superposition
            elem.children().get(0).remove()
            elem.append('<canvas></canvas>')
            canvas = elem.children().get(0)
            ctx = canvas.getContext("2d")

            switch data.chartType
              when 'Bar'
                new Chart(ctx).Bar(data.data,options)
              when 'Line'
                new Chart(ctx).Line(data.data,options)
              when 'Pie'
                angular.extend(options, {tooltipFixed: true})
                new Chart(ctx).Pie(data.data,options)


        # Triggered by widget.format()
        # ------------------------------------
        scope.drawTrigger.then(
          (success) ->
            $log.warn('chart promise has been resolved: use notify instead')
{'fraction_non_alphanumeric': 0.14633447880870562, 'fraction_numerical': 0.002004581901489118, 'mean_word_length': 1.564610866372981, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '7310165', 'n_tokens_mistral': 904, 'n_tokens_neox': 886, 'n_words': 235}