Search in sources :

Example 6 with GraphExpr

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;
}
Also used : ExprParserFactory(org.matheclipse.core.parser.ExprParserFactory) ManipulateFunction(org.matheclipse.core.builtin.ManipulateFunction) Apcomplex(org.apfloat.Apcomplex) IAssumptions(org.matheclipse.core.eval.util.IAssumptions) GraphDataFunctions(org.matheclipse.core.builtin.GraphDataFunctions) IOFunctions(org.matheclipse.core.builtin.IOFunctions) StringUtils(org.apache.commons.lang3.StringUtils) IComplex(org.matheclipse.core.interfaces.IComplex) BoxesFunctions(org.matheclipse.core.builtin.BoxesFunctions) ComputationalGeometryFunctions(org.matheclipse.core.builtin.ComputationalGeometryFunctions) EllipticIntegrals(org.matheclipse.core.builtin.EllipticIntegrals) MinMaxFunctions(org.matheclipse.core.builtin.MinMaxFunctions) Lambda(org.matheclipse.core.eval.util.Lambda) Map(java.util.Map) BigInteger(java.math.BigInteger) ISparseArray(org.matheclipse.core.interfaces.ISparseArray) ListFunctions(org.matheclipse.core.builtin.ListFunctions) IComplexNum(org.matheclipse.core.interfaces.IComplexNum) EvalEngine(org.matheclipse.core.eval.EvalEngine) BiIntFunction(org.matheclipse.core.eval.util.BiIntFunction) IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) IntervalFunctions(org.matheclipse.core.builtin.IntervalFunctions) GeodesyFunctions(org.matheclipse.core.builtin.GeodesyFunctions) ISymbol(org.matheclipse.core.interfaces.ISymbol) FinancialFunctions(org.matheclipse.core.builtin.FinancialFunctions) ComputerThreads(edu.jas.kern.ComputerThreads) VisitorLevelSpecification(org.matheclipse.core.visit.VisitorLevelSpecification) CountDownLatch(java.util.concurrent.CountDownLatch) IASTMutable(org.matheclipse.core.interfaces.IASTMutable) Logger(org.apache.logging.log4j.Logger) NumericArrayFunctions(org.matheclipse.core.builtin.NumericArrayFunctions) RootsFunctions(org.matheclipse.core.builtin.RootsFunctions) EvalAttributes(org.matheclipse.core.eval.EvalAttributes) IntegerFunctions(org.matheclipse.core.builtin.IntegerFunctions) IAssociation(org.matheclipse.core.interfaces.IAssociation) IEvaluator(org.matheclipse.core.interfaces.IEvaluator) SourceCodeFunctions(org.matheclipse.core.builtin.SourceCodeFunctions) ApfloatContext(org.apfloat.ApfloatContext) OutputFunctions(org.matheclipse.core.builtin.OutputFunctions) RandomFunctions(org.matheclipse.core.builtin.RandomFunctions) GraphicsFunctions(org.matheclipse.core.builtin.GraphicsFunctions) TrieMatch(org.matheclipse.parser.trie.TrieMatch) Algebra(org.matheclipse.core.builtin.Algebra) SyntaxError(org.matheclipse.parser.client.SyntaxError) IntFunction(java.util.function.IntFunction) AssociationFunctions(org.matheclipse.core.builtin.AssociationFunctions) ConstantDefinitions(org.matheclipse.core.builtin.ConstantDefinitions) IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) BufferedWriter(java.io.BufferedWriter) Combinatoric(org.matheclipse.core.builtin.Combinatoric) FunctionDefinitions(org.matheclipse.core.builtin.FunctionDefinitions) Config(org.matheclipse.core.basic.Config) IOException(java.io.IOException) AbstractCoreFunctionEvaluator(org.matheclipse.core.eval.interfaces.AbstractCoreFunctionEvaluator) QuantityParser(org.matheclipse.core.tensor.QuantityParser) File(java.io.File) Programming(org.matheclipse.core.builtin.Programming) HypergeometricFunctions(org.matheclipse.core.builtin.HypergeometricFunctions) ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) SimplifyFunctions(org.matheclipse.core.builtin.SimplifyFunctions) IExpr(org.matheclipse.core.interfaces.IExpr) AssumptionFunctions(org.matheclipse.core.builtin.AssumptionFunctions) ICoreFunctionEvaluator(org.matheclipse.core.eval.interfaces.ICoreFunctionEvaluator) SeriesFunctions(org.matheclipse.core.builtin.SeriesFunctions) IStringX(org.matheclipse.core.interfaces.IStringX) BiFunction(java.util.function.BiFunction) Functors(org.matheclipse.core.generic.Functors) TensorFunctions(org.matheclipse.core.builtin.TensorFunctions) IInteger(org.matheclipse.core.interfaces.IInteger) QuantityFunctions(org.matheclipse.core.builtin.QuantityFunctions) PreemptStatus(edu.jas.kern.PreemptStatus) Apfloat(org.apfloat.Apfloat) INumber(org.matheclipse.core.interfaces.INumber) Arithmetic(org.matheclipse.core.builtin.Arithmetic) BooleanFunctions(org.matheclipse.core.builtin.BooleanFunctions) ClusteringFunctions(org.matheclipse.core.builtin.ClusteringFunctions) Locale(java.util.Locale) StatisticsFunctions(org.matheclipse.core.builtin.StatisticsFunctions) FileFunctions(org.matheclipse.core.builtin.FileFunctions) IPatternSequence(org.matheclipse.core.interfaces.IPatternSequence) IdentityHashMap(java.util.IdentityHashMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) JSBuilder(org.matheclipse.core.form.output.JSBuilder) PredicateQ(org.matheclipse.core.builtin.PredicateQ) StringFunctions(org.matheclipse.core.builtin.StringFunctions) ExprParser(org.matheclipse.core.parser.ExprParser) ExpTrigsFunctions(org.matheclipse.core.builtin.ExpTrigsFunctions) PolynomialFunctions(org.matheclipse.core.builtin.PolynomialFunctions) WXFFunctions(org.matheclipse.core.builtin.WXFFunctions) SidesFunctions(org.matheclipse.core.builtin.SidesFunctions) SparseArrayFunctions(org.matheclipse.core.builtin.SparseArrayFunctions) CacheBuilder(com.google.common.cache.CacheBuilder) AST2Expr(org.matheclipse.core.convert.AST2Expr) ParserConfig(org.matheclipse.parser.client.ParserConfig) AttributeFunctions(org.matheclipse.core.builtin.AttributeFunctions) GraphExpr(org.matheclipse.core.expression.data.GraphExpr) LinearAlgebra(org.matheclipse.core.builtin.LinearAlgebra) CurveFitterFunctions(org.matheclipse.core.builtin.CurveFitterFunctions) ASTElementLimitExceeded(org.matheclipse.core.eval.exception.ASTElementLimitExceeded) VectorAnalysisFunctions(org.matheclipse.core.builtin.VectorAnalysisFunctions) IFraction(org.matheclipse.core.interfaces.IFraction) Function(java.util.function.Function) ImageFunctions(org.matheclipse.core.builtin.ImageFunctions) BiPredicate(java.util.function.BiPredicate) WindowFunctions(org.matheclipse.core.builtin.WindowFunctions) SpecialFunctions(org.matheclipse.core.builtin.SpecialFunctions) Documentation(org.matheclipse.core.form.Documentation) IPattern(org.matheclipse.core.interfaces.IPattern) CompilerFunctions(org.matheclipse.core.builtin.CompilerFunctions) EntityFunctions(org.matheclipse.core.builtin.EntityFunctions) SparseArrayExpr(org.matheclipse.core.expression.data.SparseArrayExpr) Desktop(java.awt.Desktop) StructureFunctions(org.matheclipse.core.builtin.StructureFunctions) IPatternMatcher(org.matheclipse.core.patternmatching.IPatternMatcher) IAST(org.matheclipse.core.interfaces.IAST) IPatternMap(org.matheclipse.core.patternmatching.IPatternMap) Complex(org.hipparchus.complex.Complex) FileWriter(java.io.FileWriter) INum(org.matheclipse.core.interfaces.INum) GraphFunctions(org.matheclipse.core.builtin.GraphFunctions) NumberTheory(org.matheclipse.core.builtin.NumberTheory) ContainsFunctions(org.matheclipse.core.builtin.ContainsFunctions) Field(org.hipparchus.Field) Object2Expr(org.matheclipse.core.convert.Object2Expr) PatternMatching(org.matheclipse.core.builtin.PatternMatching) IRational(org.matheclipse.core.interfaces.IRational) BesselFunctions(org.matheclipse.core.builtin.BesselFunctions) JavaFunctions(org.matheclipse.core.builtin.JavaFunctions) BigFraction(org.hipparchus.fraction.BigFraction) UnitTestingFunctions(org.matheclipse.core.builtin.UnitTestingFunctions) Cache(com.google.common.cache.Cache) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) GraphExpr(org.matheclipse.core.expression.data.GraphExpr) IAST(org.matheclipse.core.interfaces.IAST) IStringX(org.matheclipse.core.interfaces.IStringX) IOException(java.io.IOException)

