Skip to content

Commit

Permalink
Merge pull request hail-is#32 from ammekk/coord_cartesian
Browse files Browse the repository at this point in the history
Coord cartesian
  • Loading branch information
johnc1231 authored Jan 5, 2022
2 parents 5fe6b45 + cf3cc1f commit 55ce114
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions hail/python/hail/plot2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .coord_cartesian import coord_cartesian
from .ggplot import ggplot
from .aes import aes
from .geoms import geom_line, geom_point, geom_text, geom_bar, geom_histogram, geom_hline, geom_func, geom_vline, geom_tile
Expand All @@ -20,6 +21,7 @@
"ggtitle",
"xlab",
"ylab",
"coord_cartesian",
"scale_x_continuous",
"scale_y_continuous",
"scale_x_discrete",
Expand Down
17 changes: 17 additions & 0 deletions hail/python/hail/plot2/coord_cartesian.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from .geoms import FigureAttribute


class CoordCartesian(FigureAttribute):
def __init__(self, xlim, ylim):
self.xlim = xlim
self.ylim = ylim

def apply_to_fig(self, fig_so_far):
if self.xlim is not None:
fig_so_far.update_xaxes(range=list(self.xlim))
if self.ylim is not None:
fig_so_far.update_yaxes(range=list(self.ylim))


def coord_cartesian(xlim=None, ylim=None):
return CoordCartesian(xlim, ylim)
10 changes: 8 additions & 2 deletions hail/python/hail/plot2/ggplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import hail as hl

from .coord_cartesian import CoordCartesian
from .geoms import Geom, FigureAttribute
from .labels import Labels
from .scale import Scale, scale_x_continuous, scale_x_genomic, scale_y_continuous, scale_x_discrete, scale_y_discrete
Expand All @@ -13,7 +14,7 @@

class GGPlot:

def __init__(self, ht, aes, geoms=[], labels=Labels(), scales=None,
def __init__(self, ht, aes, geoms=[], labels=Labels(), coord_cartesian=None, scales=None,
discrete_color_scale=plotly.colors.qualitative.D3, continuous_color_scale=plotly.colors.sequential.Viridis):
if scales is None:
scales = {}
Expand All @@ -22,6 +23,7 @@ def __init__(self, ht, aes, geoms=[], labels=Labels(), scales=None,
self.aes = aes
self.geoms = geoms
self.labels = labels
self.coord_cartesian = coord_cartesian
self.scales = scales
self.discrete_color_scale = discrete_color_scale
self.discrete_color_dict = {}
Expand All @@ -39,6 +41,8 @@ def __add__(self, other):
copied.add_default_scales(other.aes)
elif isinstance(other, Labels):
copied.labels = copied.labels.merge(other)
elif isinstance(other, CoordCartesian):
copied.coord_cartesian = other
elif isinstance(other, Scale):
copied.scales[other.aesthetic_name] = other
elif isinstance(other, Aesthetic):
Expand Down Expand Up @@ -77,7 +81,7 @@ def is_genomic_type(dtype):
self.scales["y"] = scale_y_discrete()

def copy(self):
return GGPlot(self.ht, self.aes, self.geoms[:], self.labels, self.scales,
return GGPlot(self.ht, self.aes, self.geoms[:], self.labels, self.coord_cartesian, self.scales,
self.discrete_color_scale, self.continuous_color_scale)

def render(self):
Expand Down Expand Up @@ -118,6 +122,8 @@ def render(self):
self.scales["x"].apply_to_fig(self, fig)
if self.scales.get("y") is not None:
self.scales["y"].apply_to_fig(self, fig)
if self.coord_cartesian is not None:
self.coord_cartesian.apply_to_fig(fig)

return fig

Expand Down

0 comments on commit 55ce114

Please sign in to comment.