|
| 1 | +from geo import AitoffAxes, HammerAxes, LambertAxes |
| 2 | +from polar import PolarAxes |
| 3 | +from matplotlib import axes |
| 4 | + |
| 5 | +class ProjectionRegistry(object): |
| 6 | + def __init__(self): |
| 7 | + self._all_projection_types = {} |
| 8 | + |
| 9 | + def register(self, *projections): |
| 10 | + for projection in projections: |
| 11 | + name = projection.name |
| 12 | + self._all_projection_types[name] = projection |
| 13 | + |
| 14 | + def get_projection_class(self, name): |
| 15 | + return self._all_projection_types[name] |
| 16 | + |
| 17 | + def get_projection_names(self): |
| 18 | + names = self._all_projection_types.keys() |
| 19 | + names.sort() |
| 20 | + return names |
| 21 | +projection_registry = ProjectionRegistry() |
| 22 | + |
| 23 | +projection_registry.register( |
| 24 | + axes.Axes, |
| 25 | + PolarAxes, |
| 26 | + AitoffAxes, |
| 27 | + HammerAxes, |
| 28 | + LambertAxes) |
| 29 | + |
| 30 | + |
| 31 | +def register_projection(cls): |
| 32 | + projection_registry.register(cls) |
| 33 | + |
| 34 | +def get_projection_class(projection): |
| 35 | + if projection is None: |
| 36 | + projection = 'rectilinear' |
| 37 | + |
| 38 | + try: |
| 39 | + return projection_registry.get_projection_class(projection) |
| 40 | + except KeyError: |
| 41 | + raise ValueError("Unknown projection '%s'" % projection) |
| 42 | + |
| 43 | +def projection_factory(projection, figure, rect, **kwargs): |
| 44 | + return get_projection_class(projection)(figure, rect, **kwargs) |
| 45 | + |
| 46 | +def get_projection_names(): |
| 47 | + return projection_registry.get_projection_names() |
0 commit comments