# Path: smith/smith_mapper.py

# 
# Path: smith/smith_line_renderer.py
# class SmithLineRenderer(LinePlot):
# #    def _gather_points(self):
# #        print "SmithLineRenderer._gather_points"
# ##        self._cache_valid = False
# #        print "index", self.index.get_data()
# #        print "value", self.value.get_data()
# #        super(self.__class__, self)._gather_points()
# 
#     def _render(self, gc, points):
#         print "SmithLineRenderer._render"
#         super(self.__class__, self)._render(gc, points)
# 
#     def _gather_points(self):
#         """ Collects the data points that are within the bounds of the plot and
#         caches them.
#         """
#         if self._cache_valid:
#             return
# 
#         data = self.value.get_data()
#         x = data.real.astype(float)
#         y = data.imag.astype(float)
#         
#         if not self.index or not self.value:
#             return
# 
#         if len(x) == 0:
#             self._cached_data_pts = []
#             self._cache_valid = True
#             return
# 
#         points = [np.transpose(np.array((x, y)))]
#         self._cached_data_pts = points
#         self._cache_valid = True


from numpy import array, ndarray, transpose, real, imag
from enthought.chaco.array_data_source import ArrayDataSource
from enthought.chaco.data_range_1d import DataRange1D
from .smith_mapper import SmithMapper
from .smith_line_renderer import SmithLineRenderer
"""
Contains a convenience function to create a ready-made Smith plot
"""

# Major library imports


# Local relative imports


def create_smith_plot(data, orientation='h', color='black', width=1.0,
                      dash="solid", grid="dot", value_mapper_class=SmithMapper):
    if (type(data) != ndarray) and (len(data) == 2):
        data = transpose(array(data))

    freqs, values = transpose(data)
    index_data = real(values)
    value_data = imag(values)

    index = ArrayDataSource(index_data, sort_order='ascending')
    # Typically the value data is unsorted
    value = ArrayDataSource(value_data)

    index_range = DataRange1D()
    index_range.add(index)

# Path: smith/smith_mapper.py

# 
# Path: smith/smith_line_renderer.py
# class SmithLineRenderer(LinePlot):
# #    def _gather_points(self):
# #        print "SmithLineRenderer._gather_points"
# ##        self._cache_valid = False
# #        print "index", self.index.get_data()
# #        print "value", self.value.get_data()
# #        super(self.__class__, self)._gather_points()
# 
#     def _render(self, gc, points):
#         print "SmithLineRenderer._render"
#         super(self.__class__, self)._render(gc, points)
# 
#     def _gather_points(self):
#         """ Collects the data points that are within the bounds of the plot and
#         caches them.
#         """
#         if self._cache_valid:
#             return
# 
#         data = self.value.get_data()
#         x = data.real.astype(float)
#         y = data.imag.astype(float)
#         
#         if not self.index or not self.value:
#             return
# 
#         if len(x) == 0:
#             self._cached_data_pts = []
#             self._cache_valid = True
#             return
# 
#         points = [np.transpose(np.array((x, y)))]
#         self._cached_data_pts = points
#         self._cache_valid = True


# Path: smith/create_smith_plot.py
from numpy import array, ndarray, transpose, real, imag
from enthought.chaco.array_data_source import ArrayDataSource
from enthought.chaco.data_range_1d import DataRange1D
from .smith_mapper import SmithMapper
from .smith_line_renderer import SmithLineRenderer

"""
Contains a convenience function to create a ready-made Smith plot
"""

# Major library imports


# Local relative imports


def create_smith_plot(data, orientation='h', color='black', width=1.0,
                      dash="solid", grid="dot", value_mapper_class=SmithMapper):
    if (type(data) != ndarray) and (len(data) == 2):
        data = transpose(array(data))

    freqs, values = transpose(data)
    index_data = real(values)
    value_data = imag(values)

    index = ArrayDataSource(index_data, sort_order='ascending')
    # Typically the value data is unsorted
    value = ArrayDataSource(value_data)

    index_range = DataRange1D()
    index_range.add(index)

    index_mapper = SmithMapper(range=index_range)