# noinspection PyPep8
import matplotlib.pyplot as plt, mpld3
import pandas as pd
import seaborn as splot


class Graphics:

    @staticmethod
    def fill(df, lower, upper, alpha=0.20):
        x = df.index
        plt.fill_between(x, df[lower], d[upper], alpha=alpha)

    @staticmethod
    def table():
        """
        allows to print the entire table instead of just part when using pandas
        """
        pd.set_option('display.max_rows', None)
        pd.set_option('display.max_columns', None)
        pd.set_option('display.width', None)
        pd.set_option('display.max_colwidth', None)

    @staticmethod
    def backend(kind):
        if kind == "mpld3":
            raise NotImplementedError
        elif kind == "png":
            raise NotImplementedError
        elif kind == "jupyter":
            raise NotImplementedError

    @staticmethod
    def show(kind="inline"):
        if kind == "d3":
            mpld3.show()
        elif kind == "png":
            raise NotImplementedError
        elif kind == "inline":
            plt.show()

        # if Graphics.kind == "mpld3":
        #    mpld3.show()
        # elif Graphics.kind == "png":
        #    raise NotImplementedError
        # in png case write to a file and automatically increase a global counter so the files are not overwritten
        # we can use a borg class

    @staticmethod
    def scale(scale=1, x=6, y=3):
        print("Graphics Scale:", scale)
        plt.rcParams['figure.figsize'] = [x * scale, y * scale]

    @staticmethod
    def figuresize(scale=3, x=6, y=3):
        plt.rcParams['figure.figsize'] = [x * scale, y * scale]
        # although not a scle, but this helps also to keep the background white

    @staticmethod
    def face():
        plt.rcParams['figure.facecolor'] = 'white'
        # plt.rcParams['font.family'] = 'sans-serif'
        # plt.rcParams['font.sans-serif'] = ['Tahoma']
        # plt.rcParams.update({'font.size': 12})
        # plt.rc('font', size=8)

    @staticmethod
    def date_plot(df, title=None, y="Count", x=None, legend=True, seaborn=False,
                  logy=False):
        if not seaborn:
            df.plot(title=title, legend=legend, logy=logy)
            if logy:
                y = y + " (log)"
            plt.ylabel(y)
        else:
            if df.shape[1] > 6:
                print(
                    "ERROR: plot with `seaborn=False` as more than 6 lines are specified")
                return
            splot.lineplot(data=df, dashes=False).set_title(title)
            locs, labels = plt.xticks()
            plt.setp(labels, rotation=45)
            splot.set_style("ticks")
            plt.ylabel(y)
            plt.xlabel(x)
            plt.title(title)

    @staticmethod
    def plot_row(df, n):
        plt.xlabel("Date")
        plt.ylabel("Cases")
        s = pd.Series(df.iloc[:, n][1:])
        s.plot.line()

    @staticmethod
    def plot_fips(df, fips):
        plt.xlabel("Date")
        plt.ylabel("Cases")
        d = df[fips]
        t = pd.Series(d[1:])
        t.plot.line()

    @staticmethod
    def add_fips_title(fips, label="FIPS"):
        _title = f"{label} " + " ".join([str(x) for x in fips])
        plt.title(_title)


Graphics.scale(1)
Graphics.face()
