-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add initial support for ChartJs plugins
+ adding plugin for crosshair and zoom + adding plugin for data labels
- Loading branch information
Showing
15 changed files
with
23,592 additions
and
21,110 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,7 +170,7 @@ Page { | |
} | ||
|
||
contentItem: Item { | ||
Chart { | ||
ChartCanvas { | ||
id: graphComponent | ||
anchors.fill: parent | ||
} | ||
|
148 changes: 0 additions & 148 deletions
148
ui/StatusQ/src/StatusQ/Components/private/chart/Chart.qml
This file was deleted.
Oops, something went wrong.
113 changes: 113 additions & 0 deletions
113
ui/StatusQ/src/StatusQ/Components/private/chart/ChartCanvas.qml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import QtQuick 2.0 | ||
|
||
import "./Library/Library.js" as Lib | ||
|
||
Canvas { | ||
id: canvas | ||
|
||
readonly property var availablePlugins: { | ||
return { datalabels: ChartDataLabels } | ||
} | ||
|
||
property string type: chartType | ||
property var options: chartOptions | ||
property var plugins: [] | ||
property var labels: [] | ||
property var datasets: [] | ||
|
||
signal resized() | ||
|
||
function refresh() { | ||
if (d.instance) { | ||
Qt.callLater(d.refresh) | ||
} | ||
} | ||
|
||
function rebuild() { | ||
if (available) { | ||
Qt.callLater(d.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 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 (!d.instance) { | ||
rebuild() | ||
} | ||
} | ||
|
||
QtObject { | ||
id: d | ||
|
||
property var instance: null | ||
|
||
function refresh() { | ||
instance.config.options = canvas.options | ||
instance.config.plugins = canvas.plugins | ||
instance.data.labels = canvas.labels | ||
instance.update() | ||
} | ||
|
||
function rebuild() { | ||
if (instance) { | ||
instance.destroy() | ||
instance = null | ||
} | ||
var ctx = canvas.getContext('2d'); | ||
const config = { | ||
type: canvas.type, | ||
options: canvas.options, | ||
plugins: canvas.plugins, | ||
data: { | ||
labels: canvas.labels, | ||
datasets: canvas.datasets | ||
} | ||
} | ||
instance = new Chart(ctx, config) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.