Skip to content

Commit 3392b7f

Browse files
committed
Add showMesh parameter to toggle mesh display
1 parent b1c4b6b commit 3392b7f

File tree

2 files changed

+54
-19
lines changed

2 files changed

+54
-19
lines changed

src/utilities/helperFunctionsScript.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ export async function printVersion() {
1616
const releaseResponse = await fetch('https://api.github.com/repos/FEAScript/FEAScript/releases/latest');
1717
const releaseData = await releaseResponse.json();
1818
console.log(`FEAScript version: ${releaseData.tag_name} - ${releaseData.name}`);
19-
//console.log(`Release date: ${new Date(releaseData.published_at).toLocaleString()}`);
2019

2120
// Fetch the latest commit date
22-
const commitResponse = await fetch('https://api.github.com/repos/FEAScript/FEAScript/commits/main');
23-
const commitData = await commitResponse.json();
24-
const latestCommitDate = new Date(commitData.commit.committer.date).toLocaleString();
25-
console.log(`Latest FEAScript update: ${latestCommitDate}`);
21+
//const commitResponse = await fetch('https://api.github.com/repos/FEAScript/FEAScript/commits/main');
22+
//const commitData = await commitResponse.json();
23+
//const latestCommitDate = new Date(commitData.commit.committer.date).toLocaleString();
24+
//console.log(`Latest FEAScript update: ${latestCommitDate}`);
2625
}

src/visualization/plotSolutionScript.js

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
* @param {string} meshDimension - The dimension of the solution
1717
* @param {string} plotType - The type of plot
1818
* @param {string} plotDivId - The id of the div where the plot will be rendered
19+
* @param {boolean} showMesh - Flag to indicate if the mesh should be shown
1920
*/
2021
export function plotSolution(
2122
solutionVector,
2223
nodesCoordinates,
2324
solverConfig,
2425
meshDimension,
2526
plotType,
26-
plotDivId
27+
plotDivId,
28+
showMesh = false // Currently only for rectuangular domains
2729
) {
2830
const { nodesXCoordinates, nodesYCoordinates } = nodesCoordinates;
2931

@@ -66,17 +68,47 @@ export function plotSolution(
6668
}
6769

6870
// Create the data structure for the contour plot
69-
let data = [
70-
{
71-
z: transposedSolution,
72-
type: "contour",
73-
contours: {
74-
coloring: "heatmap",
75-
},
76-
x: reshapedXForPlot,
77-
y: reshapedYCoordinates[0],
71+
let contourData = {
72+
z: transposedSolution,
73+
type: "contour",
74+
contours: {
75+
coloring: "heatmap",
7876
},
79-
];
77+
x: reshapedXForPlot,
78+
y: reshapedYCoordinates[0],
79+
};
80+
81+
// Create mesh lines for the computational grid if showMesh is true
82+
let meshData = [];
83+
if (showMesh) {
84+
let meshLinesX = [];
85+
let meshLinesY = [];
86+
87+
// Horizontal mesh lines
88+
for (let i = 0; i < numNodesY; i++) {
89+
meshLinesX.push(...reshapedXCoordinates.map((row) => row[i]), null);
90+
meshLinesY.push(...reshapedYCoordinates.map((row) => row[i]), null);
91+
}
92+
93+
// Vertical mesh lines
94+
for (let i = 0; i < numNodesX; i++) {
95+
meshLinesX.push(...reshapedXCoordinates[i], null);
96+
meshLinesY.push(...reshapedYCoordinates[i], null);
97+
}
98+
99+
// Create the data structure for the mesh lines
100+
meshData = {
101+
x: meshLinesX,
102+
y: meshLinesY,
103+
mode: "lines",
104+
type: "scatter",
105+
line: {
106+
color: "palegoldenrod",
107+
width: 1,
108+
},
109+
showlegend: false,
110+
};
111+
}
80112

81113
// Set a fixed maximum window size for the plot
82114
let maxWindowWidth = Math.min(window.innerWidth, 700);
@@ -88,14 +120,18 @@ export function plotSolution(
88120

89121
// Set the layout for the contour plot
90122
let layout = {
91-
title: `${plotType} plot - ${solverConfig}`,
123+
title: `${plotType} plot${showMesh ? ' with mesh' : ''} - ${solverConfig}`,
92124
width: plotWidth,
93125
height: plotHeight,
94126
xaxis: { title: "x" },
95127
yaxis: { title: "y" },
96128
};
97129

98-
// Create the contour plot using Plotly
99-
Plotly.newPlot(plotDivId, data, layout);
130+
// Create the plot using Plotly
131+
let plotData = [contourData];
132+
if (showMesh) {
133+
plotData.push(meshData);
134+
}
135+
Plotly.newPlot(plotDivId, plotData, layout);
100136
}
101137
}

0 commit comments

Comments
 (0)