-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor output on desktop to F#show() method
- Loading branch information
Showing
4 changed files
with
141 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -308,4 +308,86 @@ public static boolean isFileSystemEnabled(EvalEngine engine) { | |
* Use visjs.org JavaScript library for visualizing graph theory objects | ||
*/ | ||
public static boolean USE_VISJS = false; | ||
|
||
/** | ||
* HTML template for the <a href="https://visjs.org/">VIS-network</a> | ||
*/ | ||
public final static String VISJS_PAGE = // | ||
"<html>\n" + // | ||
"<head>\n" + // | ||
"<meta charset=\"utf-8\">\n" + // | ||
"<head>\n" + // | ||
" <title>VIS-Network</title>\n" + // | ||
"\n" + // | ||
" <script type=\"text/javascript\" src=\"https://cdn.jsdelivr.net/npm/[email protected]/dist/vis-network.min.js\"></script>\n" | ||
+ // | ||
" <style type=\"text/css\">\n" + // | ||
" #mynetwork {\n" + // | ||
" width: 600px;\n" + // | ||
" height: 400px;\n" + // | ||
" border: 1px solid lightgray;\n" + // | ||
" }\n" + // | ||
" </style>\n" + // | ||
"</head>\n" + // | ||
"<body>\n" + // | ||
"\n" + // | ||
"<h1>VIS-Network</h1>\n" + // | ||
"\n" + // | ||
"<div id=\"vis\"></div>\n" + // | ||
"\n" + // | ||
"<script type=\"text/javascript\">\n" + // | ||
"`1`\n" + // | ||
" // create a network\n" + // | ||
" var container = document.getElementById('vis');\n" + // | ||
" var data = {\n" + // | ||
" nodes: nodes,\n" + // | ||
" edges: edges\n" + // | ||
" };\n" + // | ||
" var options = {};\n" + // | ||
" var network = new vis.Network(container, data, options);\n" + // | ||
"</script>\n" + // | ||
"\n" + // | ||
"\n" + // | ||
"</body>\n" + // | ||
"</html>";// | ||
|
||
/** | ||
* HTML template for the <a href="https://github.com/paulmasson/mathcell">MathCell</a> and | ||
* <a href="https://github.com/paulmasson/math">Math</a> JavaScript libraries. | ||
*/ | ||
public final static String MATHCELL_PAGE = // | ||
"<html>\n" + // | ||
"<head>\n" + // | ||
"<meta charset=\"utf-8\">\n" + // | ||
"<title>MathCell</title>\n" + // | ||
"<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n" + // | ||
"<style></style>\n" + // | ||
"</head>\n" + // | ||
"\n" + // | ||
"<body>\n" + // | ||
"<script src=\"https://cdn.jsdelivr.net/gh/paulmasson/[email protected]/build/math.js\"></script>" + // | ||
"\n" + // | ||
"\n" + // | ||
"<script src=\"https://cdn.jsdelivr.net/gh/paulmasson/[email protected]/build/mathcell.js\"></script>\n" | ||
+ // | ||
"<script src=\"https://cdn.jsdelivr.net/gh/mathjax/[email protected]/MathJax.js?config=TeX-AMS_HTML\"></script>" | ||
+ // | ||
"\n" + // | ||
"<div class=\"mathcell\" style=\"width: 100%; height: 100%; padding: .25in .5in .5in .5in;\">\n" + // | ||
"<script>\n" + // | ||
"\n" + // | ||
"var parent = document.scripts[ document.scripts.length - 1 ].parentNode;\n" + // | ||
"\n" + // | ||
"var id = generateId();\n" + // | ||
"parent.id = id;\n" + // | ||
"\n" + // | ||
"`1`\n" + // | ||
"\n" + // | ||
"parent.update( id );\n" + // | ||
"\n" + // | ||
"</script>\n" + // | ||
"</div>\n" + // | ||
"\n" + // | ||
"</body>\n" + // | ||
"</html>";// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,17 +8,13 @@ | |
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.OutputStreamWriter; | ||
import java.io.PrintStream; | ||
import java.io.PrintWriter; | ||
import java.io.StringWriter; | ||
import java.nio.charset.StandardCharsets; | ||
import java.text.DecimalFormat; | ||
import java.text.DecimalFormatSymbols; | ||
import java.util.Locale; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.matheclipse.core.basic.Config; | ||
import org.matheclipse.core.builtin.GraphFunctions; | ||
import org.matheclipse.core.eval.exception.AbortException; | ||
import org.matheclipse.core.eval.exception.ReturnException; | ||
import org.matheclipse.core.eval.exception.Validate; | ||
|
@@ -27,7 +23,6 @@ | |
import org.matheclipse.core.form.output.OutputFormFactory; | ||
import org.matheclipse.core.graphics.Show2SVG; | ||
import org.matheclipse.core.interfaces.IAST; | ||
import org.matheclipse.core.interfaces.IDataExpr; | ||
import org.matheclipse.core.interfaces.IExpr; | ||
import org.matheclipse.parser.client.Scanner; | ||
import org.matheclipse.parser.client.SyntaxError; | ||
|
@@ -39,80 +34,6 @@ | |
* See {@link MMAConsole} | ||
*/ | ||
public class Console { | ||
protected final static String VISJS_PAGE = // | ||
"<html>\n" + // | ||
"<head>\n" + // | ||
"<meta charset=\"utf-8\">\n" + // | ||
"<head>\n" + // | ||
" <title>VIS-Network</title>\n" + // | ||
"\n" + // | ||
" <script type=\"text/javascript\" src=\"https://cdn.jsdelivr.net/npm/[email protected]/dist/vis-network.min.js\"></script>\n" | ||
+ // | ||
" <style type=\"text/css\">\n" + // | ||
" #mynetwork {\n" + // | ||
" width: 600px;\n" + // | ||
" height: 400px;\n" + // | ||
" border: 1px solid lightgray;\n" + // | ||
" }\n" + // | ||
" </style>\n" + // | ||
"</head>\n" + // | ||
"<body>\n" + // | ||
"\n" + // | ||
"<h1>VIS-Network</h1>\n" + // | ||
"\n" + // | ||
"<div id=\"vis\"></div>\n" + // | ||
"\n" + // | ||
"<script type=\"text/javascript\">\n" + // | ||
"`1`\n" + // | ||
" // create a network\n" + // | ||
" var container = document.getElementById('vis');\n" + // | ||
" var data = {\n" + // | ||
" nodes: nodes,\n" + // | ||
" edges: edges\n" + // | ||
" };\n" + // | ||
" var options = {};\n" + // | ||
" var network = new vis.Network(container, data, options);\n" + // | ||
"</script>\n" + // | ||
"\n" + // | ||
"\n" + // | ||
"</body>\n" + // | ||
"</html>";// | ||
protected final static String MATHCELL_PAGE = // | ||
"<html>\n" + // | ||
"<head>\n" + // | ||
"<meta charset=\"utf-8\">\n" + // | ||
"<title>MathCell</title>\n" + // | ||
"<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n" + // | ||
"<style></style>\n" + // | ||
"</head>\n" + // | ||
"\n" + // | ||
"<body>\n" + // | ||
"<script src=\"https://cdn.jsdelivr.net/gh/paulmasson/[email protected]/build/math.js\"></script>" + // | ||
"\n" + // | ||
"\n" + // | ||
"<script src=\"https://cdn.jsdelivr.net/gh/paulmasson/[email protected]/build/mathcell.js\"></script>\n" | ||
+ // | ||
"<script src=\"https://cdn.jsdelivr.net/gh/mathjax/[email protected]/MathJax.js?config=TeX-AMS_HTML\"></script>" | ||
+ // | ||
"\n" + // | ||
"<div class=\"mathcell\" style=\"width: 100%; height: 100%; padding: .25in .5in .5in .5in;\">\n" + // | ||
"<script>\n" + // | ||
"\n" + // | ||
"var parent = document.scripts[ document.scripts.length - 1 ].parentNode;\n" + // | ||
"\n" + // | ||
"var id = generateId();\n" + // | ||
"parent.id = id;\n" + // | ||
"\n" + // | ||
"`1`\n" + // | ||
"\n" + // | ||
"parent.update( id );\n" + // | ||
"\n" + // | ||
"</script>\n" + // | ||
"</div>\n" + // | ||
"\n" + // | ||
"</body>\n" + // | ||
"</html>";// | ||
|
||
/** | ||
* 60 seconds timeout limit as the default value for Symja expression evaluation. | ||
*/ | ||
|
@@ -590,35 +511,9 @@ private String printResult(IExpr result) throws IOException { | |
if (result.isAST(F.Graphics)) {// || result.isAST(F.Graphics3D)) { | ||
outExpr = F.Show(outExpr); | ||
} | ||
if (outExpr.isSameHeadSizeGE(F.Show, 2)) { | ||
try { | ||
IAST show = (IAST) outExpr; | ||
if (show.size() > 1 && show.arg1().isSameHeadSizeGE(F.Graphics, 2)) { | ||
return openSVGOnDesktop(show); | ||
} | ||
} catch (Exception ex) { | ||
if (Config.SHOW_STACKTRACE) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
} else if (result.head().equals(F.Graph) && result instanceof IDataExpr) { | ||
String javaScriptStr = GraphFunctions.graphToJSForm((IDataExpr) result); | ||
if (javaScriptStr != null) { | ||
String html = VISJS_PAGE; | ||
html = html.replaceAll("`1`", javaScriptStr); | ||
return Console.openHTMLOnDesktop(html); | ||
} | ||
} else if (result.isAST(F.JSFormData, 3) && result.second().toString().equals("mathcell")) { | ||
try { | ||
String manipulateStr = ((IAST) result).arg1().toString(); | ||
String html = MATHCELL_PAGE; | ||
html = html.replaceAll("`1`", manipulateStr); | ||
return Console.openHTMLOnDesktop(html); | ||
} catch (Exception ex) { | ||
if (Config.SHOW_STACKTRACE) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
String html = F.show(outExpr); | ||
if (html != null) { | ||
return html; | ||
} | ||
} | ||
StringBuilder strBuffer = new StringBuilder(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters