<commit_before>import 'dart:math';

import 'package:fivekmrun_flutter/state/run_model.dart';
import 'package:flutter/material.dart';
import 'package:charts_flutter/flutter.dart' as charts;
import "package:collection/collection.dart";

class RunsByRouteChart extends StatelessWidget {
  final List<charts.Series> seriesList;
  final bool animate;

  RunsByRouteChart(this.seriesList, {this.animate});

  factory RunsByRouteChart.withRuns(List<Run> runs) {
    return new RunsByRouteChart(
      _createData(runs),
    );
  }
  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    final subHeadStyle = theme.textTheme.subhead;

    return Padding(
      padding: EdgeInsets.all(8.0),
      child: Column(children: <Widget>[
        IntrinsicHeight(child: Text("Бягания по трасета", style: subHeadStyle)),
        Expanded(
            child: new charts.PieChart(seriesList, animate: animate, behaviors: [
          new charts.DatumLegend(
            // Positions for "start" and "end" will be left and right respectively
            // for widgets with a build context that has directionality ltr.
            // For rtl, "start" and "end" will be right and left respectively.
            // Since this example has directionality of ltr, the legend is
            // positioned on the right side of the chart.
            position: charts.BehaviorPosition.end,
            // For a legend that is positioned on the left or right of the chart,
            // setting the justification for [endDrawArea] is aligned to the
            // bottom of the chart draw area.
            //outsideJustification: charts.OutsideJustification.endDrawArea,
            // By default, if the position of the chart is on the left or right of
            // the chart, [horizontalFirst] is set to false. This means that the
            // legend entries will grow as new rows first instead of a new column.
            horizontalFirst: false,
            // This defines the padding around each legend entry.
            cellPadding: new EdgeInsets.only(right: 4.0, bottom: 4.0),
          )
        ])),
    ]));
  }

  static List<charts.Series<RunsByRouteEntry, String>> _createData(
      List<Run> runs) {
    List<RunsByRouteEntry> series = groupBy(runs, (r) => r.location)
        .entries
        .map((e) => RunsByRouteEntry(e.key, e.value.length))
        .toList();

    return [
      new charts.Series<RunsByRouteEntry, String>(
        id: 'RunsByRoute',
        colorFn: (_, i) => charts.MaterialPalette.deepOrange.makeShades(1000)[i*100],
        domainFn: (RunsByRouteEntry run, _) => run.location,
        measureFn: (RunsByRouteEntry run, _) => run.timeInSeconds,
        data: series,
      )
    ];
  }
}

class RunsByRouteEntry {
  final String location;
  final int timeInSeconds;
<commit_msg>add labels to pie chart<commit_after>import 'dart:math';

import 'package:fivekmrun_flutter/state/run_model.dart';
import 'package:flutter/material.dart';
import 'package:charts_flutter/flutter.dart' as charts;
import "package:collection/collection.dart";

class RunsByRouteChart extends StatelessWidget {
  final List<charts.Series> seriesList;
  final bool animate;

  RunsByRouteChart(this.seriesList, {this.animate});

  factory RunsByRouteChart.withRuns(List<Run> runs) {
    return new RunsByRouteChart(
      _createData(runs),
    );
  }
  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    final subHeadStyle = theme.textTheme.subhead;

    return Padding(
      padding: EdgeInsets.all(8.0),
      child: Column(children: <Widget>[
        IntrinsicHeight(child: Text("Бягания по трасета", style: subHeadStyle)),
        Expanded(
            child: new charts.PieChart(
              seriesList, 
              animate: animate, 
              defaultRenderer: new charts.ArcRendererConfig(
                arcWidth: 60,
                arcRendererDecorators: [new charts.ArcLabelDecorator(
                  outsideLabelStyleSpec: charts.TextStyleSpec(fontSize: 12, color: charts.Color.white)
                )]),
              behaviors: [
                new charts.DatumLegend(
                  // Positions for "start" and "end" will be left and right respectively
                  // for widgets with a build context that has directionality ltr.
                  // For rtl, "start" and "end" will be right and left respectively.
                  // Since this example has directionality of ltr, the legend is
                  // positioned on the right side of the chart.
                  position: charts.BehaviorPosition.end,
                  // For a legend that is positioned on the left or right of the chart,
                  // setting the justification for [endDrawArea] is aligned to the
                  // bottom of the chart draw area.
                  //outsideJustification: charts.OutsideJustification.endDrawArea,
                  // By default, if the position of the chart is on the left or right of
                  // the chart, [horizontalFirst] is set to false. This means that the
                  // legend entries will grow as new rows first instead of a new column.
                  horizontalFirst: false,
                  // This defines the padding around each legend entry.
                  cellPadding: new EdgeInsets.only(right: 4.0, bottom: 4.0),
                )
        ])),
    ]));
  }

  static List<charts.Series<RunsByRouteEntry, String>> _createData(
      List<Run> runs) {
    List<RunsByRouteEntry> series = groupBy(runs, (r) => r.location)
        .entries
        .map((e) => RunsByRouteEntry(e.key, e.value.length))
        .toList();

    return [
      new charts.Series<RunsByRouteEntry, String>(
        id: 'RunsByRoute',
        colorFn: (_, i) => charts.MaterialPalette.deepOrange.makeShades(1000)[i*100],
        domainFn: (RunsByRouteEntry run, _) => run.location,
        measureFn: (RunsByRouteEntry run, _) => run.timeInSeconds,
        data: series,
        labelAccessorFn: (RunsByRouteEntry run, _) => run.timeInSeconds.toString(),
      )
    ];
  }
}

class RunsByRouteEntry {
  final String location;
  final int timeInSeconds;

{'fraction_non_alphanumeric': 0.09464688810061271, 'fraction_numerical': 0.004837149306675266, 'mean_word_length': 2.4063701263042283, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 30, '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': '1368862', 'n_tokens_mistral': 1795, 'n_tokens_neox': 1722, 'n_words': 510}