<commit_before>import 'dart:math';

import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

import '../../../../core/helpers/color_palette_helper.dart';
import '../../domain/entities/graph_data.dart';

class PlaysByDateGraph extends StatelessWidget {
  final GraphData playsByDate;

  const PlaysByDateGraph({
    Key key,
    @required this.playsByDate,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    double largestPlayCount = (List<int>.from(
            playsByDate.seriesDataList[0].seriesData +
                playsByDate.seriesDataList[1].seriesData +
                playsByDate.seriesDataList[2].seriesData))
        .reduce(max)
        .toDouble();

    double horizontalLineStep = (largestPlayCount / 5).ceilToDouble();
    double verticalLineStep =
        (playsByDate.categories.length / 7).ceilToDouble();

    double maxYLines = (largestPlayCount / horizontalLineStep).ceilToDouble() *
        horizontalLineStep;

    List<FlSpot> tvData = [];
    List<FlSpot> moviesData = [];
    List<FlSpot> musicData = [];
    for (var i = 0; i < playsByDate.categories.length; i++) {
      tvData.add(
        FlSpot(
          i.toDouble(),
          playsByDate.seriesDataList[0].seriesData[i].toDouble(),
        ),
      );
      moviesData.add(
        FlSpot(
          i.toDouble(),
          playsByDate.seriesDataList[1].seriesData[i].toDouble(),
        ),
      );
      musicData.add(
        FlSpot(
          i.toDouble(),
          playsByDate.seriesDataList[2].seriesData[i].toDouble(),
        ),
      );
    }

    return Padding(
      padding: const EdgeInsets.only(
        top: 8,
        left: 8,
        right: 8,
      ),
      child: ClipRRect(
        borderRadius: BorderRadius.circular(4),
        child: Container(
          height: 275,
          color: TautulliColorPalette.gunmetal,
          child: Padding(
            padding: const EdgeInsets.only(
              top: 12,
              left: 4,
              bottom: 8,
              right: 8,
            ),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Expanded(
                  child: LineChart(
                    LineChartData(
                      titlesData: FlTitlesData(
                        leftTitles: SideTitles(
                          showTitles: true,
                          interval: 5,
                          getTextStyles: (value) {
                            return const TextStyle(
                              color: Colors.grey,
                              fontSize: 12,
                            );
                          },
                        ),
                        bottomTitles: SideTitles(
                          showTitles: true,
                          interval: verticalLineStep,
                          getTitles: (value) => 'Mar\n12',
                          // rotateAngle: -45,
                          // margin: 20,
                          reservedSize: 30,
                          getTextStyles: (value) {
                            return const TextStyle(
                              color: Colors.grey,
                              fontSize: 12,
                            );
                          },
                        ),
                      ),
                      maxY: maxYLines,
                      gridData: FlGridData(
                        checkToShowHorizontalLine: (value) =>
                            value % horizontalLineStep == 0,
                        checkToShowVerticalLine: (value) =>
                            value % verticalLineStep == 0,
                        drawVerticalLine: true,
                        getDrawingVerticalLine: (value) => FlLine(
                          color: Colors.white.withOpacity(0.03),
                        ),
                      ),
                      borderData: FlBorderData(
                        border: const Border(
                          top: BorderSide(
                            width: 1,
                            color: Colors.white24,
                          ),
                        ),
                      ),
                      lineTouchData: LineTouchData(
                        touchTooltipData: LineTouchTooltipData(
                          fitInsideHorizontally: true,
                          fitInsideVertically: true,
                          tooltipBgColor:
                              TautulliColorPalette.midnight.withOpacity(0.95),
                          getTooltipItems: (touchedSpots) {
                            return [
                              LineTooltipItem(
                                'TV: ${touchedSpots[0].y.toStringAsFixed(0)}',
                                const TextStyle(
                                  color: TautulliColorPalette.amber,
                                ),
                              ),
                              LineTooltipItem(
                                'Movies: ${touchedSpots[1].y.toStringAsFixed(0)}',<commit_msg>Use dates on x axis and add date to tooltip.<commit_after>import 'dart:math';

import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

import '../../../../core/helpers/color_palette_helper.dart';
import '../../../../core/helpers/time_format_helper.dart';
import '../../domain/entities/graph_data.dart';

class PlaysByDateGraph extends StatelessWidget {
  final GraphData playsByDate;

  const PlaysByDateGraph({
    Key key,
    @required this.playsByDate,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    double largestPlayCount = (List<int>.from(
            playsByDate.seriesDataList[0].seriesData +
                playsByDate.seriesDataList[1].seriesData +
                playsByDate.seriesDataList[2].seriesData))
        .reduce(max)
        .toDouble();

    double horizontalLineStep = (largestPlayCount / 5).ceilToDouble();
    double verticalLineStep =
        (playsByDate.categories.length / 7).ceilToDouble();

    double maxYLines = (largestPlayCount / horizontalLineStep).ceilToDouble() *
        horizontalLineStep;

    List<FlSpot> tvData = [];
    List<FlSpot> moviesData = [];
    List<FlSpot> musicData = [];
    for (var i = 0; i < playsByDate.categories.length; i++) {
      tvData.add(
        FlSpot(
          i.toDouble(),
          playsByDate.seriesDataList[0].seriesData[i].toDouble(),
        ),
      );
      moviesData.add(
        FlSpot(
          i.toDouble(),
          playsByDate.seriesDataList[1].seriesData[i].toDouble(),
        ),
      );
      musicData.add(
        FlSpot(
          i.toDouble(),
          playsByDate.seriesDataList[2].seriesData[i].toDouble(),
        ),
      );
    }

    return Padding(
      padding: const EdgeInsets.only(
        top: 8,
        left: 8,
        right: 8,
      ),
      child: ClipRRect(
        borderRadius: BorderRadius.circular(4),
        child: Container(
          height: 275,
          color: TautulliColorPalette.gunmetal,
          child: Padding(
            padding: const EdgeInsets.only(
              top: 12,
              left: 4,
              bottom: 8,
              right: 8,
            ),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Expanded(
                  child: LineChart(
                    LineChartData(
                      titlesData: FlTitlesData(
                        leftTitles: SideTitles(
                          showTitles: true,
                          interval: horizontalLineStep,
                          getTextStyles: (value) {
                            return const TextStyle(
                              color: Colors.grey,
                              fontSize: 12,
                            );
                          },
                        ),
                        bottomTitles: SideTitles(
                          showTitles: true,
                          interval: verticalLineStep,
                          getTitles: (value) {
                            return TimeFormatHelper.graphDate(
                                playsByDate.categories[value.toInt()]);
                          },
                          reservedSize: 30,
                          getTextStyles: (value) {
                            return const TextStyle(
                              color: Colors.grey,
                              fontSize: 12,
                            );
                          },
                        ),
                      ),
                      maxY: maxYLines,
                      gridData: FlGridData(
                        checkToShowHorizontalLine: (value) =>
                            value % horizontalLineStep == 0,
                        checkToShowVerticalLine: (value) =>
                            value % verticalLineStep == 0,
                        drawVerticalLine: true,
                        getDrawingVerticalLine: (value) => FlLine(
                          color: Colors.white.withOpacity(0.03),
                        ),
                      ),
                      borderData: FlBorderData(
                        border: const Border(
                          top: BorderSide(
                            width: 1,
                            color: Colors.white24,
                          ),
                        ),
                      ),
                      lineTouchData: LineTouchData(
                        touchTooltipData: LineTouchTooltipData(
                          fitInsideHorizontally: true,
                          fitInsideVertically: true,
                          tooltipBgColor:
                              TautulliColorPalette.midnight.withOpacity(0.95),
                          getTooltipItems: (touchedSpots) {
                            return [
                              LineTooltipItem(
                                '',
                                const TextStyle(),
                                children: [
                                  TextSpan(
                                    text:
                                        '${TimeFormatHelper.graphDate(playsByDate.categories[touchedSpots[0].x.toInt()], includeWeekDay: true)}\n\n',
                                    style: const TextStyle(
                                      color: Colors.grey,
                                    ),
                                  ),
                                  TextSpan(
                                    text:
                                        'TV: ${touchedSpots[0].y.toStringAsFixed(0)}',
                                    style: const TextStyle(
                                      color: TautulliColorPalette.amber,
                                    ),
                                  ),
                                ],
                              ),
                              LineTooltipItem(
                                'Movies: ${touchedSpots[1].y.toStringAsFixed(0)}',
{'fraction_non_alphanumeric': 0.08659885006634233, 'fraction_numerical': 0.008137992038920832, 'mean_word_length': 1.0028343666961914, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '257645', 'n_tokens_mistral': 2815, 'n_tokens_neox': 2645, 'n_words': 456}