Class JsonExporter

java.lang.Object
com.digitizer.io.JsonExporter

public class JsonExporter extends Object
Handles JSON import and export of graph digitizer projects.

The JSON format contains project metadata (title and axis labels), calibration settings (numeric ranges and log flags) and the list of datasets and their points. Export behavior notes:

  • When provided, the secondary (right-hand) Y-axis title is written to the top-level y2label property in the ProjectJson.
  • Each dataset object contains a boolean use_secondary_y flag set to true when that dataset is assigned to the secondary Y axis.
  • Datasets that contain no points are omitted from the exported JSON to avoid clutter and empty series entries.
The export path is compatible with the ProjectJson model.
  • Method Details

    • exportToJson

      public static void exportToJson(String filePath, String title, String xlabel, String ylabel, String y2label, CalibrationState calibration, List<Dataset> datasets) throws IOException
      Exports project data to a JSON file.

      The exporter will skip any datasets that have no points (they will not appear in the resulting JSON). Each dataset entry includes its name, color, point list, visibility and the use_secondary_y flag.

      Parameters:
      filePath - the path where the JSON file will be written
      title - the project title
      xlabel - the x-axis label
      ylabel - the y-axis label
      y2label - the secondary (right-hand) Y-axis label (may be null/empty)
      calibration - the calibration state (may be null; defaults applied if null)
      datasets - the list of datasets to export
      Throws:
      IOException - if writing to the file fails
    • importFromJson

      public static ProjectJson importFromJson(String filePath) throws IOException
      Imports project data from a JSON file.
      Parameters:
      filePath - the path to the JSON file to read
      Returns:
      a ProjectJson object containing the imported data
      Throws:
      IOException - if reading from the file fails
      com.google.gson.JsonSyntaxException - if the JSON is malformed
    • convertJsonToDatasets

      public static List<Dataset> convertJsonToDatasets(ProjectJson project, CalibrationState calibration)
      Converts imported JSON data back into application objects.

      The converter restores dataset visibility and the use_secondary_y flag (mapping it to each Dataset's setUseSecondaryYAxis property) so imported projects preserve secondary-axis assignments.

      Parameters:
      project - the ProjectJson object imported from file
      calibration - the CalibrationState to populate
      Returns:
      a list of Dataset objects