diff --git a/.gitignore b/.gitignore
index 4fcba7cc..ab55f877 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,4 +32,6 @@ my/
*~
# Generated app.yaml
-app.yaml
\ No newline at end of file
+app.yaml
+
+.vscode
\ No newline at end of file
diff --git a/app/logic/resultsets.py b/app/logic/resultsets.py
index 12ed4e5d..b314ac01 100644
--- a/app/logic/resultsets.py
+++ b/app/logic/resultsets.py
@@ -280,8 +280,8 @@ def extract_plot(arguments, evaluated):
result['variable'] = result['variables'][0]
result['input_evaluated'] = [arguments.args[0]]
- if len(result['variables']) != 1:
- raise ValueError("Cannot plot function of multiple variables")
+ # if len(result['variables']) != 1:
+ # raise ValueError("Cannot plot function of multiple variables")
else:
variables = set()
try:
@@ -517,9 +517,10 @@ def eval_plot(evaluator, components, parameters=None):
parameters = {}
xmin, xmax = parameters.get('xmin', -10), parameters.get('xmax', 10)
+ ymin, ymax = [-10, 10]
pmin, pmax = parameters.get('tmin', 0), parameters.get('tmax', 2 * sympy.pi)
tmin, tmax = parameters.get('tmin', 0), parameters.get('tmax', 10)
- from sympy.plotting.plot import LineOver1DRangeSeries, Parametric2DLineSeries
+ from sympy.plotting.plot import LineOver1DRangeSeries, Parametric2DLineSeries, SurfaceOver2DRangeSeries
functions = evaluator.get("input_evaluated")
if isinstance(functions, sympy.Basic):
functions = [(functions, 'xy')]
@@ -539,7 +540,7 @@ def eval_plot(evaluator, components, parameters=None):
else:
variables = func.free_symbols
- if len(variables) > 1:
+ if len(variables) > 3:
raise ValueError("Cannot plot multivariate function")
elif len(variables) == 0:
variable = sympy.Symbol('x')
@@ -555,17 +556,29 @@ def eval_plot(evaluator, components, parameters=None):
graph_range = (variable, tmin, tmax)
if graph_type in ('xy', 'polar'):
- series = LineOver1DRangeSeries(func, graph_range, nb_of_points=150)
+ if len(variables) == 1 :
+ series = LineOver1DRangeSeries(func, graph_range, nb_of_points=150)
+ series = series.get_segments()
+ if len(variables) == 2:
+ series = SurfaceOver2DRangeSeries(func, graph_range, ('x', -10, 10), nb_of_points=150)
+ series = series.get_meshes()
+ series = list(series)
+ # print("from resultset line 584", series[0][0])
+ if variable == 'y':
+ print("true")
+ series = SurfaceOver2DRangeSeries(func, graph_range, ('x', -10, 10), nb_of_points=150)
+ series = series.get_meshes()
+ series = list(series)
elif graph_type == 'parametric':
series = Parametric2DLineSeries(x_func, y_func, graph_range, nb_of_points=150)
+ series = series.get_segments()
# returns a list of [[x,y], [next_x, next_y]] pairs
- series = series.get_segments()
except TypeError:
raise ValueError("Cannot plot function")
xvalues = []
yvalues = []
-
+ zvalues = []
def limit_y(y):
CEILING = 1e8
if y > CEILING:
@@ -575,26 +588,54 @@ def limit_y(y):
return y
x_transform, y_transform = GRAPH_TYPES[graph_type]
- series.append([series[-1][1], None])
- for point in series:
- if point[0][1] is None:
- continue
- x = point[0][0]
- y = limit_y(point[0][1])
- xvalues.append(x_transform(x, y))
- yvalues.append(y_transform(x, y))
-
- graphs.append({
- 'type': graph_type,
- 'function': sympy.jscode(sympy.sympify(func)),
- 'points': {
- 'x': xvalues,
- 'y': yvalues
- },
- 'data': None
- })
+ if len(variables) == 1 :
+ series.append([series[-1][1], None])
+ if(len(variables) == 2 ):
+ series = list(series)
+ if(len(variables) == 1 ):
+ for point in series:
+ if point[0][1] is None:
+ continue
+ x = point[0][0]
+ y = limit_y(point[0][1])
+ xvalues.append(x_transform(x, y))
+ yvalues.append(y_transform(x, y))
+
+ graphs.append({
+ 'type': graph_type,
+ 'function': sympy.jscode(sympy.sympify(func)),
+ 'points': {
+ 'x': xvalues,
+ 'y': yvalues
+ },
+ 'data': None
+ })
+ if(len(variables) == 2) :
+ for points in series[0][0]:
+ xvalues.append(points)
+ # print("from resultsets line 641 xvalues", xvalues)
+ for points in series[1]:
+ yvalues.append(points[0])
+ # print("from resultsets line 644 yvalues", yvalues)
+ for points in series[2].data:
+ new = []
+ for p in points:
+ new.append(p)
+ # print(new)
+ zvalues.append(new)
+ # print("from resultsets line 654 yvalues", zvalues)
+ graphs.append({
+ 'type': graph_type,
+ 'function': sympy.jscode(sympy.sympify(func)),
+ 'points': {
+ 'x': xvalues,
+ 'y': yvalues,
+ 'z': zvalues
+ },
+ 'data': None
+ })
return {
- 'variable': repr(variable),
+ 'variable': repr(variables),
'graphs': json.dumps(graphs)
}
diff --git a/static/js/plot.js b/static/js/plot.js
index 36ab4739..85ef313b 100644
--- a/static/js/plot.js
+++ b/static/js/plot.js
@@ -569,7 +569,7 @@ function setupPlots() {
}
var card = $(this).parents('.result_card').data('card');
var graphs = JSON.parse($(this).find('.graphs').text());
-
+ if(variable.length == 8) {
var plot = new Plot2D(card, $(this)[0], D3Backend, graphs);
plot.show();
@@ -721,5 +721,19 @@ function setupPlots() {
attributes: true
});
}
+ }
+
+ if(variable.length >= 8) {
+ card.element.addClass('plot-card');
+ svg = document.createElement("svg")
+ document.getElementsByClassName('plot')[0].appendChild(svg)
+ document.getElementsByTagName('svg')[0].setAttribute('id', "plotly")
+ const returned = graphs[0].points
+ const type = {type : 'contour'}
+ data = Object.assign(returned , type)
+ data =[data]
+ console.log(data);
+ Plotly.newPlot("plotly", data);
+ }
});
}
diff --git a/templates/base.html b/templates/base.html
index c08cb729..0c6375f8 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -17,6 +17,7 @@
+