Commits

Takeshi Komiya committed 6ed6d6d

* Support axis of chart

Comments (0)

Files changed (3)

googlechart/README

       car: 60, 75, 60, 30
       car.color: 0000ff
 
+   If you want to append axis to chart,
+   write axis and axis_label parameters at source script::
+
+      .. linechart::
+
+         bicycle: 15, 35, 20, 40
+         bicycle.color: ff0000
+         bicycle.axis: x
+         bicycle.axis_label: slow, fast
+         car: 60, 75, 60, 30
+         car.color: 0000ff
+
+   .. linechart::
+
+      bicycle: 15, 35, 20, 40
+      bicycle.color: ff0000
+      bicycle.axis: x
+      bicycle.axis_label: slow, fast
+      car: 60, 75, 60, 30
+      car.color: 0000ff
+
+   If you want to change colors of chart,
+   write color parameters at source script::
+
+      .. linechart::
+
+         bicycle: 15, 35, 20, 40
+         bicycle.color: ff0000
+         car: 60, 75, 60, 30
+         car.color: 0000ff
+
+   .. linechart::
+
+      bicycle: 15, 35, 20, 40
+      bicycle.color: ff0000
+      car: 60, 75, 60, 30
+      car.color: 0000ff
+
 
 .. describe:: .. linechartxy::
 
 
          bicycle: 15, 25, 20, 30
          bicycle.color: ff0000
+         bicycle.axis: x
+         bicycle.axis_label: slow, fast
          car: 40, 50, 60, 45
          car.color: 0000ff
 
 
       bicycle: 15, 25, 20, 30
       bicycle.color: ff0000
+      bicycle.axis: x
+      bicycle.axis_label: slow, fast
       car: 40, 50, 60, 45
       car.color: 0000ff
 
 
          bicycle: 15, 25, 20, 30
          bicycle.color: ff0000
+         bicycle.axis: y
+         bicycle.axis_label: slow, fast
          car: 40, 50, 60, 45
          car.color: 0000ff
 
 
       bicycle: 15, 25, 20, 30
       bicycle.color: ff0000
+      bicycle.axis: y
+      bicycle.axis_label: slow, fast
       car: 40, 50, 60, 45
       car.color: 0000ff
 
 
          bicycle: 15, 25, 20, 30
          bicycle.color: ff0000
+         bicycle.axis: x
+         bicycle.axis_label: slow, fast
          car: 40, 50, 60, 45
          car.color: 0000ff
 
 
       bicycle: 15, 25, 20, 30
       bicycle.color: ff0000
+      bicycle.axis: x
+      bicycle.axis_label: slow, fast
       car: 40, 50, 60, 45
       car.color: 0000ff
 
 
          bicycle: 15, 25, 20, 30
          bicycle.color: ff0000
+         bicycle.axis: y
+         bicycle.axis_label: slow, fast
          car: 40, 50, 60, 45
          car.color: 0000ff
 
 
       bicycle: 15, 25, 20, 30
       bicycle.color: ff0000
+      bicycle.axis: y
+      bicycle.axis_label: slow, fast
       car: 40, 50, 60, 45
       car.color: 0000ff
 
    .. plotchart::
 
       data: (50, 60), (75, 20), (20, 30), (10, 70), (45, 10)
+      data.axis: x, y
+      data.axis_label: (slow, fast), (low, high)
 
 
 Graphviz charts on Google Chart

googlechart/sphinxcontrib/googlechart/core.py

         colors = ",".join(chart.colors)
         labels = "|".join(chart.labels)
 
-        return dict(chd=data, chdl=labels, chco=colors)
+        axes = ",".join(n[0] for n in chart.axes)
+        _labels = ([str(i) + ":"] + n for i, n in chart.axis_labels.items())
+        axis_labels = "|".join("|".join(n) for n in _labels)
+
+        params = dict(chd=data, chdl=labels, chco=colors)
+        if chart.axes:
+            params['chxt'] = axes
+            params['chxl'] = axis_labels
+
+        return params
 
     def _url_for_linechart_xy(self, chart):
         series = []
         colors = ",".join(chart.colors)
         labels = "|".join(chart.labels)
 
-        return dict(chd=data, chdl=labels, chco=colors)
+        axes = []
+        if chart.axes:
+            axes = ",".join(chart.axes[0])
+
+        _labels = []
+        if chart.axis_labels:
+            _labels = chart.axis_labels[0]
+
+        if _labels and isinstance(_labels[0], tuple):
+            _labels = ([str(i) + ":"] + list(n) for i, n in enumerate(_labels))
+        axis_labels = "|".join("|".join(n) for n in _labels)
+
+        params = dict(chd=data, chdl=labels, chco=colors)
+        if chart.axes:
+            params['chxt'] = axes
+            params['chxl'] = axis_labels
+
+        return params
 
     def _url_for_barchart(self, chart):
         data = "t:" + "|".join(",".join(n) for n in chart.items)
         colors = ",".join(chart.colors)
         labels = "|".join(chart.labels)
 
-        return dict(chd=data, chdl=labels, chco=colors)
+        axes = ",".join(n[0] for n in chart.axes)
+        _labels = ([str(i) + ":"] + n for i, n in chart.axis_labels.items())
+        axis_labels = "|".join("|".join(n) for n in _labels)
+
+        params = dict(chd=data, chdl=labels, chco=colors)
+        if chart.axes:
+            params['chxt'] = axes
+            params['chxl'] = axis_labels
+
+        return params
 
     def _url_for_venndiagram(self, chart):
         data = "t:" + ",".join(chart.items.next())
     def _url_for_spotchart(self, chart):
         data = "t:" + "|".join(",".join(n) for n in zip(*chart.items.next()))
 
-        return dict(chd=data)
+        axes = []
+        if chart.axes:
+            axes = ",".join(chart.axes[0])
+
+        _labels = []
+        if chart.axis_labels:
+            _labels = chart.axis_labels[0]
+
+        if _labels and isinstance(_labels[0], tuple):
+            _labels = ([str(i) + ":"] + list(n) for i, n in enumerate(_labels))
+        axis_labels = "|".join("|".join(n) for n in _labels)
+
+        params = dict(chd=data)
+        if chart.axes:
+            params['chxt'] = axes
+            params['chxl'] = axis_labels
+
+        return params
 
     def _url_for_graphviz(self):
         _type = self.options.get('type', 'dot')

googlechart/sphinxcontrib/googlechart/parser.py

 
         return colors
 
+    @property
+    def axes(self):
+        axes = []
+
+        exist = False
+        for key in self._order:
+            key += ".axis"
+
+            if key in self._items:
+                exist = True
+                axes.append(self._items[key])
+
+        if not exist:
+            axes = []
+
+        return axes
+
+    @property
+    def axis_labels(self):
+        labels = {}
+
+        for i, key in enumerate(self._order):
+            key += ".axis_label"
+
+            if key in self._items:
+                labels[i] = self._items[key]
+
+        return labels
+
 
 def parse_string(code):
     tree = parse(tokenize(code))