Skip to content

Commit 44c6cd3

Browse files
committed
log charts
1 parent 2de487e commit 44c6cd3

File tree

4 files changed

+286
-1
lines changed

4 files changed

+286
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
import QtQuick
2+
import QtQuick.Controls
3+
import QtCharts
4+
5+
import EasyApp.Gui.Animations as EaAnimations
6+
import EasyApp.Gui.Style as EaStyle
7+
import EasyApp.Gui.Charts as EaCharts
8+
9+
10+
ChartView {
11+
id: chartView
12+
13+
property alias axisX: axisX
14+
property alias axisY: axisY
15+
16+
property bool useOpenGL: false
17+
property bool allowZoom: true
18+
property bool allowHover: true
19+
20+
anchors.top: parent.top
21+
anchors.bottom: parent.bottom
22+
anchors.left: parent.left
23+
anchors.right: parent.right
24+
anchors.margins: -12 // Reset default margins
25+
26+
antialiasing: true
27+
28+
legend.visible: false
29+
legend.alignment: Qt.AlignBottom
30+
legend.font.family: EaStyle.Fonts.fontFamily
31+
legend.font.pixelSize: EaStyle.Sizes.fontPixelSize
32+
legend.markerShape: Legend.MarkerShapeRectangle
33+
legend.labelColor: EaStyle.Colors.chartForeground
34+
Behavior on legend.labelColor { EaAnimations.ThemeChange {} }
35+
36+
backgroundRoundness: 0
37+
backgroundColor: EaStyle.Colors.chartBackground
38+
Behavior on backgroundColor { EaAnimations.ThemeChange {} }
39+
40+
titleFont.family: EaStyle.Fonts.fontFamily
41+
titleFont.pixelSize: EaStyle.Sizes.fontPixelSize
42+
titleFont.bold: true
43+
titleColor: EaStyle.Colors.chartForeground
44+
/* BREAKS ANIMATION !
45+
Behavior on titleColor { Animations.ThemeChange {} }
46+
*/
47+
48+
plotAreaColor: EaStyle.Colors.chartPlotAreaBackground
49+
Behavior on plotAreaColor { EaAnimations.ThemeChange {} }
50+
51+
animationOptions: ChartView.SeriesAnimations
52+
animationDuration: EaStyle.Times.chartAnimation
53+
54+
// X-axis
55+
EaCharts.QtCharts1dValueAxis {
56+
id: axisX
57+
}
58+
59+
// Y-axis
60+
EaCharts.QtCharts1dLogValueAxis {
61+
id: axisY
62+
}
63+
64+
// Zoom rectangle
65+
Rectangle{
66+
id: recZoom
67+
68+
property int xScaleZoom: 0
69+
property int yScaleZoom: 0
70+
71+
visible: false
72+
transform: Scale {
73+
origin.x: 0
74+
origin.y: 0
75+
xScale: recZoom.xScaleZoom
76+
yScale: recZoom.yScaleZoom
77+
}
78+
border.color: EaStyle.Colors.appBorder
79+
border.width: 1
80+
opacity: 0.9
81+
color: "transparent"
82+
83+
Rectangle {
84+
anchors.fill: parent
85+
opacity: 0.5
86+
color: recZoom.border.color
87+
}
88+
}
89+
90+
// Zoom with left mouse button
91+
MouseArea {
92+
id: zoomMouseArea
93+
94+
enabled: allowZoom
95+
anchors.fill: chartView
96+
acceptedButtons: Qt.LeftButton
97+
onPressed: {
98+
recZoom.x = mouseX
99+
recZoom.y = mouseY
100+
recZoom.visible = true
101+
}
102+
onMouseXChanged: {
103+
if (mouseX > recZoom.x) {
104+
recZoom.xScaleZoom = 1
105+
recZoom.width = Math.min(mouseX, chartView.width) - recZoom.x
106+
} else {
107+
recZoom.xScaleZoom = -1
108+
recZoom.width = recZoom.x - Math.max(mouseX, 0)
109+
}
110+
}
111+
onMouseYChanged: {
112+
if (mouseY > recZoom.y) {
113+
recZoom.yScaleZoom = 1
114+
recZoom.height = Math.min(mouseY, chartView.height) - recZoom.y
115+
} else {
116+
recZoom.yScaleZoom = -1
117+
recZoom.height = recZoom.y - Math.max(mouseY, 0)
118+
}
119+
}
120+
onReleased: {
121+
const x = Math.min(recZoom.x, mouseX) - chartView.anchors.leftMargin
122+
const y = Math.min(recZoom.y, mouseY) - chartView.anchors.topMargin
123+
const width = recZoom.width
124+
const height = recZoom.height
125+
chartView.zoomIn(Qt.rect(x, y, width, height))
126+
recZoom.visible = false
127+
}
128+
}
129+
130+
// Pan with left mouse button
131+
MouseArea {
132+
property real pressedX
133+
property real pressedY
134+
property int threshold: 1
135+
136+
enabled: !zoomMouseArea.enabled
137+
anchors.fill: chartView
138+
acceptedButtons: Qt.LeftButton
139+
onPressed: {
140+
pressedX = mouseX
141+
pressedY = mouseY
142+
}
143+
onMouseXChanged: Qt.callLater(update)
144+
onMouseYChanged: Qt.callLater(update)
145+
146+
function update() {
147+
const dx = mouseX - pressedX
148+
const dy = mouseY - pressedY
149+
pressedX = mouseX
150+
pressedY = mouseY
151+
152+
if (dx > threshold)
153+
chartView.scrollLeft(dx)
154+
else if (dx < -threshold)
155+
chartView.scrollRight(-dx)
156+
if (dy > threshold)
157+
chartView.scrollUp(dy)
158+
else if (dy < -threshold)
159+
chartView.scrollDown(-dy)
160+
}
161+
}
162+
163+
// Reset axes with right mouse button
164+
MouseArea {
165+
anchors.fill: chartView
166+
acceptedButtons: Qt.RightButton
167+
onClicked: resetAxes()
168+
}
169+
170+
// Logic
171+
172+
function resetAxes() {
173+
//chartView.zoomReset()
174+
axisX.min = axisX.minAfterReset
175+
axisX.max = axisX.maxAfterReset
176+
axisY.min = axisY.minAfterReset
177+
axisY.max = axisY.maxAfterReset
178+
}
179+
180+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import QtQuick
2+
import QtQuick.Controls
3+
import QtCharts
4+
5+
import EasyApp.Gui.Style as EaStyle
6+
import EasyApp.Gui.Charts as EaCharts
7+
8+
9+
EaCharts.QtCharts1dLogBase {
10+
id: chartView
11+
12+
property alias measSerie: measSerie
13+
property alias bkgSerie: bkgSerie
14+
property alias calcSerie: calcSerie
15+
16+
/*
17+
ScatterSeries {
18+
id: measSerie
19+
20+
axisX: chartView.axisX
21+
axisY: chartView.axisY
22+
23+
useOpenGL: chartView.useOpenGL
24+
25+
markerSize: 5
26+
borderWidth: 1
27+
color: EaStyle.Colors.chartForegroundsExtra[2]
28+
borderColor: this.color
29+
}
30+
*/
31+
32+
LineSeries {
33+
id: measSerie
34+
35+
axisX: chartView.axisX
36+
axisY: chartView.axisY
37+
38+
useOpenGL: chartView.useOpenGL
39+
40+
color: EaStyle.Colors.chartForegroundsExtra[2]
41+
width: 2
42+
}
43+
44+
LineSeries {
45+
id: bkgSerie
46+
47+
axisX: chartView.axisX
48+
axisY: chartView.axisY
49+
50+
useOpenGL: chartView.useOpenGL
51+
52+
color: EaStyle.Colors.chartForegrounds[1]
53+
width: 2
54+
}
55+
56+
LineSeries {
57+
id: calcSerie
58+
59+
axisX: chartView.axisX
60+
axisY: chartView.axisY
61+
62+
useOpenGL: chartView.useOpenGL
63+
64+
color: EaStyle.Colors.chartForegrounds[0]
65+
width: 2
66+
}
67+
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import QtQuick
2+
import QtCharts
3+
4+
import EasyApp.Gui.Animations as EaAnimations
5+
import EasyApp.Gui.Style as EaStyle
6+
import EasyApp.Gui.Globals 1.0 as EaGlobals
7+
8+
9+
LogValueAxis {
10+
property string title: ""
11+
property real minAfterReset: 0
12+
property real maxAfterReset: 1
13+
14+
lineVisible: false // Hide axes lines (only grid is visible)
15+
16+
color: EaStyle.Colors.chartAxis
17+
Behavior on color { EaAnimations.ThemeChange {} }
18+
19+
gridLineColor: EaStyle.Colors.chartGridLine
20+
Behavior on gridLineColor { EaAnimations.ThemeChange {} }
21+
22+
minorGridLineColor: EaStyle.Colors.chartMinorGridLine
23+
Behavior on minorGridLineColor { EaAnimations.ThemeChange {} }
24+
25+
labelsColor: EaStyle.Colors.chartLabels
26+
Behavior on labelsColor { EaAnimations.ThemeChange {} }
27+
28+
titleText: `<font color='${labelsColor}'>${title}</font>` // The only way to change a title color
29+
30+
labelsFont.family: EaStyle.Fonts.fontFamily
31+
labelsFont.pixelSize: EaStyle.Sizes.fontPixelSize
32+
titleFont.family: EaStyle.Fonts.fontFamily
33+
titleFont.pixelSize: EaStyle.Sizes.fontPixelSize
34+
}

src/EasyApp/Gui/Charts/qmldir

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
module Charts
22

33
QtCharts1dValueAxis QtCharts1dValueAxis.qml
4-
54
QtCharts1dBase QtCharts1dBase.qml
65
QtCharts1dMeasVsCalc QtCharts1dMeasVsCalc.qml
76

7+
QtCharts1dLogValueAxis QtChart1dLogValueAxis.qml
8+
QtCharts1dLogBase QtCharts1dLogBase.qml
9+
QtCharts1dLogMeasVsCalc QtCharts1dLogMeasVsCalc.qml
10+
811
Plotly1dLine Plotly1dLine.qml
912
Plotly1dMeasVsCalc Plotly1dMeasVsCalc.qml
1013

0 commit comments

Comments
 (0)