better error handling for bounds
This commit is contained in:
parent
30dfcfa36a
commit
7525b3acf2
44
www/index.js
44
www/index.js
@ -85,10 +85,40 @@ function onMouseMove(event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updatePlot() {
|
function postErrorStatus(string) {
|
||||||
|
status.style.color = "red";
|
||||||
|
status.innerText = string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function postNormalStatus(string) {
|
||||||
status.style.color = "grey";
|
status.style.color = "grey";
|
||||||
status.innerText = `Rendering y=${math_function.value}...`;
|
status.innerText = string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updatePlot() {
|
||||||
|
postNormalStatus(`Rendering y=${math_function.value}...`);
|
||||||
|
|
||||||
|
if (minX.value > maxX.value) {
|
||||||
|
postErrorStatus("minX is larger than maxX!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minY.value > maxY.value) {
|
||||||
|
postErrorStatus("minY is larger than maxY!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 > num_interval.value) {
|
||||||
|
postErrorStatus("Interval is smaller than 0!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 > resolution.value) {
|
||||||
|
postErrorStatus("resolution (Number of Points) is smaller than 0!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (chart_manager == null) {
|
if (chart_manager == null) {
|
||||||
chart_manager = ChartManager.new(math_function.value, Number(minX.value), Number(maxX.value), Number(minY.value), Number(maxY.value), Number(num_interval.value), Number(resolution.value));
|
chart_manager = ChartManager.new(math_function.value, Number(minX.value), Number(maxX.value), Number(minY.value), Number(maxY.value), Number(num_interval.value), Number(resolution.value));
|
||||||
}
|
}
|
||||||
@ -96,11 +126,10 @@ function updatePlot() {
|
|||||||
const test_result = ChartManager.test_func(math_function.value);
|
const test_result = ChartManager.test_func(math_function.value);
|
||||||
if (test_result != "") {
|
if (test_result != "") {
|
||||||
const error_recommendation = ChartManager.error_recommend(test_result);
|
const error_recommendation = ChartManager.error_recommend(test_result);
|
||||||
status.style.color = "red";
|
|
||||||
if (error_recommendation == "") {
|
if (error_recommendation == "") {
|
||||||
status.innerText = test_result;
|
postErrorStatus(test_result);
|
||||||
} else {
|
} else {
|
||||||
status.innerText = `${test_result}\nTip: ${error_recommendation}`
|
postErrorStatus(`${test_result}\nTip: ${error_recommendation}`);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -112,9 +141,8 @@ function updatePlot() {
|
|||||||
|
|
||||||
area_msg.innerText = `Estimated Area: ${chart.get_area()}`;
|
area_msg.innerText = `Estimated Area: ${chart.get_area()}`;
|
||||||
|
|
||||||
status.innerText = `Rendered ${math_function.innerText} in ${Math.ceil(end - start)}ms`;
|
postNormalStatus(`Rendered ${math_function.innerText} in ${Math.ceil(end - start)}ms`);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
status.style.color = "red";
|
postErrorStatus(`Error! check console logs for more detail`);
|
||||||
status.innerText = `Error! check console logs for more detail`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user