MCPcopy Create free account
hub / github.com/KDE/labplot / autoScaleFitCurveCalculation

Method autoScaleFitCurveCalculation

tests/cartesianplot/CartesianPlotTest.cpp:966–1016  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

964}
965
966void CartesianPlotTest::autoScaleFitCurveCalculation() {
967 Project project;
968
969 auto* worksheet = new Worksheet(QStringLiteral("Worksheet"));
970 project.addChild(worksheet);
971 auto* view = dynamic_cast<WorksheetView*>(worksheet->view());
972 QVERIFY(view != nullptr);
973 view->initActions(); // needed by SET_CARTESIAN_MOUSE_MODE()
974
975 auto* plot = new CartesianPlot(QStringLiteral("plot"));
976 worksheet->addChild(plot);
977 plot->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created
978 plot->setNiceExtend(false);
979
980 auto* equationCurve{new XYEquationCurve(QStringLiteral("f(x)"))};
981 equationCurve->setCoordinateSystemIndex(plot->defaultCoordinateSystemIndex());
982 plot->addChild(equationCurve);
983
984 XYEquationCurve::EquationData data;
985 data.min = QStringLiteral("0");
986 data.max = QStringLiteral("1");
987 data.count = 10;
988 data.expression1 = QStringLiteral("x");
989 equationCurve->setEquationData(data);
990 equationCurve->recalculate();
991
992 CHECK_RANGE(plot, equationCurve, Dimension::X, 0., 1.);
993 CHECK_RANGE(plot, equationCurve, Dimension::Y, 0., 1.);
994
995 auto* fitCurve = new XYFitCurve(QStringLiteral("Fit"));
996 fitCurve->setCoordinateSystemIndex(plot->defaultCoordinateSystemIndex());
997 plot->addChild(fitCurve);
998
999 XYFitCurve::FitData f;
1000 f.autoRange = false;
1001 f.fitRange = Range<double>(0, 1);
1002 f.autoEvalRange = false;
1003 f.evalRange = Range<double>(0, 3); // larger than fit range
1004 f.modelCategory = nsl_fit_model_basic;
1005 f.modelType = nsl_fit_model_polynomial;
1006 f.degree = 1; // linear
1007 f.model = QStringLiteral("c0 + c1*x");
1008 fitCurve->initFitData(f); // Important, otherwise paramNames gets not filled
1009 fitCurve->setFitData(f);
1010 fitCurve->setDataSourceType(XYAnalysisCurve::DataSourceType::Curve);
1011 fitCurve->setDataSourceCurve(equationCurve);
1012 fitCurve->recalculate();
1013
1014 CHECK_RANGE(plot, equationCurve, Dimension::X, 0., 3.);
1015 CHECK_RANGE(plot, equationCurve, Dimension::Y, 0., 3.);
1016}
1017
1018void CartesianPlotTest::wheelEventCenterAxes() {
1019 Project project;

Callers

nothing calls this directly

Calls 13

setNiceExtendMethod · 0.80
setEquationDataMethod · 0.80
initFitDataMethod · 0.80
setDataSourceTypeMethod · 0.80
setDataSourceCurveMethod · 0.80
addChildMethod · 0.45
viewMethod · 0.45
initActionsMethod · 0.45
setTypeMethod · 0.45
recalculateMethod · 0.45

Tested by

no test coverage detected