from .chart_component import ChartComponentDict


class Ticks(ChartComponentDict):

    def __init__(self, axis):

        super(Ticks, self).__init__()

        self.axis = axis

    def set_format(self, tick_format):

        if self.axis.axis_dimension == 'x':
            if self.axis.config['type'] == self.__string_wrap__('timeseries'):
                format_str = "d3.time.format({tick_format})"
            else:
                format_str = "d3.format({tick_format})"

        else:
            format_str = "d3.format({tick_format})"

        self.config['format'] = format_str.format(
            tick_format=self.__string_wrap__(tick_format),
        )

    def set_count(self, tick_count):

        self.config['count'] = tick_count

    def set_values(self, tick_values):

        tick_values_str = [str(i) for i in tick_values]

        self.config['values'] = tick_values_str


class XTicks(Ticks):

    def __init__(self, axis):

        super(XTicks, self).__init__(axis)

    def cull(self, max_ticks):

        self.config['culling'] = {
            'max': max_ticks,
        }

    def rotate(self, degrees):

        self.config['rotate'] = degrees

    def set_multiline(self, multiline):

        self.config['multiline'] = str(multiline).lower()

    def set_fit(self, fit):

        self.config['fit'] = str(fit).lower()


class YTicks(Ticks):

    def __init__(self, axis):

        super(YTicks, self).__init__(axis)
@@ -777,24 +777,136 @@
 k_values):%0A%0A
+        if self.axis.axis_dimension == 'x' and self.axis.config%5B'type'%5D != self.__string_wrap__('indexed'):%0A    
         tick
@@ -916,19 +916,32 @@
 lues
-_str
  = %5Bs
-tr
+elf.__string_wrap__
 (i) 
@@ -1006,20 +1006,16 @@
 k_values
-_str
 %0A%0A%0Aclass

Fix tick value setting for non-indexed x axes