Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 0 additions & 123 deletions python/out.svg

This file was deleted.

25 changes: 16 additions & 9 deletions python/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Class that generates composite and reference lines svg elements
class Plot:
def __init__(self, title=None, xmin=None, xmax=None, ymin=None, ymax=None, xlabel=None, ylabel=None,
opacity=None, smoothing=None, bp_shift=None, combined=False, color_trace=False, hide_legend=False):
opacity=None, smoothing=None, bp_shift=None, combined=False, color_trace=False, hide_legend=False, resolution=None):
# Set variables to defaults if argument passed into constructor was None
self.title = title if title is not None else "Composite plot"
self.xmin = xmin if xmin is not None else -500
Expand All @@ -29,6 +29,9 @@ def __init__(self, title=None, xmin=None, xmax=None, ymin=None, ymax=None, xlabe
self.width = 460
self.height = 300
self.margins = {'top': 30, 'right': 170, 'bottom': 35, 'left': 40}
resolution = (int(resolution.split("x")[0]), int(resolution.split("x")[1])) if resolution is not None else (300, 300)
self.width = 160 + resolution[0]
self.height = resolution[1]
# Create groups for adding composites and reference lines
self.plot = document.createElement("g")
self.composite_group = document.createElement("g")
Expand Down Expand Up @@ -262,16 +265,19 @@ def scale_axes(self, xmin=None, xmax=None, ymin=None, ymax=None):
self.yscale = YScale(self)

# Finds the max/min x and y values from composites on plot and scales axes accordingly
def autoscale_axes(self, allow_shrink):
def autoscale_axes(self, args):
xmin = min([group.xmin for group in self.composites])
xmax = max([group.xmax for group in self.composites])
if self.combined:
if self.combined:
ymin = 0
ymax = round(max([(group.sense[i] + group.sense[i]) * group.scale for group in self.composites for i in range(min(len(group.sense), len(group.anti)))]), 2)
else:
ymin = min([-val * group.scale for group in self.composites for val in group.anti])
ymax = max([val * group.scale for group in self.composites for val in group.sense])
self.scale_axes(xmin,xmax,ymin if allow_shrink else None,ymax if allow_shrink else None)
if args.no_resize:
self.scale_axes(args.xmin, args.xmax, args.ymin, args.ymax)
else:
self.scale_axes(args.xmin or xmin, args.xmax or xmax, args.ymin or ymin, args.ymax or ymax)

# Adds composite group object to plot
def add_composite_group(self, composite_group):
Expand Down Expand Up @@ -482,10 +488,10 @@ def generateGradients(self, opacity, i, color, secondary_color=None):
# Class that mimics d3 scaleLinear() for x-axis of plot
class XScale:
def __init__(self, plot):
self.plot = plot
svg_width = plot.width - (plot.margins.get('right') + plot.margins.get('left'))
self.domain = [plot.xmin, plot.xmax, plot.xmax - plot.xmin]
self.range = [plot.margins.get('left'), plot.width - plot.margins.get('right'), plot.width - (plot.margins.get('right') + plot.margins.get('left'))]
self.zero = (plot.width - (plot.margins.get('right') + plot.margins.get('left'))) * (abs(plot.xmin) / (abs(plot.xmin) + abs(plot.xmax))) + plot.margins.get('left')
self.range = [plot.margins.get('left'), plot.width - plot.margins.get('right'), svg_width]
self.zero = svg_width * (abs(plot.xmin) / (abs(plot.xmin) + abs(plot.xmax))) + plot.margins.get('left')
# Returns position given bp
def get(self, value):
return (self.range[2] / self.domain[2]) * value + self.zero
Expand All @@ -495,9 +501,10 @@ def inverse(self, value):
# Class that mimics d3 scaleLinear() for y-axis of plot
class YScale:
def __init__(self, plot):
svg_height = plot.height - (plot.margins.get('top') + plot.margins.get('bottom'))
self.domain = [plot.ymin, plot.ymax, abs(plot.ymax) + abs(plot.ymin)]
self.range = [plot.margins.get('top'), plot.height - plot.margins.get('bottom'), plot.height - (plot.margins.get('top') + plot.margins.get('bottom'))]
self.zero = (plot.height - (plot.margins.get('top') + plot.margins.get('bottom'))) * (0.5) + plot.margins.get('top') if plot.combined is False else self.range[1]
self.range = [plot.margins.get('top'), plot.height - plot.margins.get('bottom'), svg_height]
self.zero = svg_height * (abs(plot.ymax) / (abs(plot.ymin) + abs(plot.ymax))) + plot.margins.get('top') if plot.combined is False else self.range[1]
# Returns position on svg given occupancy
def get(self, value):
return self.zero - (self.range[2] / self.domain[2]) * value
Expand Down
16 changes: 7 additions & 9 deletions python/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ def main():
plot_parser.add_argument("--xmin",type=int)
plot_parser.add_argument("--xmax",type=int)
plot_parser.add_argument("--xlabel", nargs="+")
plot_parser.add_argument("--ymin", type=int)
plot_parser.add_argument("--ymax", type=int)
plot_parser.add_argument("--ymin", type=float)
plot_parser.add_argument("--ymax", type=float)
plot_parser.add_argument("--ylabel", nargs="+")
plot_parser.add_argument("--color-trace", action="store_true", default=False)
plot_parser.add_argument("--combined", action="store_true", default=False)
plot_parser.add_argument("--hide-legend", action="store_true", default=False)
plot_parser.add_argument("--no-resize", action="store_true", default=False)
plot_parser.add_argument("--no-shrink", action="store_true", default=False)
plot_parser.add_argument("--resolution")
plot_parser.add_argument("--out")
plot_parser.add_argument("--export-json")
plot_parser.add_argument("--import-json")
Expand All @@ -69,7 +70,8 @@ def main():
# Create plot based on plot subcommand, default values in Plot class will be used if argument is not specified
plot_args = plot_parser.parse_args(plot_command.split())
p = plot.Plot(title=" ".join(plot_args.title) if plot_args.title is not None else None, xmin=plot_args.xmin, xmax=plot_args.xmax, ymin=plot_args.ymin, ymax=plot_args.ymax, xlabel=" ".join(plot_args.xlabel) if plot_args.xlabel is not None else None,
ylabel=" ".join(plot_args.ylabel) if plot_args.ylabel is not None else None, opacity=plot_args.opacity, smoothing=plot_args.smoothing, bp_shift=plot_args.bp_shift, combined=plot_args.combined, color_trace=plot_args.color_trace, hide_legend=plot_args.hide_legend)
ylabel=" ".join(plot_args.ylabel) if plot_args.ylabel is not None else None, opacity=plot_args.opacity, smoothing=plot_args.smoothing, bp_shift=plot_args.bp_shift, combined=plot_args.combined, color_trace=plot_args.color_trace, hide_legend=plot_args.hide_legend,
resolution=plot_args.resolution)

