diff --git a/plot/axis.v b/plot/axis.v index 04ced55aa..4493a53ec 100644 --- a/plot/axis.v +++ b/plot/axis.v @@ -5,11 +5,11 @@ pub struct Axis { pub mut: title AxisTitle tickmode string = 'auto' - tick0 f64 - dtick f64 - tickvals []f64 - ticktext []string - range []f64 + tick0 f64 [omitempty] + dtick f64 [omitempty] + tickvals []f64 [omitempty] + ticktext []string [omitempty] + range []f64 [omitempty] } // AxisTitle handles needed data to render an axis title diff --git a/plot/plot.v b/plot/plot.v index 98df2766f..dd4adf735 100644 --- a/plot/plot.v +++ b/plot/plot.v @@ -32,6 +32,14 @@ pub fn (mut p Plot) add_annotation(annotation Annotation) Plot { } pub fn (mut p Plot) set_layout(layout Layout) Plot { - p.layout = layout + mut next_layout := layout + // Ensure that the layout range is specified correctly + if next_layout.xaxis.range.len != 2 { + next_layout.xaxis.range = []f64{} + } + if next_layout.yaxis.range.len != 2 { + next_layout.yaxis.range = []f64{} + } + p.layout = next_layout return p } diff --git a/plot/scripts/plotter.py b/plot/scripts/plotter.py index 09a270030..4a0581eb1 100644 --- a/plot/scripts/plotter.py +++ b/plot/scripts/plotter.py @@ -21,16 +21,6 @@ def load_json_file(file_handle): return json.load(file_handle) -def process_layout_range(layout, axis): - """ - Ensure that the layout range is specified correctly. - """ - if f'{axis}axis' in layout: - if 'range' in layout[f'{axis}axis']: - if len(layout[f'{axis}axis']['range']) != 2: - layout[f'{axis}axis']['range'] = None - - def map_trace_type_to_plotly_object(trace_type): """ Map vsl.plot.TraceType enum to Plotly objects. @@ -90,10 +80,6 @@ def main(): # Read layout JSON file. layout = load_json_file(args.layout) - # Ensure correct layout range specification. - for axis in ['x', 'y']: - process_layout_range(layout, axis) - # List of traces to be plotted. plot_data = [process_trace(trace) for trace in data]