Example 7 with GraphExpr

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;
}
Also used : ExprEdge(org.matheclipse.core.expression.data.ExprEdge) GraphExpr(org.matheclipse.core.expression.data.GraphExpr) GraphType(org.jgrapht.GraphType) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Aggregations

GraphExpr (org.matheclipse.core.expression.data.GraphExpr)7 IExpr (org.matheclipse.core.interfaces.IExpr)7 IAST (org.matheclipse.core.interfaces.IAST)6 IOException (java.io.IOException)4 IStringX (org.matheclipse.core.interfaces.IStringX)4 StringWriter (java.io.StringWriter)3 SyntaxError (org.matheclipse.parser.client.SyntaxError)3 File (java.io.File)2 FileWriter (java.io.FileWriter)2 Collections (java.util.Collections)2 Map (java.util.Map)2 StringUtils (org.apache.commons.lang3.StringUtils)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 DefaultEdge (org.jgrapht.graph.DefaultEdge)2 ExportException (org.jgrapht.nio.ExportException)2 IASTDataset (org.matheclipse.core.interfaces.IASTDataset)2 Extension (org.matheclipse.core.io.Extension)2 ExprParser (org.matheclipse.core.parser.ExprParser)2 MathException (org.matheclipse.parser.client.math.MathException)2