use of org.matheclipse.core.expression.data.GraphExpr in project symja_android_library by axkr.
the class F method showGraphic.
public static String showGraphic(IExpr expr) {
try {
if (expr.isSameHeadSizeGE(Graphics, 2)) {
return openSVGOnDesktop((IAST) expr);
} else if (expr.isSameHeadSizeGE(Graphics3D, 2)) {
StringBuilder buf = new StringBuilder();
if (GraphicsFunctions.renderGraphics3D(buf, (IAST) expr, EvalEngine.get())) {
try {
String manipulateStr = buf.toString();
String html = JSBuilder.buildGraphics3D(JSBuilder.GRAPHICS3D_TEMPLATE, manipulateStr);
return openHTMLOnDesktop(html);
} catch (Exception ex) {
LOGGER.debug("JSBuilder.buildGraphics3D() failed", ex);
}
}
} else if (expr instanceof GraphExpr) {
String javaScriptStr = GraphFunctions.graphToJSForm((GraphExpr) expr);
if (javaScriptStr != null) {
String html = Config.VISJS_PAGE;
html = StringUtils.replace(html, "`1`", javaScriptStr);
html = StringUtils.replace(html, "`2`", "var options = {};");
return openHTMLOnDesktop(html);
}
} else if (expr.isAST(JSFormData, 3)) {
return printJSFormData(expr);
} else if (expr.isString()) {
IStringX str = (IStringX) expr;
if (str.getMimeType() == IStringX.TEXT_HTML) {
String htmlSnippet = str.toString();
String htmlPage = Config.HTML_PAGE;
htmlPage = StringUtils.replace(htmlPage, "`1`", htmlSnippet);
EvalEngine.get().getOutPrintStream().println(htmlPage);
return openHTMLOnDesktop(htmlPage);
}
} else if (expr.isList(x -> x.isAST(JSFormData, 3))) {
StringBuilder buf = new StringBuilder();
((IAST) expr).forEach(x -> buf.append(printJSFormData(x)));
return buf.toString();
}
} catch (Exception ex) {
LOGGER.debug("F.showGraphic() failed", ex);
}
return null;
}
use of org.matheclipse.core.expression.data.GraphExpr in project symja_android_library by axkr.
the class GraphFunctions method createGraph.
/**
* Create a <code>Graph<IExpr, ExprWeightedEdge></code> or <code>Graph<IExpr, ExprEdge></code>
*
* @param arg1
* @return
*/
private static GraphExpr<?> createGraph(final IExpr arg1) {
if (arg1.head().equals(S.Graph) && arg1 instanceof GraphExpr) {
return (GraphExpr<?>) arg1;
}
Graph<IExpr, ExprEdge> g;
GraphType t = arg1.isListOfEdges();
if (t != null) {
if (t.isDirected()) {
g = new DefaultDirectedGraph<IExpr, ExprEdge>(ExprEdge.class);
} else {
g = new DefaultUndirectedGraph<IExpr, ExprEdge>(ExprEdge.class);
}
IAST list = (IAST) arg1;
for (int i = 1; i < list.size(); i++) {
IAST edge = list.getAST(i);
g.addVertex(edge.arg1());
g.addVertex(edge.arg2());
g.addEdge(edge.arg1(), edge.arg2());
}
return GraphExpr.newInstance(g);
}
return null;
}
Aggregations