You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.7 KiB

4 years ago
  1. # Copyright 2015 Bloomberg Finance L.P.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. r"""
  15. =======
  16. Toolbar
  17. =======
  18. .. currentmodule:: bqplot.toolbar
  19. .. autosummary::
  20. :toctree: _generate/
  21. Toolbar
  22. """
  23. from traitlets import Unicode, Instance, Bool
  24. from ipywidgets import DOMWidget, register, widget_serialization
  25. from .interacts import PanZoom
  26. from .figure import Figure
  27. from ._version import __frontend_version__
  28. @register
  29. class Toolbar(DOMWidget):
  30. """Default toolbar for bqplot figures.
  31. The default toolbar provides three buttons:
  32. - A *Panzoom* toggle button which enables panning and zooming the figure.
  33. - A *Save* button to save the figure as a png image.
  34. - A *Reset* button, which resets the figure position to its original
  35. state.
  36. When the *Panzoom* button is toggled to True for the first time, a new
  37. instance of ``PanZoom`` widget is created.
  38. The created ``PanZoom`` widget uses the scales of all the marks that are on
  39. the figure at this point.
  40. When the *PanZoom* widget is toggled to False, the figure retrieves its
  41. previous interaction.
  42. When the *Reset* button is pressed, the ``PanZoom`` widget is deleted and
  43. the figure scales reset to their initial state. We are back to the case
  44. where the PanZoom widget has never been set.
  45. If new marks are added to the figure after the panzoom button is toggled,
  46. and these use new scales, those scales will not be panned or zoomed,
  47. unless the reset button is clicked.
  48. Attributes
  49. ----------
  50. figure: instance of Figure
  51. The figure to which the toolbar will apply.
  52. """
  53. figure = Instance(Figure).tag(sync=True, **widget_serialization)
  54. _panning = Bool(read_only=True).tag(sync=True)
  55. _panzoom = Instance(PanZoom, default_value=None, allow_none=True,
  56. read_only=True).tag(sync=True, **widget_serialization)
  57. _view_name = Unicode('Toolbar').tag(sync=True)
  58. _model_name = Unicode('ToolbarModel').tag(sync=True)
  59. _view_module = Unicode('bqplot').tag(sync=True)
  60. _model_module = Unicode('bqplot').tag(sync=True)
  61. _view_module_version = Unicode(__frontend_version__).tag(sync=True)
  62. _model_module_version = Unicode(__frontend_version__).tag(sync=True)