Skip to content

Commit 462a81c

Browse files
committed
Implement 1D line plot in plotSolution function
1 parent 8ec0b9f commit 462a81c

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/visualization/plotSolutionScript.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,37 @@ export function plotSolution(
2929
) {
3030
const { nodesXCoordinates, nodesYCoordinates } = nodesCoordinates;
3131

32-
if (meshDimension === "2D" && plotType === "contour") {
32+
if (meshDimension === "1D" && plotType === "line") {
33+
// Flatten solutionVector
34+
let yData = solutionVector.map(arr => arr[0]);
35+
let xData = Array.from(nodesXCoordinates);
36+
37+
let lineData = {
38+
x: xData,
39+
y: yData,
40+
mode: "lines",
41+
type: "scatter",
42+
line: { color: "rgb(219, 64, 82)", width: 2 },
43+
name: "Solution"
44+
};
45+
46+
let maxWindowWidth = Math.min(window.innerWidth, 700);
47+
let maxPlotWidth = Math.max(...xData);
48+
let zoomFactor = maxWindowWidth / maxPlotWidth;
49+
let plotWidth = Math.max(zoomFactor * maxPlotWidth, 400);
50+
let plotHeight = 350;
51+
52+
let layout = {
53+
title: `line plot - ${solverConfig}`,
54+
width: plotWidth,
55+
height: plotHeight,
56+
xaxis: { title: "x" },
57+
yaxis: { title: "Solution" },
58+
margin: { l: 70, r: 40, t: 50, b: 50 }
59+
};
60+
61+
Plotly.newPlot(plotDivId, [lineData], layout, { responsive: true });
62+
} else if (meshDimension === "2D" && plotType === "contour") {
3363
// Calculate the number of nodes along the x-axis and y-axis
3464
const numNodesX = new Set(nodesXCoordinates).size;
3565
const numNodesY = new Set(nodesYCoordinates).size;

0 commit comments

Comments
 (0)