-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port custom tools, streams and links from EarthSim (#377)
- Loading branch information
1 parent
ef14244
commit f19cb0d
Showing
30 changed files
with
1,436 additions
and
68 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,82 @@ | ||
import param | ||
|
||
import cartopy.crs as ccrs | ||
|
||
from holoviews.annotators import ( | ||
Annotator, PathAnnotator, PolyAnnotator, PointAnnotator, BoxAnnotator # noqa | ||
) | ||
from holoviews.plotting.links import DataLink, VertexTableLink as hvVertexTableLink | ||
from panel.util import param_name | ||
|
||
from .models.custom_tools import CheckpointTool, RestoreTool, ClearTool | ||
from .links import VertexTableLink, PointTableLink, HvRectanglesTableLink, RectanglesTableLink | ||
from .operation import project | ||
from .streams import PolyVertexDraw, PolyVertexEdit | ||
|
||
Annotator._tools = [CheckpointTool, RestoreTool, ClearTool] | ||
Annotator.table_transforms.append(project.instance(projection=ccrs.PlateCarree())) | ||
|
||
def get_point_table_link(self, source, target): | ||
if hasattr(source.callback.inputs[0], 'crs'): | ||
return PointTableLink(source, target) | ||
else: | ||
return DataLink(source, target) | ||
|
||
PointAnnotator._link_type = get_point_table_link | ||
|
||
def get_rectangles_table_link(self, source, target): | ||
if hasattr(source.callback.inputs[0], 'crs'): | ||
return RectanglesTableLink(source, target) | ||
else: | ||
return HvRectanglesTableLink(source, target) | ||
|
||
BoxAnnotator._link_type = get_rectangles_table_link | ||
|
||
def get_vertex_table_link(self, source, target): | ||
if hasattr(source.callback.inputs[0], 'crs'): | ||
return VertexTableLink(source, target) | ||
else: | ||
return hvVertexTableLink(source, target) | ||
|
||
PathAnnotator._vertex_table_link = get_vertex_table_link | ||
PolyAnnotator._vertex_table_link = get_vertex_table_link | ||
|
||
def initialize_tools(plot, element): | ||
""" | ||
Initializes the Checkpoint and Restore tools. | ||
""" | ||
cds = plot.handles['source'] | ||
checkpoint = plot.state.select(type=CheckpointTool) | ||
restore = plot.state.select(type=RestoreTool) | ||
clear = plot.state.select(type=ClearTool) | ||
if checkpoint: | ||
checkpoint[0].sources.append(cds) | ||
if restore: | ||
restore[0].sources.append(cds) | ||
if clear: | ||
clear[0].sources.append(cds) | ||
|
||
Annotator._extra_opts['hooks'] = [initialize_tools] | ||
|
||
|
||
class PathBreakingAnnotator(PathAnnotator): | ||
|
||
feature_style = param.Dict(default={'fill_color': 'blue', 'size': 10}, doc=""" | ||
Styling to apply to the feature vertices.""") | ||
|
||
node_style = param.Dict(default={'fill_color': 'indianred', 'size': 6}, doc=""" | ||
Styling to apply to the node vertices.""") | ||
|
||
def _init_stream(self): | ||
name = param_name(self.name) | ||
style_kwargs = dict(node_style=self.node_style, feature_style=self.feature_style) | ||
self._stream = PolyVertexDraw( | ||
source=self.plot, data={}, num_objects=self.num_objects, | ||
show_vertices=self.show_vertices, tooltip='%s Tool' % name, | ||
**style_kwargs | ||
) | ||
if self.edit_vertices: | ||
self._vertex_stream = PolyVertexEdit( | ||
source=self.plot, tooltip='%s Edit Tool' % name, | ||
**style_kwargs | ||
) |
This file contains 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 @@ | ||
{} |
This file contains 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 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,5 @@ | ||
import * as GeoViews from "./models" | ||
export {GeoViews} | ||
|
||
import {register_models} from "@bokehjs/base" | ||
register_models(GeoViews as any) |
Oops, something went wrong.