Skip to content

Commit

Permalink
WIP #1087 add ECharts implementataion
Browse files Browse the repository at this point in the history
  • Loading branch information
axkr committed Oct 20, 2024
1 parent f60fb77 commit 28e5b12
Show file tree
Hide file tree
Showing 33 changed files with 2,057 additions and 234 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,10 @@ public class ToggleFeature {
*/
public static boolean SOLVE_DIOPHANTINE = true;

/**
* Use Apache ECharts for rendering some 2D plot functions.
*/
public static boolean JS_ECHARTS = false;

public static boolean SHOW_STEPS = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private static void init() {
S.ListPlot3D.setEvaluator(new org.matheclipse.core.reflection.system.ListPlot3D());
S.ListPointPlot3D.setEvaluator(new org.matheclipse.core.reflection.system.ListPointPlot3D());
S.ListPolarPlot.setEvaluator(new org.matheclipse.core.reflection.system.ListPolarPlot());
S.ListStepPlot.setEvaluator(new org.matheclipse.core.reflection.system.ListStepPlot());
S.LogPlot.setEvaluator(new org.matheclipse.core.reflection.system.LogPlot());
S.LogLinearPlot.setEvaluator(new org.matheclipse.core.reflection.system.LogLinearPlot());
S.LogLogPlot.setEvaluator(new org.matheclipse.core.reflection.system.LogLogPlot());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ private static IExpr boundingBox(IAST ast, double[] boundingbox, String function
jsControl.append("board.suspendUpdate();\n");
jsControl.append(js);
jsControl.append("board.unsuspendUpdate();\n");
return F.JSFormData(jsControl.toString(), "jsxgraph");
return F.JSFormData(jsControl.toString(), JSBuilder.JSXGRAPH_STR);
}

// private static void range(StringBuilder graphicControl, IAST plotRange, int steps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;

import org.matheclipse.core.basic.OperationSystem;
import org.matheclipse.core.convert.Convert;
import org.matheclipse.core.eval.Errors;
import org.matheclipse.core.eval.EvalAttributes;
Expand All @@ -21,12 +19,14 @@
import org.matheclipse.core.eval.interfaces.AbstractCoreFunctionEvaluator;
import org.matheclipse.core.eval.interfaces.AbstractCoreFunctionOptionEvaluator;
import org.matheclipse.core.eval.interfaces.AbstractFunctionEvaluator;
import org.matheclipse.core.eval.interfaces.AbstractFunctionOptionEvaluator;
import org.matheclipse.core.eval.util.Lambda;
import org.matheclipse.core.eval.util.OpenFixedSizeMap;
import org.matheclipse.core.eval.util.OptionArgs;
import org.matheclipse.core.expression.F;
import org.matheclipse.core.expression.ImplementationStatus;
import org.matheclipse.core.expression.S;
import org.matheclipse.core.generic.Comparators;
import org.matheclipse.core.generic.Predicates;
import org.matheclipse.core.generic.Predicates.IsBinaryFalse;
import org.matheclipse.core.interfaces.IAST;
Expand Down Expand Up @@ -66,6 +66,7 @@ private static class Initializer {

private static void init() {
S.Apply.setEvaluator(new Apply());
S.MapApply.setEvaluator(new MapApply());
S.ByteCount.setEvaluator(new ByteCount());
S.Depth.setEvaluator(new Depth());
S.Exit.setEvaluator(new QuitExit());
Expand All @@ -87,6 +88,7 @@ private static void init() {
S.ParallelMap.setEvaluator(new ParallelMap());
S.PatternOrder.setEvaluator(new PatternOrder());
S.Quit.setEvaluator(new QuitExit());
S.ReverseSort.setEvaluator(new ReverseSort());
S.Scan.setEvaluator(new Scan());
S.Sort.setEvaluator(new Sort());
S.SortBy.setEvaluator(new SortBy());
Expand Down Expand Up @@ -186,30 +188,35 @@ private static void init() {
* Apply(f, {a, b, c}, x + y)
* </pre>
*/
private static final class Apply extends AbstractCoreFunctionEvaluator {

private static class Apply extends AbstractFunctionOptionEvaluator {
@Override
public IExpr evaluate(IAST ast, EvalEngine engine) {
if (ast.argSize() < 2 || ast.argSize() > 4) {
return Errors.printArgMessage(ast, ARGS_2_4, engine);
}
IASTMutable evaledAST = ast.copy();
evaledAST.setArgs(evaledAST.size(), (int i) -> engine.evaluate(evaledAST.get(i)));
public IExpr evaluate(final IAST ast, final int argSize, final IExpr[] option,
final EvalEngine engine, IAST originalAST) {
return apply(ast, argSize, option, engine);
}

int lastIndex = evaledAST.argSize();
boolean heads = false;
final OptionArgs options = new OptionArgs(evaledAST.topHead(), evaledAST, lastIndex, engine);
IExpr option = options.getOption(S.Heads);
if (option.isPresent()) {
lastIndex--;
if (option.isTrue()) {
heads = true;
}
} else {
if (ast.argSize() == 4) {
return Errors.printArgMessage(ast, ARGS_2_3, engine);
}
public static IExpr apply(IAST ast, int argSize, IExpr[] option, EvalEngine engine) {
if (argSize < 2 || argSize > 4) {
return Errors.printArgMessage(ast, ARGS_2_4, engine);
}
// IASTMutable evaledAST = ast.copy();
// evaledAST.setArgs(evaledAST.size(), (int i) -> engine.evaluate(evaledAST.get(i)));
IAST evaledAST = ast;
int lastIndex = argSize;
boolean heads = option[0].isTrue();
// final OptionArgs options = new OptionArgs(evaledAST.topHead(), evaledAST, lastIndex,
// engine);
// IExpr option = options.getOption(S.Heads);
// if (option.isPresent()) {
// lastIndex--;
// if (option.isTrue()) {
// heads = true;
// }
// } else {
// if (ast.argSize() == 4) {
// return Errors.printArgMessage(ast, ARGS_2_3, engine);
// }
// }

IExpr arg1 = evaledAST.arg1();
IExpr arg2 = evaledAST.arg2();
Expand Down Expand Up @@ -255,6 +262,34 @@ public static IExpr evalApply(IExpr f, IExpr expr, IAST evaledAST, int lastIndex
return F.NIL;
}

@Override
public void setUp(final ISymbol newSymbol) {
setOptions(newSymbol, S.Heads, S.False);
}

}

private static final class MapApply extends Apply {
@Override
public IExpr evaluate(final IAST ast, final int argSize, final IExpr[] option,
final EvalEngine engine, IAST originalAST) {
if (argSize >= 2) {
IASTMutable applyFunction = ast.appendAtClone(3, F.CListC1);
applyFunction.set(0, S.Apply);
return super.evaluate(applyFunction, argSize + 1, option, engine, originalAST);
}
return F.NIL;
}

@Override
public int[] expectedArgSize(IAST ast) {
return ARGS_1_3_2;
}

@Override
public void setUp(final ISymbol newSymbol) {
setOptions(newSymbol, S.Heads, S.False);
}
}

private static class ByteCount extends AbstractCoreFunctionEvaluator {
Expand Down Expand Up @@ -1763,6 +1798,26 @@ public void setUp(final ISymbol newSymbol) {
}
}

private static class ReverseSort extends Sort {

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
IExpr arg2 = F.NIL;
Comparator<IExpr> comparator = Comparators.CANONICAL_COMPARATOR;
if (ast.isAST2()) {
arg2 = ast.arg2();
comparator = new Predicates.IsBinaryFalse(arg2);
}
comparator = Comparators.reversedComparator(comparator);
return super.sortByComparator(comparator, ast, engine);
}

@Override
public int[] expectedArgSize(IAST ast) {
return ARGS_1_2;
}
}

/**
*
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import edu.jas.kern.PreemptingException;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -25,6 +23,7 @@
import org.matheclipse.core.interfaces.ISymbol;
import org.matheclipse.core.patternmatching.IPatternMatcher;
import org.matheclipse.parser.client.math.MathException;
import edu.jas.kern.PreemptingException;
import io.pebbletemplates.pebble.PebbleEngine;
import io.pebbletemplates.pebble.cache.PebbleCache;
import io.pebbletemplates.pebble.node.BodyNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2145,7 +2145,7 @@ private boolean convertOperator(final org.matheclipse.parser.client.operator.Ope
return true;
}
if (list.size() == 4 && list.arg2().equals(F.CListC1)) {
convertInfixOperator(buf, list, ASTNodeFactory.APPLY_LEVEL_OPERATOR, precedence);
convertInfixOperator(buf, list, ASTNodeFactory.MAPAPPLY_OPERATOR, precedence);
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.hipparchus.linear.RealMatrix;
import org.hipparchus.linear.RealVector;
import org.matheclipse.core.basic.Config;
import org.matheclipse.core.basic.OperationSystem;
import org.matheclipse.core.builtin.Algebra;
import org.matheclipse.core.convert.AST2Expr;
import org.matheclipse.core.eval.Errors;
Expand Down Expand Up @@ -531,7 +530,7 @@ private void convertPlusOperatorReversed(final StringBuilder buf, final IAST plu
IExpr arg1 = timesAST.arg1();

if (arg1.isNumber() && (((INumber) arg1).complexSign() < 0)) {
if (((INumber) arg1).isOne()) {
if (arg1.isOne()) {
showOperator = false;
} else {
if (arg1.isMinusOne()) {
Expand Down Expand Up @@ -864,11 +863,15 @@ public void convert(final StringBuilder buf, final IExpr o) {
convertInternal(buf, expr, Integer.MIN_VALUE, false, true);
}

public void convertExpr(final StringBuilder buf, final IExpr expr) {
convertInternal(buf, expr, Integer.MIN_VALUE, false, true);
}

protected void convertInternal(final StringBuilder buf, final IExpr o) {
convertInternal(buf, o, Integer.MIN_VALUE, false, true);
}

private void convertNumber(final StringBuilder buf, final INumber o, final int precedence,
protected void convertNumber(final StringBuilder buf, final INumber o, final int precedence,
boolean caller) {
if (o instanceof INum) {
convertDouble(buf, (INum) o, precedence, caller);
Expand Down Expand Up @@ -912,7 +915,7 @@ protected void convertInternal(final StringBuilder buf, final IExpr o, final int
}
}
}
convertAST(buf, list, eval);
convertAST(buf, list, precedence, eval);
return;
}
if (o instanceof IReal) {
Expand Down Expand Up @@ -965,7 +968,7 @@ protected boolean convertOperator(final Operator operator, final IAST list,
return true;
}
if (list.size() == 4 && list.arg2().equals(F.CListC1)) {
convertInfixOperator(head, buf, list, ASTNodeFactory.APPLY_LEVEL_OPERATOR, precedence);
convertInfixOperator(head, buf, list, ASTNodeFactory.MAPAPPLY_OPERATOR, precedence);
return true;
}
return false;
Expand Down Expand Up @@ -1253,12 +1256,15 @@ public void convertFunctionArgs(final StringBuilder buf, final IAST list) {
* @param eval TODO
* @throws IOException
*/
public void convertAST(final StringBuilder buf, final IAST function, boolean eval) {
public void convertAST(final StringBuilder buf, final IAST function, final int precedence,
boolean eval) {
if (function.isNumericFunction(true)) {
try {
double value = EvalEngine.get().evalDouble(function);
buf.append("(" + value + ")");
return;
INumber value = function.evalNumber();
if (value != null) {
convertNumber(buf, value, precedence, NO_PLUS_CALL);
return;
}
} catch (RuntimeException rex) {
Errors.rethrowsInterruptException(rex);
//
Expand Down
Loading

0 comments on commit 28e5b12

Please sign in to comment.