Package com.digitizer.io
Class JsonExporter
java.lang.Object
com.digitizer.io.JsonExporter
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
y2labelproperty in theProjectJson. - Each dataset object contains a boolean
use_secondary_yflag set totruewhen 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.
ProjectJson model.-
Method Summary
Modifier and TypeMethodDescriptionconvertJsonToDatasets(ProjectJson project, CalibrationState calibration) Converts imported JSON data back into application objects.static voidexportToJson(String filePath, String title, String xlabel, String ylabel, String y2label, CalibrationState calibration, List<Dataset> datasets) Exports project data to a JSON file.static ProjectJsonimportFromJson(String filePath) Imports project data from a JSON file.
-
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_yflag.- Parameters:
filePath- the path where the JSON file will be writtentitle- the project titlexlabel- the x-axis labelylabel- the y-axis labely2label- 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
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 failscom.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_yflag (mapping it to eachDataset'ssetUseSecondaryYAxisproperty) so imported projects preserve secondary-axis assignments.- Parameters:
project- the ProjectJson object imported from filecalibration- the CalibrationState to populate- Returns:
- a list of Dataset objects
-