QuickGraphLib 0.1.0a0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) 2024 Matthew Joyce and other QuickGraphLib contributors
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import QtQuick
5
+
6
+ /*!
7
+ \qmltype AntialiasingContainer
8
+ \inqmlmodule QuickGraphLib
9
+ \inherits QtQuick::Item
10
+ \brief Enables antialiasing for it's contents.
11
+ */
12
+
13
+ Item {
14
+ implicitHeight: 100
15
+ implicitWidth: 100
16
+ layer.enabled: true // Improves rendering of fractional DPIs
17
+ layer.samples: 2
18
+ }
QuickGraphLib/Axis.qml ADDED
@@ -0,0 +1,227 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) 2024 Matthew Joyce and other QuickGraphLib contributors
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ pragma ComponentBehavior: Bound
5
+ import QtQuick
6
+ import QtQuick.Shapes as QQS
7
+
8
+ /*!
9
+ \qmltype Axis
10
+ \inqmlmodule QuickGraphLib
11
+ \inherits QtQuick::Item
12
+ \brief Displays an Axis.
13
+ */
14
+
15
+ Item {
16
+ id: root
17
+
18
+ enum Direction {
19
+ Left,
20
+ Right,
21
+ Top,
22
+ Bottom
23
+ }
24
+
25
+ property list<point> _path: _calculateTickPath(ticks, direction, width, height, dataTransform)
26
+ property list<int> _tickPositions
27
+ /*!
28
+ TODO
29
+ \sa {GraphArea::dataTransform}
30
+ */
31
+ required property matrix4x4 dataTransform
32
+ /*! TODO */
33
+ property int decimalPoints: 2
34
+ /*! TODO
35
+
36
+
37
+ \value Axis.Direction.Left Axis to the left of the GraphArea
38
+ \value Axis.Direction.Right Axis to the right of the GraphArea
39
+ \value Axis.Direction.Top Axis above of the GraphArea
40
+ \value Axis.Direction.Bottom Axis below of the GraphArea
41
+ */
42
+ required property int direction
43
+ /*! TODO */
44
+ property alias label: labelText.text
45
+ /*! TODO */
46
+ property bool showTickLabels: true
47
+ /*! TODO */
48
+ property double spacing: 4
49
+ /*! TODO */
50
+ property double tickLength: 10
51
+ /*! TODO */
52
+ required property list<double> ticks
53
+
54
+ function _calculateTickPath(ticks, direction: int, width: double, height: double, dataTransform) {
55
+ const longAxis = direction == Axis.Direction.Top || direction == Axis.Direction.Bottom ? width : height;
56
+ let transformedTicks = ticks.map(t => dataTransform.map(Qt.point(t, t))[direction == Axis.Direction.Top || direction == Axis.Direction.Bottom ? "x" : "y"]);
57
+
58
+ // Calculate everything as if we were a bottom axis
59
+ let points = [Qt.point(0, 0)], tickPositions = [];
60
+ transformedTicks.forEach(t => {
61
+ if (t >= -0.5 && t <= longAxis + 0.5) {
62
+ points.push(Qt.point(t, 0));
63
+ points.push(Qt.point(t, root.tickLength));
64
+ points.push(Qt.point(t, 0));
65
+ tickPositions.push(points.length - 2);
66
+ } else {
67
+ tickPositions.push(-1);
68
+ }
69
+ });
70
+ points.push(Qt.point(longAxis, 0));
71
+ _tickPositions = tickPositions;
72
+
73
+ // Transform into the correct positions
74
+ switch (root.direction) {
75
+ case Axis.Direction.Left:
76
+ return points.map(p => Qt.point(width - p.y, p.x));
77
+ case Axis.Direction.Right:
78
+ return points.map(p => Qt.point(p.y, p.x));
79
+ case Axis.Direction.Top:
80
+ return points.map(p => Qt.point(p.x, height - p.y));
81
+ case Axis.Direction.Bottom:
82
+ return points;
83
+ }
84
+ }
85
+
86
+ implicitHeight: {
87
+ switch (root.direction) {
88
+ case Axis.Direction.Left:
89
+ case Axis.Direction.Right:
90
+ return 100;
91
+ case Axis.Direction.Top:
92
+ case Axis.Direction.Bottom:
93
+ let height = 0;
94
+ if (ticks.length > 0) {
95
+ height += root.tickLength + Math.max(0, ...[...Array(tickLabels.count).keys()].map(i => tickLabels.itemAt(i)?.height));
96
+ }
97
+ if (label != "") {
98
+ height += labelText.height + root.spacing;
99
+ }
100
+ return height;
101
+ }
102
+ }
103
+ implicitWidth: {
104
+ switch (root.direction) {
105
+ case Axis.Direction.Left:
106
+ case Axis.Direction.Right:
107
+ let width = 0;
108
+ if (ticks.length > 0) {
109
+ width += root.tickLength + Math.max(0, ...[...Array(tickLabels.count).keys()].map(i => tickLabels.itemAt(i)?.width));
110
+ }
111
+ if (label != "") {
112
+ width += labelText.height + root.spacing;
113
+ }
114
+ return width;
115
+ case Axis.Direction.Top:
116
+ case Axis.Direction.Bottom:
117
+ return 100;
118
+ }
119
+ }
120
+ z: 1
121
+
122
+ QQS.Shape {
123
+ id: shape
124
+
125
+ anchors.fill: parent
126
+
127
+ QQS.ShapePath {
128
+ id: myPath
129
+
130
+ startX: root._path[0].x
131
+ startY: root._path[0].y
132
+ strokeColor: "black"
133
+ strokeWidth: 1
134
+
135
+ PathPolyline {
136
+ path: root._path
137
+ }
138
+ }
139
+ }
140
+ Repeater {
141
+ id: tickLabels
142
+
143
+ model: root.showTickLabels ? root.ticks : []
144
+
145
+ Text {
146
+ required property int index
147
+ required property double modelData
148
+
149
+ leftPadding: 2
150
+ rightPadding: 2
151
+ text: Number(modelData).toFixed(root.decimalPoints)
152
+ visible: root._tickPositions[index] >= 0
153
+ x: {
154
+ let baseX = root._path[root._tickPositions[index]]?.x ?? 0;
155
+ switch (root.direction) {
156
+ case Axis.Direction.Left:
157
+ return baseX - width;
158
+ case Axis.Direction.Right:
159
+ return baseX;
160
+ case Axis.Direction.Top:
161
+ return baseX - width / 2;
162
+ case Axis.Direction.Bottom:
163
+ return baseX - width / 2;
164
+ }
165
+ }
166
+ y: {
167
+ let baseY = root._path[root._tickPositions[index]]?.y ?? 0;
168
+ switch (root.direction) {
169
+ case Axis.Direction.Left:
170
+ return baseY - height / 2;
171
+ case Axis.Direction.Right:
172
+ return baseY - height / 2;
173
+ case Axis.Direction.Top:
174
+ return baseY - height;
175
+ case Axis.Direction.Bottom:
176
+ return baseY;
177
+ }
178
+ }
179
+ }
180
+ }
181
+ Text {
182
+ id: labelText
183
+
184
+ x: {
185
+ switch (root.direction) {
186
+ case Axis.Direction.Left:
187
+ return height / 2;
188
+ case Axis.Direction.Right:
189
+ return root.width - height / 2;
190
+ case Axis.Direction.Top:
191
+ case Axis.Direction.Bottom:
192
+ return root.width / 2;
193
+ }
194
+ }
195
+ y: {
196
+ switch (root.direction) {
197
+ case Axis.Direction.Left:
198
+ case Axis.Direction.Right:
199
+ return root.height / 2;
200
+ case Axis.Direction.Top:
201
+ return height / 2;
202
+ case Axis.Direction.Bottom:
203
+ return root.height - height / 2;
204
+ }
205
+ }
206
+
207
+ transform: [
208
+ Translate {
209
+ x: -labelText.width / 2
210
+ y: -labelText.height / 2
211
+ },
212
+ Rotation {
213
+ angle: {
214
+ switch (root.direction) {
215
+ case Axis.Direction.Left:
216
+ return -90;
217
+ case Axis.Direction.Right:
218
+ return 90;
219
+ case Axis.Direction.Top:
220
+ case Axis.Direction.Bottom:
221
+ return 0;
222
+ }
223
+ }
224
+ }
225
+ ]
226
+ }
227
+ }
@@ -0,0 +1,54 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) 2024 Matthew Joyce and other QuickGraphLib contributors
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import QtQuick
5
+ import QtQuick.Shapes as QQS
6
+
7
+ /*!
8
+ \qmltype Histogram
9
+ \inqmlmodule QuickGraphLib
10
+ \inherits QtQuick::Shapes::Shape
11
+ \brief An area that graphs can be added to.
12
+ */
13
+
14
+ QQS.Shape {
15
+ id: root
16
+
17
+ /*!
18
+ Transform from data coordinates to pixel coordinates inside the GraphArea with the viewTransform applied
19
+ */
20
+ readonly property matrix4x4 dataTransform: viewTransform.times(rawDataTransform)
21
+ /*!
22
+ The view rect the view is actually showing based on viewTransform
23
+ */
24
+ readonly property rect effectiveViewRect: {
25
+ let mat = rawDataTransform.inverted().times(viewTransform.inverted().times(rawDataTransform));
26
+ return mat.mapRect(viewRect);
27
+ }
28
+ /*!
29
+ Transform from data coordinates to pixel coordinates inside the GraphArea
30
+ */
31
+ readonly property matrix4x4 rawDataTransform: {
32
+ let mat = Qt.matrix4x4();
33
+ // Flip coordinate system so that Y points upwards
34
+ mat.translate(Qt.vector3d(0, root.height, 0));
35
+ mat.scale(root.width / viewRect.width, -root.height / viewRect.height, 1);
36
+ mat.translate(Qt.vector3d(-viewRect.x, -viewRect.y, 0));
37
+ return mat;
38
+ }
39
+ /*! TODO */
40
+ required property rect viewRect
41
+ /*! TODO */
42
+ property matrix4x4 viewTransform
43
+
44
+ function baseTransformFromRect(r: rect): matrix4x4 {
45
+ let mat = Qt.matrix4x4();
46
+ mat.scale(viewRect.width / r.width, viewRect.height / r.height, 1);
47
+ mat.translate(Qt.vector3d((viewRect.x - r.x) / viewRect.width, (r.y + r.height - viewRect.y - viewRect.height) / viewRect.height, 0));
48
+ return mat;
49
+ }
50
+
51
+ clip: true
52
+ implicitHeight: 100
53
+ implicitWidth: 100
54
+ }
@@ -0,0 +1,25 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) 2024 Matthew Joyce and other QuickGraphLib contributors
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import QtQuick
5
+
6
+ /*!
7
+ \qmltype AxHLine
8
+ \inqmlmodule QuickGraphLib.GraphItems
9
+ \inherits QtQuick::Rectangle
10
+ \brief Displays a horizontal line.
11
+ */
12
+
13
+ Rectangle {
14
+ id: root
15
+
16
+ /*! TODO */
17
+ required property matrix4x4 dataTransform
18
+ /*! TODO */
19
+ required property double position
20
+
21
+ height: 2
22
+ width: parent.width + border.width * 4
23
+ x: -border.width * 2
24
+ y: root.dataTransform.map(Qt.point(0, position)).y - height / 2
25
+ }
@@ -0,0 +1,28 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) 2024 Matthew Joyce and other QuickGraphLib contributors
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import QtQuick
5
+
6
+ /*!
7
+ \qmltype AxHSpan
8
+ \inqmlmodule QuickGraphLib.GraphItems
9
+ \inherits QtQuick::Rectangle
10
+ \brief Displays a horizontal span.
11
+ */
12
+
13
+ Rectangle {
14
+ id: root
15
+
16
+ /*! TODO */
17
+ required property matrix4x4 dataTransform
18
+ /*! TODO */
19
+ required property double yMax
20
+ /*! TODO */
21
+ required property double yMin
22
+
23
+ border.width: 0
24
+ height: root.dataTransform.map(Qt.point(0, yMin)).y - root.dataTransform.map(Qt.point(0, yMax)).y
25
+ width: parent.width + border.width * 4
26
+ x: -border.width * 2
27
+ y: root.dataTransform.map(Qt.point(0, yMax)).y
28
+ }
@@ -0,0 +1,25 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) 2024 Matthew Joyce and other QuickGraphLib contributors
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import QtQuick
5
+
6
+ /*!
7
+ \qmltype AxVLine
8
+ \inqmlmodule QuickGraphLib.GraphItems
9
+ \inherits QtQuick::Rectangle
10
+ \brief Displays an vertical line.
11
+ */
12
+
13
+ Rectangle {
14
+ id: root
15
+
16
+ /*! TODO */
17
+ required property matrix4x4 dataTransform
18
+ /*! TODO */
19
+ required property double position
20
+
21
+ height: parent.height + border.width * 4
22
+ width: 2
23
+ x: root.dataTransform.map(Qt.point(position, 0)).x - width / 2
24
+ y: -border.width * 2
25
+ }
@@ -0,0 +1,28 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) 2024 Matthew Joyce and other QuickGraphLib contributors
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import QtQuick
5
+
6
+ /*!
7
+ \qmltype AxVSpan
8
+ \inqmlmodule QuickGraphLib.GraphItems
9
+ \inherits QtQuick::Rectangle
10
+ \brief Displays an vertical span.
11
+ */
12
+
13
+ Rectangle {
14
+ id: root
15
+
16
+ /*! TODO */
17
+ required property matrix4x4 dataTransform
18
+ /*! TODO */
19
+ required property double xMax
20
+ /*! TODO */
21
+ required property double xMin
22
+
23
+ border.width: 0
24
+ height: parent.height + border.width * 4
25
+ width: root.dataTransform.map(Qt.point(xMax, 0)).x - root.dataTransform.map(Qt.point(xMin, 0)).x
26
+ x: root.dataTransform.map(Qt.point(xMin, 0)).x
27
+ y: -border.width * 2
28
+ }
@@ -0,0 +1,29 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) 2024 Matthew Joyce and other QuickGraphLib contributors
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import QtQuick
5
+
6
+ /*!
7
+ \qmltype BasicLegend
8
+ \inqmlmodule QuickGraphLib.GraphItems
9
+ \inherits QtQuick::Rectangle
10
+ \brief Displays a simple legend.
11
+ */
12
+
13
+ Rectangle {
14
+ /*! TODO */
15
+ default property alias contentChildren: legend.children
16
+ /*! TODO */
17
+ property alias verticalSpacing: legend.spacing
18
+
19
+ border.color: "black"
20
+ color: "#aaffffff"
21
+ height: legend.height + 10
22
+ width: legend.width + 10
23
+
24
+ Column {
25
+ id: legend
26
+
27
+ anchors.centerIn: parent
28
+ }
29
+ }
@@ -0,0 +1,54 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) 2024 Matthew Joyce and other QuickGraphLib contributors
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import QtQuick
5
+
6
+ /*!
7
+ \qmltype BasicLegendItem
8
+ \inqmlmodule QuickGraphLib.GraphItems
9
+ \inherits QtQuick::Row
10
+ \brief An single entry in a simple legend.
11
+ */
12
+
13
+ Row {
14
+ id: root
15
+
16
+ /*! TODO */
17
+ property color fillColor: "transparent"
18
+ /*! TODO */
19
+ property Gradient fillGradient: null
20
+
21
+ /*! TODO */
22
+ property color strokeColor: "black"
23
+ /*! TODO */
24
+ property real strokeWidth: 1
25
+ /*! TODO */
26
+ property alias text: label.text
27
+
28
+ spacing: 2
29
+
30
+ Item {
31
+ id: clipper
32
+
33
+ anchors.verticalCenter: parent.verticalCenter
34
+ clip: true
35
+ height: root.height - 2
36
+ width: root.height - 2
37
+
38
+ Rectangle {
39
+ border.color: root.strokeColor
40
+ border.width: root.strokeWidth
41
+ color: root.fillColor
42
+ gradient: root.fillGradient
43
+ height: clipper.height / 2 + root.strokeWidth * 2
44
+ width: clipper.width + root.strokeWidth * 4
45
+ x: -root.strokeWidth * 2
46
+ y: clipper.height / 2
47
+ }
48
+ }
49
+ Text {
50
+ id: label
51
+
52
+ anchors.verticalCenter: parent.verticalCenter
53
+ }
54
+ }
@@ -0,0 +1,33 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) 2024 Matthew Joyce and other QuickGraphLib contributors
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import QtQuick
5
+ import QtQuick.Shapes as QQS
6
+
7
+ /*!
8
+ \qmltype Contours
9
+ \inqmlmodule QuickGraphLib.GraphItems
10
+ \inherits QtQuick::Shapes::ShapePath
11
+ \brief Draw a contour line or fill.
12
+ */
13
+
14
+ QQS.ShapePath {
15
+ id: root
16
+
17
+ /*!
18
+ TODO
19
+ */
20
+ required property matrix4x4 dataTransform
21
+ /*!
22
+ TODO
23
+ */
24
+ required property var paths
25
+
26
+ capStyle: QQS.ShapePath.RoundCap
27
+ fillColor: "transparent"
28
+ joinStyle: QQS.ShapePath.RoundJoin
29
+
30
+ PathMultiline {
31
+ paths: root.paths.map(ps => ps.map(p => root.dataTransform.map(p)))
32
+ }
33
+ }
@@ -0,0 +1,39 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) 2024 Matthew Joyce and other QuickGraphLib contributors
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import QtQuick
5
+
6
+ /*!
7
+ \qmltype GraphItemDragHandler
8
+ \inqmlmodule QuickGraphLib.GraphItems
9
+ \inherits QtQuick::MouseArea
10
+ \brief Assists converting mouse drags into data positions.
11
+ */
12
+
13
+ MouseArea {
14
+ id: root
15
+
16
+ property rect _startDragPos
17
+
18
+ /*! TODO */
19
+ required property matrix4x4 dataTransform
20
+ /*! TODO */
21
+ property bool dragging
22
+
23
+ signal moved(rect position)
24
+
25
+ hoverEnabled: true
26
+
27
+ onPositionChanged: event => {
28
+ if (dragging) {
29
+ moved(dataTransform.inverted().mapRect(Qt.rect(parent.x + event.x - _startDragPos.x, parent.y + event.y - _startDragPos.y, _startDragPos.width, _startDragPos.height)));
30
+ }
31
+ }
32
+ onPressed: event => {
33
+ _startDragPos = Qt.rect(mouseX, mouseY, width, height);
34
+ dragging = true;
35
+ }
36
+ onReleased: event => {
37
+ dragging = false;
38
+ }
39
+ }
@@ -0,0 +1,58 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) 2024 Matthew Joyce and other QuickGraphLib contributors
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import QtQuick
5
+ import QtQuick.Shapes as QQS
6
+
7
+ /*!
8
+ \qmltype Grid
9
+ \inqmlmodule QuickGraphLib.GraphItems
10
+ \inherits QtQuick::Shapes::ShapePath
11
+ \brief Displays a grid in the background of a graph.
12
+ */
13
+
14
+ QQS.ShapePath {
15
+ id: root
16
+
17
+ /*! TODO */
18
+ required property matrix4x4 dataTransform
19
+ /*! TODO */
20
+ required property double parentHeight
21
+ /*! TODO */
22
+ required property double parentWidth
23
+ /*! TODO */
24
+ property list<double> xTicks: []
25
+ /*! TODO */
26
+ property list<double> yTicks: []
27
+
28
+ function _calculateXPath(xTicks, dataTransform, parentHeight) {
29
+ let points = [];
30
+ xTicks.forEach(t => {
31
+ let x = dataTransform.map(Qt.point(t, 0)).x;
32
+ points.push(Qt.point(x, -10));
33
+ points.push(Qt.point(x, parentHeight + 10));
34
+ points.push(Qt.point(x, -10));
35
+ });
36
+ return points;
37
+ }
38
+ function _calculateYPath(yTicks, dataTransform, parentWidth) {
39
+ let points = [];
40
+ yTicks.forEach(t => {
41
+ let y = dataTransform.map(Qt.point(0, t)).y;
42
+ points.push(Qt.point(-10, y));
43
+ points.push(Qt.point(parentWidth + 10, y));
44
+ points.push(Qt.point(-10, y));
45
+ });
46
+ return points;
47
+ }
48
+
49
+ capStyle: QQS.ShapePath.RoundCap
50
+ joinStyle: QQS.ShapePath.RoundJoin
51
+
52
+ PathPolyline {
53
+ path: root._calculateXPath(root.xTicks, root.dataTransform, root.parentHeight)
54
+ }
55
+ PathPolyline {
56
+ path: root._calculateYPath(root.yTicks, root.dataTransform, root.parentWidth)
57
+ }
58
+ }
@@ -0,0 +1,50 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) 2024 Matthew Joyce and other QuickGraphLib contributors
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import QtQuick
5
+ import QtQuick.Shapes as QQS
6
+
7
+ /*!
8
+ \qmltype Histogram
9
+ \inqmlmodule QuickGraphLib.GraphItems
10
+ \inherits QtQuick::Shapes::ShapePath
11
+ \brief Displays a histogram.
12
+ */
13
+
14
+ QQS.ShapePath {
15
+ id: root
16
+
17
+ /*! TODO */
18
+ required property var bins
19
+ /*! TODO */
20
+ required property matrix4x4 dataTransform
21
+ /*! TODO */
22
+ required property var heights
23
+ /*! TODO */
24
+ property bool vertical: false
25
+
26
+ function _calculatePoints(bins, heights) {
27
+ if (bins.length != heights.length + 1) {
28
+ print(bins.length, heights.length);
29
+ return [];
30
+ }
31
+ let points = [Qt.point(bins[0], 0)];
32
+ heights.forEach((h, i) => {
33
+ points.push(Qt.point(bins[i], h));
34
+ points.push(Qt.point(bins[i + 1], h));
35
+ });
36
+ points.push(Qt.point(bins[bins.length - 1], 0));
37
+ if (root.vertical) {
38
+ return points.map(p => Qt.point(p.y, p.x));
39
+ } else {
40
+ return points;
41
+ }
42
+ }
43
+
44
+ capStyle: QQS.ShapePath.RoundCap
45
+ joinStyle: QQS.ShapePath.RoundJoin
46
+
47
+ PathPolyline {
48
+ path: root._calculatePoints(root.bins, root.heights).map(p => root.dataTransform.map(p))
49
+ }
50
+ }