Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Demos/UI Builder Examples/Plot function.js')
-rw-r--r--Demos/UI Builder Examples/Plot function.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/Demos/UI Builder Examples/Plot function.js b/Demos/UI Builder Examples/Plot function.js
new file mode 100644
index 0000000..9eb31e1
--- /dev/null
+++ b/Demos/UI Builder Examples/Plot function.js
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Christian Pontesegger and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * Contributors:
+ * Christian Pontesegger - initial API and implementation
+ *******************************************************************************/
+loadModule("/System/UI Builder");
+loadModule("/System/UI");
+loadModule("/Charting");
+
+createView("Function Plot")
+
+createLabel("Function:", "1/1 > x");
+var txtFunction = createText("2-6/1 o!");
+createButton("Plot", plotFunction, "7/1 o")
+
+createLabel("Range:", "1/2 > x")
+var txtRangeFrom = createText("2/2")
+createLabel("to", "3/2 < x")
+var txtRangeTo = createText("4/2")
+createLabel("Step size", "5/2 < x")
+var txtRangeStep = createText("6/2")
+createButton("Clear", "clear()", "7/2 o")
+
+executeUI("txtRangeFrom.setText('-10')")
+executeUI("txtRangeTo.setText('10')")
+executeUI("txtRangeStep.setText('1')")
+
+chart = createChart(getComposite());
+chartComposite = addControl(chart, "1-7/3 o! o!")
+
+function plotFunction() {
+ var formula = executeUI("txtFunction.getText()");
+ var rangeFrom = parseFloat(executeUI("txtRangeFrom.getText()"))
+ var rangeTo = parseFloat(executeUI("txtRangeTo.getText()"))
+ var rangeStep = parseFloat(executeUI("txtRangeStep.getText()"))
+
+ series(formula);
+ for (var x = rangeFrom; x <= rangeTo; x += rangeStep) {
+ print("from " + x)
+ y = eval("x=" + x + ";\n" + formula);
+ plotPoint(x, y);
+ }
+} \ No newline at end of file

Back to the top