-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChart.qml
109 lines (92 loc) · 2.61 KB
/
Chart.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import QtQuick 2.0
import "Private/Library.js" as Lib
Canvas {
id: canvas
property string type: "line"
property var options: ({})
property var plugins: []
property var labels: []
property var datasets: []
signal resized()
function refresh() {
if (_instance) {
Qt.callLater(_refresh)
}
}
function rebuild() {
if (available) {
Qt.callLater(_rebuild)
}
}
// [WORKAROUND] context.lineWidth > 1 makes the scene graph polish step very slow
// in case of "Image" render target, so by default let's draw with OpenGL when
// possible (which seems only possible with "Cooperative" strategy).
renderTarget: Canvas.FramebufferObject
renderStrategy: Canvas.Cooperative
// https://www.w3.org/TR/2012/WD-html5-author-20120329/the-canvas-element.html#the-canvas-element
implicitHeight: 150
implicitWidth: 300
// [polyfill] Element
readonly property alias clientHeight: canvas.height
readonly property alias clientWidth: canvas.width
// [polyfill] canvas.style
readonly property var style: ({
height: canvas.height,
width: canvas.width
})
// [polyfill] element.getBoundingClientRect
// https://developer.mozilla.org/docs/Web/API/Element/getBoundingClientRect
function getBoundingClientRect() {
return {top: 0, right: canvas.width, bottom: canvas.height, left: 0}
}
/**
\internal
*/
property var _instance: null
property alias _mouse: mouse
MouseArea {
id: mouse
anchors.fill: parent
hoverEnabled: enabled
enabled: false
}
onTypeChanged: rebuild()
onOptionsChanged: refresh()
onPluginsChanged: refresh()
onLabelsChanged: refresh()
onDatasetsChanged: rebuild()
onHeightChanged: resized()
onWidthChanged: resized()
onAvailableChanged: {
if (!_instance) {
rebuild()
}
}
/**
\internal
*/
function _refresh() {
_instance.config.options = canvas.options
_instance.config.plugins = canvas.plugins
_instance.data.labels = canvas.labels
_instance.update()
}
/**
\internal
*/
function _rebuild() {
if (_instance) {
_instance.destroy()
_instance = null
}
_instance = new Lib.Chart(canvas, {
type: canvas.type,
options: canvas.options,
plugins: canvas.plugins,
data: {
labels: canvas.labels,
datasets: canvas.datasets
}
})
}
}