diff --git a/src/EasyApp/Gui/Charts/QtCharts1dLogBase.qml b/src/EasyApp/Gui/Charts/QtCharts1dLogBase.qml new file mode 100644 index 0000000..6c7ed48 --- /dev/null +++ b/src/EasyApp/Gui/Charts/QtCharts1dLogBase.qml @@ -0,0 +1,180 @@ +import QtQuick +import QtQuick.Controls +import QtCharts + +import EasyApp.Gui.Animations as EaAnimations +import EasyApp.Gui.Style as EaStyle +import EasyApp.Gui.Charts as EaCharts + + +ChartView { + id: chartView + + property alias axisX: axisX + property alias axisY: axisY + + property bool useOpenGL: false + property bool allowZoom: true + property bool allowHover: true + + anchors.top: parent.top + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.margins: -12 // Reset default margins + + antialiasing: true + + legend.visible: false + legend.alignment: Qt.AlignBottom + legend.font.family: EaStyle.Fonts.fontFamily + legend.font.pixelSize: EaStyle.Sizes.fontPixelSize + legend.markerShape: Legend.MarkerShapeRectangle + legend.labelColor: EaStyle.Colors.chartForeground + Behavior on legend.labelColor { EaAnimations.ThemeChange {} } + + backgroundRoundness: 0 + backgroundColor: EaStyle.Colors.chartBackground + Behavior on backgroundColor { EaAnimations.ThemeChange {} } + + titleFont.family: EaStyle.Fonts.fontFamily + titleFont.pixelSize: EaStyle.Sizes.fontPixelSize + titleFont.bold: true + titleColor: EaStyle.Colors.chartForeground + /* BREAKS ANIMATION ! + Behavior on titleColor { Animations.ThemeChange {} } + */ + + plotAreaColor: EaStyle.Colors.chartPlotAreaBackground + Behavior on plotAreaColor { EaAnimations.ThemeChange {} } + + animationOptions: ChartView.SeriesAnimations + animationDuration: EaStyle.Times.chartAnimation + + // X-axis + EaCharts.QtCharts1dValueAxis { + id: axisX + } + + // Y-axis + EaCharts.QtCharts1dLogValueAxis { + id: axisY + } + + // Zoom rectangle + Rectangle{ + id: recZoom + + property int xScaleZoom: 0 + property int yScaleZoom: 0 + + visible: false + transform: Scale { + origin.x: 0 + origin.y: 0 + xScale: recZoom.xScaleZoom + yScale: recZoom.yScaleZoom + } + border.color: EaStyle.Colors.appBorder + border.width: 1 + opacity: 0.9 + color: "transparent" + + Rectangle { + anchors.fill: parent + opacity: 0.5 + color: recZoom.border.color + } + } + + // Zoom with left mouse button + MouseArea { + id: zoomMouseArea + + enabled: allowZoom + anchors.fill: chartView + acceptedButtons: Qt.LeftButton + onPressed: { + recZoom.x = mouseX + recZoom.y = mouseY + recZoom.visible = true + } + onMouseXChanged: { + if (mouseX > recZoom.x) { + recZoom.xScaleZoom = 1 + recZoom.width = Math.min(mouseX, chartView.width) - recZoom.x + } else { + recZoom.xScaleZoom = -1 + recZoom.width = recZoom.x - Math.max(mouseX, 0) + } + } + onMouseYChanged: { + if (mouseY > recZoom.y) { + recZoom.yScaleZoom = 1 + recZoom.height = Math.min(mouseY, chartView.height) - recZoom.y + } else { + recZoom.yScaleZoom = -1 + recZoom.height = recZoom.y - Math.max(mouseY, 0) + } + } + onReleased: { + const x = Math.min(recZoom.x, mouseX) - chartView.anchors.leftMargin + const y = Math.min(recZoom.y, mouseY) - chartView.anchors.topMargin + const width = recZoom.width + const height = recZoom.height + chartView.zoomIn(Qt.rect(x, y, width, height)) + recZoom.visible = false + } + } + + // Pan with left mouse button + MouseArea { + property real pressedX + property real pressedY + property int threshold: 1 + + enabled: !zoomMouseArea.enabled + anchors.fill: chartView + acceptedButtons: Qt.LeftButton + onPressed: { + pressedX = mouseX + pressedY = mouseY + } + onMouseXChanged: Qt.callLater(update) + onMouseYChanged: Qt.callLater(update) + + function update() { + const dx = mouseX - pressedX + const dy = mouseY - pressedY + pressedX = mouseX + pressedY = mouseY + + if (dx > threshold) + chartView.scrollLeft(dx) + else if (dx < -threshold) + chartView.scrollRight(-dx) + if (dy > threshold) + chartView.scrollUp(dy) + else if (dy < -threshold) + chartView.scrollDown(-dy) + } + } + + // Reset axes with right mouse button + MouseArea { + anchors.fill: chartView + acceptedButtons: Qt.RightButton + onClicked: resetAxes() + } + + // Logic + + function resetAxes() { + //chartView.zoomReset() + axisX.min = axisX.minAfterReset + axisX.max = axisX.maxAfterReset + axisY.min = axisY.minAfterReset + axisY.max = axisY.maxAfterReset + } + +} diff --git a/src/EasyApp/Gui/Charts/QtCharts1dLogMeasVsCalc.qml b/src/EasyApp/Gui/Charts/QtCharts1dLogMeasVsCalc.qml new file mode 100644 index 0000000..ec2033d --- /dev/null +++ b/src/EasyApp/Gui/Charts/QtCharts1dLogMeasVsCalc.qml @@ -0,0 +1,68 @@ +import QtQuick +import QtQuick.Controls +import QtCharts + +import EasyApp.Gui.Style as EaStyle +import EasyApp.Gui.Charts as EaCharts + + +EaCharts.QtCharts1dLogBase { + id: chartView + + property alias measSerie: measSerie + property alias bkgSerie: bkgSerie + property alias calcSerie: calcSerie + + /* + ScatterSeries { + id: measSerie + + axisX: chartView.axisX + axisY: chartView.axisY + + useOpenGL: chartView.useOpenGL + + markerSize: 5 + borderWidth: 1 + color: EaStyle.Colors.chartForegroundsExtra[2] + borderColor: this.color + } + */ + + LineSeries { + id: measSerie + + axisX: chartView.axisX + axisY: chartView.axisY + + useOpenGL: chartView.useOpenGL + + color: EaStyle.Colors.chartForegroundsExtra[2] + width: 2 + } + + LineSeries { + id: bkgSerie + + axisX: chartView.axisX + axisY: chartView.axisY + + useOpenGL: chartView.useOpenGL + + color: EaStyle.Colors.chartForegrounds[1] + width: 2 + } + + LineSeries { + id: calcSerie + + axisX: chartView.axisX + axisY: chartView.axisY + + useOpenGL: chartView.useOpenGL + + color: EaStyle.Colors.chartForegrounds[0] + width: 2 + } + +} diff --git a/src/EasyApp/Gui/Charts/QtCharts1dLogValueAxis.qml b/src/EasyApp/Gui/Charts/QtCharts1dLogValueAxis.qml new file mode 100644 index 0000000..606d0e7 --- /dev/null +++ b/src/EasyApp/Gui/Charts/QtCharts1dLogValueAxis.qml @@ -0,0 +1,34 @@ +import QtQuick +import QtCharts + +import EasyApp.Gui.Animations as EaAnimations +import EasyApp.Gui.Style as EaStyle +import EasyApp.Gui.Globals 1.0 as EaGlobals + + +LogValueAxis { + property string title: "" + property real minAfterReset: 0 + property real maxAfterReset: 1 + + lineVisible: false // Hide axes lines (only grid is visible) + + color: EaStyle.Colors.chartAxis + Behavior on color { EaAnimations.ThemeChange {} } + + gridLineColor: EaStyle.Colors.chartGridLine + Behavior on gridLineColor { EaAnimations.ThemeChange {} } + + minorGridLineColor: EaStyle.Colors.chartMinorGridLine + Behavior on minorGridLineColor { EaAnimations.ThemeChange {} } + + labelsColor: EaStyle.Colors.chartLabels + Behavior on labelsColor { EaAnimations.ThemeChange {} } + + titleText: `${title}` // The only way to change a title color + + labelsFont.family: EaStyle.Fonts.fontFamily + labelsFont.pixelSize: EaStyle.Sizes.fontPixelSize + titleFont.family: EaStyle.Fonts.fontFamily + titleFont.pixelSize: EaStyle.Sizes.fontPixelSize +} diff --git a/src/EasyApp/Gui/Charts/qmldir b/src/EasyApp/Gui/Charts/qmldir index dacfe70..8c688b3 100644 --- a/src/EasyApp/Gui/Charts/qmldir +++ b/src/EasyApp/Gui/Charts/qmldir @@ -1,10 +1,13 @@ module Charts QtCharts1dValueAxis QtCharts1dValueAxis.qml - QtCharts1dBase QtCharts1dBase.qml QtCharts1dMeasVsCalc QtCharts1dMeasVsCalc.qml +QtCharts1dLogValueAxis QtChart1dLogValueAxis.qml +QtCharts1dLogBase QtCharts1dLogBase.qml +QtCharts1dLogMeasVsCalc QtCharts1dLogMeasVsCalc.qml + Plotly1dLine Plotly1dLine.qml Plotly1dMeasVsCalc Plotly1dMeasVsCalc.qml