wireservice / leather

Python charting for 80% of humans.
https://leather.readthedocs.io
MIT License
330 stars 30 forks source link

Automatically coerce key values to strings #67

Closed cryzed closed 8 years ago

cryzed commented 8 years ago

Currently using non-string key values in the data set is impossible. When changing the columns example to only include non-string values the following exception is thrown:

Traceback (most recent call last):
  File "/home/cryzed/Documents/Code/Sandbox/columns.py", line 12, in <module>
    chart.to_svg('examples/charts/columns.svg')
  File "/home/cryzed/.conda/envs/Sandbox3/lib/python3.5/site-packages/leather/chart.py", line 326, in to_svg
    group = self.to_svg_group(width, height)
  File "/home/cryzed/.conda/envs/Sandbox3/lib/python3.5/site-packages/leather/chart.py", line 291, in to_svg_group
    series_group.append(series.to_svg(canvas_width, canvas_height, x_scale, y_scale))
  File "/home/cryzed/.conda/envs/Sandbox3/lib/python3.5/site-packages/leather/series.py", line 126, in to_svg
    return self._shape.to_svg(width, height, x_scale, y_scale, self)
  File "/home/cryzed/.conda/envs/Sandbox3/lib/python3.5/site-packages/leather/shapes/columns.py", line 32, in to_svg
    x1, x2 = x_scale.project_interval(x, 0, width)
  File "/home/cryzed/.conda/envs/Sandbox3/lib/python3.5/site-packages/leather/scales/linear.py", line 32, in project_interval
    raise NotImplementedError
NotImplementedError

The object's string representation should be used for the text display in the chart. Comparison between used key objects (for sorting etc.) can obviously still be done before coercing them to strings.

onyxfish commented 8 years ago

Leather takes the opinionated stance that you intend for the type to be the one you provide. If you want to do bar or column labels, those have to be text, so you have to supply text. The bug you're hitting is because by supplying numbers agate assumes you intend to position the bars as intervals across a linear domain, which I haven't implemented yet (though I will).

Going to close this ticket out. I do think it's confusing now, but once the LinearScale interval method is implemented the behavior will be consistent with other scale/data types.

cryzed commented 8 years ago

I see, that makes sense.