# Create arrays for default composite names and colors
names = range(1, len(composite_commands) + 1)
Expand Down Expand Up @@ -115,12 +117,8 @@ def main():
elif plot_args.import_settings_json:
p.import_data(plot_args.import_settings_json, plot_args, False)

# If --no-shrink is specified, don't change y-axis but resize x-axis
if plot_args.no_shrink:
p.autoscale_axes(False)
# If --no-resize is specified, don't change either axis
elif not plot_args.no_resize:
p.autoscale_axes(True)
# Autoscale axis if options don't specify limits
p.autoscale_axes(plot_args)

p.plot_composites()

Expand Down
4 changes: 2 additions & 2 deletions python/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The `composite` and `reference-line` subcommands can be repeated for as many com
plot [plot options]
```

The `plot` subcommand takes no positional arguments, and the options specify properties for the entire plot, such as domain, range, and the axis labels. Options can also be used to specify default properties for all composites such as `opacity` and `smoothing`. This implementation of the plotter autoscales the axes to fit the largest composite by default, ignoring the `xmin`, `xmax`, `ymin`, and `ymax` options unless `--no-shrink` or `--no-resize` is specified.
The `plot` subcommand takes no positional arguments, and the options specify properties for the entire plot, such as domain, range, and the axis labels. Options can also be used to specify default properties for all composites such as `opacity` and `smoothing`. This implementation of the plotter autoscales the axes to fit the largest composite by default, ignoring the `xmin`, `xmax`, `ymin`, and `ymax` options unless `--no-resize` is specified.

The available options for the `plot` subcommand are:

Expand All @@ -42,7 +42,7 @@ The available options for the `plot` subcommand are:
| --combined | Boolean | Draws a combined plot | False |
| --hide-legend | Boolean | Hides the plot legend | False |
| --no-resize | Boolean | Prevents plotter from autoscaling the x and y axes | False |
| --no-shrink | Boolean | Prevents plotter from autoscaling the y-axis | False |
| --resolution | String | Resolution of the output. Can influence aspect ratio | "300x300" |
| --out | String | Name and filepath of svg output | `out.svg` |
| --export-json | String | JSON file to export composites and plot settings | `None` |
| --import-json | String | JSON file to import composites and plot settings | `None` |
Expand Down
Loading