# Path: apasvo/utils/plotting.py
# SPECGRAM_WINDOWS = ("boxcar", "hamming", "hann", "bartlett",
#                             'blackman', "blackmanharris")
# SPECGRAM_WINDOWS_NAMES = ("Rectangular", "Hamming", "Hann", "Bartlett",
#                           "Blackman", "Blackman-Harris")
# def plot_specgram(ax, data, fs, nfft=256, noverlap=128, window='hann',
#                   cmap='jet', interpolation='bilinear', rasterized=True):
# def reduce_data(x, y, width, xmin=0, xmax=None):
# def adjust_axes_height(ax, max_value=None, min_value=None, margin=0.1):
# 
# Path: apasvo/utils/clt.py
# def float_secs_2_string_date(x, starttime=datetime.datetime.utcfromtimestamp(0)):
# def print_msg(msg):
# def query_yes_no_all_quit(question, default="yes"):
# def query_custom_answers(question, answers, default=None):
#     def __init__(self, name, data, align=ALIGN.RIGHT, fmt='%.6g'):
#     def __init__(self, *columns):
#     def get_row(self, i=None):
#     def get_line(self):
#     def join_n_wrap(self, char, elements):
#     def get_rows(self):
#     def __str__(self):
#     def __init__(self, minValue=0, maxValue=100, totalWidth=12):
#     def updateAmount(self, newAmount=0):
#     def __str__(self):
# class ALIGN:
# class Column():
# class Table:
# class ProgressBar:
#     LEFT, RIGHT = '-', ''


from PySide import QtGui
from PySide import QtCore
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.ticker import FuncFormatter
from mpl_toolkits.axes_grid.anchored_artists import AnchoredText
from apasvo.utils import plotting
from apasvo.utils import clt
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
        self.ax.grid(True, which='both')
        # Set event markers
        self.marker_select_color = 'r'
        self.marker_color = 'b'
        self.markers = {}
        self.update_markers()
        # Selection parameters
        self.selected = False
        self.selector = self.ax.axvspan(0, self.xmax, fc='LightCoral', ec='r', alpha=0.5, visible=False)#, animated=True)
        # Place legend
        at = AnchoredText(self.trace.short_name, prop=dict(size=12), frameon=True, loc=2)
        at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
        self.ax.add_artist(at)

    def on_xlim_change(self, ax):
        xmin, xmax = ax.get_xlim()
        if self.xmin <= xmin <= xmax <= self.xmax:
            # Update data
            self.update_data(ax)
        else:
            xmin = max(self.xmin, xmin)
            xmax = min(self.xmax, xmax)
            ax.set_xlim(xmin, xmax)

    def update_data(self, ax=None):
        ax = self.ax if ax is None else ax
        xmin, xmax = self.ax.get_xlim()
        xmin = int(max(0, self.xmin) * self.trace.fs)
        xmax = int(min(self.xmax, xmax) * self.trace.fs)
        pixel_width = np.ceil(self.fig.get_figwidth() * self.fig.get_dpi())

# Path: apasvo/utils/plotting.py
# SPECGRAM_WINDOWS = ("boxcar", "hamming", "hann", "bartlett",
#                             'blackman', "blackmanharris")
# SPECGRAM_WINDOWS_NAMES = ("Rectangular", "Hamming", "Hann", "Bartlett",
#                           "Blackman", "Blackman-Harris")
# def plot_specgram(ax, data, fs, nfft=256, noverlap=128, window='hann',
#                   cmap='jet', interpolation='bilinear', rasterized=True):
# def reduce_data(x, y, width, xmin=0, xmax=None):
# def adjust_axes_height(ax, max_value=None, min_value=None, margin=0.1):
# 
# Path: apasvo/utils/clt.py
# def float_secs_2_string_date(x, starttime=datetime.datetime.utcfromtimestamp(0)):
# def print_msg(msg):
# def query_yes_no_all_quit(question, default="yes"):
# def query_custom_answers(question, answers, default=None):
#     def __init__(self, name, data, align=ALIGN.RIGHT, fmt='%.6g'):
#     def __init__(self, *columns):
#     def get_row(self, i=None):
#     def get_line(self):
#     def join_n_wrap(self, char, elements):
#     def get_rows(self):
#     def __str__(self):
#     def __init__(self, minValue=0, maxValue=100, totalWidth=12):
#     def updateAmount(self, newAmount=0):
#     def __str__(self):
# class ALIGN:
# class Column():
# class Table:
# class ProgressBar:
#     LEFT, RIGHT = '-', ''


# Path: apasvo/gui/views/tsvwidget.py
from PySide import QtGui
from PySide import QtCore
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.ticker import FuncFormatter
from mpl_toolkits.axes_grid.anchored_artists import AnchoredText
from apasvo.utils import plotting
from apasvo.utils import clt
import numpy as np
import matplotlib
import matplotlib.pyplot as plt

        self.ax.grid(True, which='both')
        # Set event markers
        self.marker_select_color = 'r'
        self.marker_color = 'b'
        self.markers = {}
        self.update_markers()
        # Selection parameters
        self.selected = False
        self.selector = self.ax.axvspan(0, self.xmax, fc='LightCoral', ec='r', alpha=0.5, visible=False)#, animated=True)
        # Place legend
        at = AnchoredText(self.trace.short_name, prop=dict(size=12), frameon=True, loc=2)
        at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
        self.ax.add_artist(at)

    def on_xlim_change(self, ax):
        xmin, xmax = ax.get_xlim()
        if self.xmin <= xmin <= xmax <= self.xmax:
            # Update data
            self.update_data(ax)
        else:
            xmin = max(self.xmin, xmin)
            xmax = min(self.xmax, xmax)
            ax.set_xlim(xmin, xmax)

    def update_data(self, ax=None):
        ax = self.ax if ax is None else ax
        xmin, xmax = self.ax.get_xlim()
        xmin = int(max(0, self.xmin) * self.trace.fs)
        xmax = int(min(self.xmax, xmax) * self.trace.fs)
        pixel_width = np.ceil(self.fig.get_figwidth() * self.fig.get_dpi())

        x_data, y_data = plotting.reduce_data(self.time, self.trace.signal, pixel_width, xmin, xmax)