From df4aa861ca109700992af9e6ab9f26e67b395d06 Mon Sep 17 00:00:00 2001 From: dgelessus <dgelessus@users.noreply.github.com> Date: Thu, 3 Dec 2020 21:03:43 +0100 Subject: [PATCH] Use new high-level dot and table visualization APIs --- .../de/prob2/jupyter/commands/DotCommand.java | 13 ++++++------- .../de/prob2/jupyter/commands/TableCommand.java | 15 +++++---------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/main/java/de/prob2/jupyter/commands/DotCommand.java b/src/main/java/de/prob2/jupyter/commands/DotCommand.java index 98cbedf..d7242cd 100644 --- a/src/main/java/de/prob2/jupyter/commands/DotCommand.java +++ b/src/main/java/de/prob2/jupyter/commands/DotCommand.java @@ -15,7 +15,7 @@ import com.google.inject.Inject; import com.google.inject.Provider; import de.prob.animator.command.GetAllDotCommands; -import de.prob.animator.command.GetSvgForVisualizationCommand; +import de.prob.animator.domainobjects.DotVisualizationCommand; import de.prob.animator.domainobjects.DynamicCommandItem; import de.prob.animator.domainobjects.FormulaExpand; import de.prob.animator.domainobjects.IEvalElement; @@ -105,9 +105,8 @@ public final class DotCommand implements Command { } final Trace trace = this.animationSelector.getCurrentTrace(); - final GetAllDotCommands cmd1 = new GetAllDotCommands(trace.getCurrentState()); - trace.getStateSpace().execute(cmd1); - final DynamicCommandItem item = cmd1.getCommands().stream() + final DotVisualizationCommand dotCommand = DotVisualizationCommand.getAll(trace.getCurrentState()) + .stream() .filter(i -> command.equals(i.getCommand())) .findAny() .orElseThrow(() -> new UserErrorException("No such dot command: " + command)); @@ -118,9 +117,8 @@ public final class DotCommand implements Command { } catch (final IOException e) { throw new UncheckedIOException("Failed to create temp file", e); } - final GetSvgForVisualizationCommand cmd2 = new GetSvgForVisualizationCommand(trace.getCurrentState(), item, outPath.toFile(), dotCommandArgs); // Provide source code (if any) to error highlighter - final Runnable execute = () -> trace.getStateSpace().execute(cmd2); + final Runnable execute = () -> dotCommand.visualizeAsSvgToFile(outPath, dotCommandArgs); if (code != null) { CommandUtils.withSourceCode(code, execute); } else { @@ -153,7 +151,8 @@ public final class DotCommand implements Command { final GetAllDotCommands cmd = new GetAllDotCommands(trace.getCurrentState()); trace.getStateSpace().execute(cmd); final String prefix = commandName.substring(0, at); - final List<String> commands = cmd.getCommands().stream() + final List<String> commands = DotVisualizationCommand.getAll(trace.getCurrentState()) + .stream() .filter(DynamicCommandItem::isAvailable) .map(DynamicCommandItem::getCommand) .filter(s -> s.startsWith(prefix)) diff --git a/src/main/java/de/prob2/jupyter/commands/TableCommand.java b/src/main/java/de/prob2/jupyter/commands/TableCommand.java index d2d75c0..700da4a 100644 --- a/src/main/java/de/prob2/jupyter/commands/TableCommand.java +++ b/src/main/java/de/prob2/jupyter/commands/TableCommand.java @@ -7,12 +7,10 @@ import java.util.stream.Collectors; import com.google.inject.Inject; import com.google.inject.Provider; -import de.prob.animator.command.GetAllTableCommands; -import de.prob.animator.command.GetTableForVisualizationCommand; -import de.prob.animator.domainobjects.DynamicCommandItem; import de.prob.animator.domainobjects.FormulaExpand; import de.prob.animator.domainobjects.IEvalElement; import de.prob.animator.domainobjects.TableData; +import de.prob.animator.domainobjects.TableVisualizationCommand; import de.prob.statespace.AnimationSelector; import de.prob.statespace.Trace; import de.prob.unicode.UnicodeTranslator; @@ -75,15 +73,12 @@ public final class TableCommand implements Command { final String code = kernel.insertLetVariables(args.get(EXPRESSION_PARAM)); final IEvalElement formula = CommandUtils.withSourceCode(code, () -> kernel.parseFormula(code, FormulaExpand.EXPAND)); - final GetAllTableCommands cmd1 = new GetAllTableCommands(trace.getCurrentState()); - trace.getStateSpace().execute(cmd1); - final DynamicCommandItem dc = cmd1.getCommands().stream() + final TableData table = TableVisualizationCommand.getAll(trace.getCurrentState()) + .stream() .filter(c -> "expr_as_table".equals(c.getCommand())) .findAny() - .orElseThrow(AssertionError::new); - final GetTableForVisualizationCommand cmd2 = new GetTableForVisualizationCommand(trace.getCurrentState(), dc, Collections.singletonList(formula)); - trace.getStateSpace().execute(cmd2); - final TableData table = cmd2.getTable(); + .orElseThrow(AssertionError::new) + .visualize(Collections.singletonList(formula)); final StringBuilder sbPlain = new StringBuilder(); final StringBuilder sbMarkdown = new StringBuilder(); -- GitLab