Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion calc-backend/graph-gen/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Code for Generating Graphs
Each python file outputs an html div for displaying the respective graph on the frontend.<br/>
Each python file outputs a json object for displaying the graph on the frontend.<br/>
The following script must be added to index.html to render the graph:

```html
Expand Down
13 changes: 7 additions & 6 deletions calc-backend/graph-gen/graph-deriv.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def derivative(func, x, h=1e-5):
return (func(x + h) - func(x - h)) / (2 * h)

# Create an array of x values and evaluate f(x) for these values.
x_vals = np.linspace(x_range[0], x_range[1], num=51)
x_vals = np.linspace(x_range[0], x_range[1], num=101)
f_vals = f(x_vals)

# Initialize the Plotly figure
Expand All @@ -51,16 +51,16 @@ def derivative(func, x, h=1e-5):

# Set the final y-axis range with padding
y_min = np.min(f_vals) - pad
# No padding on top to avoid cutting off curve
y_max = np.max(f_vals)
y_max = np.max(f_vals) + pad

# Calculate x-axis padding
x_range_val = x_range[1] - x_range[0]
x_pad = max(x_range_val * 0.05, 0.1)

# Set the final x-axis range with padding
x_min = x_range[0] - x_pad
x_max = x_range[1] + x_pad
# Set the final x-axis range with padding (only pad if lowest x value >= 0)
x_min = x_range[0] - x_pad if x_range[0] >= 0 else x_range[0]
# No padding on right
x_max = x_range[1]

# Vertical line at x=0 (y-axis)
if x_min < 0 < x_max:
Expand Down Expand Up @@ -164,6 +164,7 @@ def derivative(func, x, h=1e-5):
yaxis=dict(range=[y_min, y_max], fixedrange=True),
sliders=sliders,
uirevision='static',
showlegend=False,
margin=dict(t=50, r=0,l=60),
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import plotly.graph_objects as go
import numpy as np

# === USER DEFINES ONLY THESE TWO ===
func = lambda x: np.log(x) # ← your function
limit_x = 2 # ← point to approach
# === User Input ===
func = lambda x: np.tan(x) # ← your function
limit_x = 0 # ← point to approach

# === Range of values ===
x_range = [-2, 2]
y_range = [-75, 75]

# === Slider & sampling settings (fixed) ===
num_steps = 50
Expand Down Expand Up @@ -63,7 +67,6 @@ def segment(i):
x=[limit_x], y=[y_limit],
mode="markers+text",
marker=dict(color="red", size=10),
text=[f"Limit (x={limit_x})"],
textposition="top center",
showlegend=False
))
Expand All @@ -83,16 +86,15 @@ def segment(i):
fig.update_layout(
sliders=[dict(active=0, steps=steps,
currentvalue={"visible": False},
pad={"t": 50}, ticklen=0)],
xaxis=dict(autorange=True, fixedrange=True, title="x-axis"),
yaxis=dict(autorange=True, fixedrange=True, title="y-axis"),
showlegend=True
pad={"t": 50}, ticklen=0, tickcolor="rgba(0,0,0,0)")],
xaxis=dict(range=x_range, fixedrange=True, title="x-axis"),
yaxis=dict(range=y_range, fixedrange=True, title="y-axis"),
showlegend=False
)

fig.show()
# Displays figure in browser window (for local testing)
# fig.show()

fig_json = fig.to_json(pretty=True)

# Save to file
with open("limit-graph.txt", "a") as f:
f.write(fig_json)
print(fig_json)
2,914 changes: 2,592 additions & 322 deletions calc-frontend/public/cosineDeriv.json

Large diffs are not rendered by default.

24,363 changes: 24,363 additions & 0 deletions calc-frontend/public/cosineInt.json

Large diffs are not rendered by default.

Loading
Loading