-
Notifications
You must be signed in to change notification settings - Fork 98
Revive ScalyPlot #744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Revive ScalyPlot #744
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| """ A Plot which uses ScaleSystems for its ticks. | ||
| """ | ||
|
|
||
| from traits.api import Any | ||
|
|
||
| from chaco.axis import PlotAxis | ||
| from chaco.data_range_2d import DataRange2D | ||
| from chaco.grid import PlotGrid | ||
| from chaco.linear_mapper import LinearMapper | ||
| from chaco.log_mapper import LogMapper | ||
| from chaco.plot import Plot | ||
| from chaco.scales.scales import DefaultScale, LogScale, ScaleSystem | ||
| from chaco.scales_tick_generator import ScalesTickGenerator | ||
|
|
||
|
|
||
| def add_default_axes(plot, orientation="normal", vtitle="", htitle=""): | ||
| """ | ||
| Creates left and bottom axes for a plot. Assumes that the index is | ||
| horizontal and value is vertical by default; set orientation to | ||
| something other than "normal" if they are flipped. | ||
| """ | ||
| if orientation in ("normal", "h"): | ||
| v_mapper = plot.value_mapper | ||
| h_mapper = plot.index_mapper | ||
| else: | ||
| v_mapper = plot.index_mapper | ||
| h_mapper = plot.value_mapper | ||
|
|
||
| yticks = ScalesTickGenerator() | ||
| left = PlotAxis( | ||
| orientation="left", | ||
| title=vtitle, | ||
| mapper=v_mapper, | ||
| component=plot, | ||
| tick_generator=yticks, | ||
| ) | ||
|
|
||
| xticks = ScalesTickGenerator() | ||
| bottom = PlotAxis( | ||
| orientation="bottom", | ||
| title=htitle, | ||
| mapper=h_mapper, | ||
| component=plot, | ||
| tick_generator=xticks, | ||
| ) | ||
|
|
||
| plot.underlays.append(left) | ||
| plot.underlays.append(bottom) | ||
| return left, bottom | ||
|
|
||
|
|
||
| class ScalyPlot(Plot): | ||
| x_axis = Any() | ||
| y_axis = Any() | ||
| x_ticks = Any() | ||
| y_ticks = Any() | ||
| linear_scale_factory = Any() | ||
| log_scale_factory = Any() | ||
|
|
||
| def _linear_scale_default(self): | ||
| return self._make_scale("linear") | ||
|
|
||
| def _log_scale_default(self): | ||
| return self._make_scale("log") | ||
|
|
||
| def _make_scale(self, scale_type="linear"): | ||
| """ Returns a new linear or log scale """ | ||
| if scale_type == "linear": | ||
| if self.linear_scale_factory is not None: | ||
| return self.linear_scale_factory() | ||
| else: | ||
| return ScaleSystem(DefaultScale()) | ||
| else: | ||
| if self.log_scale_factory is not None: | ||
| return self.log_scale_factory() | ||
| else: | ||
| return ScaleSystem(LogScale()) | ||
|
|
||
| def _init_components(self): | ||
| # Since this is called after the HasTraits constructor, we have to make | ||
| # sure that we don't blow away any components that the caller may have | ||
| # already set. | ||
|
|
||
| if self.range2d is None: | ||
| self.range2d = DataRange2D() | ||
|
|
||
| if self.index_mapper is None: | ||
| if self.index_scale == "linear": | ||
| imap = LinearMapper(range=self.range2d.x_range) | ||
| else: | ||
| imap = LogMapper(range=self.range2d.x_range) | ||
| self.index_mapper = imap | ||
|
|
||
| if self.value_mapper is None: | ||
| if self.value_scale == "linear": | ||
| vmap = LinearMapper(range=self.range2d.y_range) | ||
| else: | ||
| vmap = LogMapper(range=self.range2d.y_range) | ||
| self.value_mapper = vmap | ||
|
|
||
| if self.x_ticks is None: | ||
| self.x_ticks = ScalesTickGenerator( | ||
| scale=self._make_scale(self.index_scale) | ||
| ) | ||
| if self.y_ticks is None: | ||
| self.y_ticks = ScalesTickGenerator( | ||
| scale=self._make_scale(self.value_scale) | ||
| ) | ||
|
|
||
| if self.x_grid is None: | ||
| self.x_grid = PlotGrid( | ||
| mapper=self.x_mapper, | ||
| orientation="vertical", | ||
| line_color="lightgray", | ||
| line_style="dot", | ||
| component=self, | ||
| tick_generator=self.x_ticks, | ||
| ) | ||
| if self.y_grid is None: | ||
| self.y_grid = PlotGrid( | ||
| mapper=self.y_mapper, | ||
| orientation="horizontal", | ||
| line_color="lightgray", | ||
| line_style="dot", | ||
| component=self, | ||
| tick_generator=self.y_ticks, | ||
| ) | ||
| if self.x_axis is None: | ||
| self.x_axis = PlotAxis( | ||
| mapper=self.x_mapper, | ||
| orientation="bottom", | ||
| component=self, | ||
| tick_generator=self.x_ticks, | ||
| ) | ||
| if self.y_axis is None: | ||
| self.y_axis = PlotAxis( | ||
| mapper=self.y_mapper, | ||
| orientation="left", | ||
| component=self, | ||
| tick_generator=self.y_ticks, | ||
| ) | ||
|
|
||
| def _index_scale_changed(self, old, new): | ||
| Plot._index_scale_changed(self, old, new) | ||
| # Now adjust the ScaleSystems. | ||
| self.x_ticks.scale = self._make_scale(self.index_scale) | ||
|
|
||
| def _value_scale_changed(self, old, new): | ||
| Plot._value_scale_changed(self, old, new) | ||
| # Now adjust the ScaleSystems. | ||
| self.y_ticks.scale = self._make_scale(self.value_scale) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not entirely sure how this works. Shouldn't this be
super()._index_scale_changed(old, new)? Same comment below withPlot._value_scale_changed(...)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, super makes more sense / is cleaner here. This code I believe is also untested, I simply copy pasted the old file to revive it.
It could probably use a closer look / some updates / some new tests. I can do so in some follow up PRs