Skip to content

Commit bdade5e

Browse files
author
MichaelV
committed
added possibility to animate to changes, fixed rectangles in bars to display with borders more like expected and fixed licensing
1 parent 482962b commit bdade5e

File tree

5 files changed

+127
-14
lines changed

5 files changed

+127
-14
lines changed

Chart.bundle.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -4669,20 +4669,18 @@ var element_rectangle = core_element.extend({
46694669
var outer = rects.outer;
46704670
var inner = rects.inner;
46714671

4672-
ctx.fillStyle = vm.backgroundColor;
4673-
ctx.fillRect(outer.x, outer.y, outer.w, outer.h);
4672+
ctx.save();
46744673

4675-
if (outer.w === inner.w && outer.h === inner.h) {
4676-
return;
4674+
if (outer.w !== inner.w || outer.h !== inner.h) {
4675+
ctx.beginPath();
4676+
ctx.strokeStyle = vm.borderColor;
4677+
ctx.strokeRect(inner.x, inner.y, inner.w, inner.h);
4678+
ctx.fill('evenodd');
46774679
}
46784680

4679-
ctx.save();
4680-
ctx.beginPath();
4681-
ctx.rect(outer.x, outer.y, outer.w, outer.h);
4682-
ctx.clip();
4683-
ctx.fillStyle = vm.borderColor;
4684-
ctx.rect(inner.x, inner.y, inner.w, inner.h);
4685-
ctx.fill('evenodd');
4681+
ctx.fillStyle = vm.backgroundColor;
4682+
ctx.fillRect(inner.x, inner.y, inner.w, inner.h);
4683+
46864684
ctx.restore();
46874685
},
46884686

Chart.qml

+7
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ Canvas {
103103
jsChart.draw(chartAnimationProgress);
104104
}
105105

106+
function animateToNewData()
107+
{
108+
chartAnimationProgress = 0.1;
109+
jsChart.update();
110+
chartAnimator.restart();
111+
}
112+
106113
onWidthChanged: {
107114
if(jsChart) {
108115
jsChart.resize();

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 IceMichael
3+
Copyright (c) 2020 ChartJs2QML contributors (starting with Elypson, Michael A. Voelkel, https://github.com/Elypson)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

animationExample.qml

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*!
2+
* Elypson's Chart.qml adaptor to Chart.js
3+
* (c) 2020 ChartJs2QML contributors (starting with Elypson, Michael A. Voelkel, https://github.com/Elypson)
4+
* Released under the MIT License
5+
*/
6+
7+
import QtQuick 2.0
8+
import QtQuick.Window 2.0
9+
import "Chart.bundle.js" as Chart
10+
11+
Window {
12+
id: myWindow
13+
width: 800
14+
height: 800
15+
16+
function generateData() {
17+
var result = [];
18+
for(var i = 0; i < 10; ++i) {
19+
result[i] = Math.random().toFixed(2);
20+
}
21+
return result;
22+
}
23+
24+
Chart {
25+
id: chart
26+
chartType: 'bar'
27+
chartData: {
28+
return {
29+
labels: [1,2,3,4,5,6,7,8,9,10],
30+
datasets: [{
31+
label: 'One dataset',
32+
xAxisId: 'x-axis-1',
33+
yAxisId: 'y-axis-1',
34+
backgroundColor: 'rgba(255, 192, 192, 0.8)',
35+
borderColor: 'rgba(255,0,0,1)',
36+
borderWidth: 1,
37+
data: myWindow.generateData()
38+
}]
39+
}
40+
}
41+
42+
chartOptions: {return {
43+
maintainAspectRatio: false,
44+
responsive: true,
45+
hoverMode: 'nearest',
46+
intersect: true,
47+
title: {
48+
display: true,
49+
text: 'Chart.js Scatter Chart - Multi Axis'
50+
},
51+
scales: {
52+
xAxes: [{
53+
position: 'bottom',
54+
id: 'x-axis-1',
55+
gridLines: {
56+
zeroLineColor: 'rgba(0,0,0,1)'
57+
}
58+
}],
59+
yAxes: [{
60+
display: true,
61+
position: 'left',
62+
id: 'y-axis-1',
63+
ticks: {
64+
min: 0,
65+
max: 1,
66+
stepSize: 0.1
67+
}
68+
}]
69+
}
70+
}
71+
}
72+
73+
anchors {
74+
fill: parent
75+
bottomMargin: 50
76+
}
77+
}
78+
Rectangle {
79+
anchors {
80+
horizontalCenter: parent.horizontalCenter
81+
bottom: parent.bottom
82+
topMargin: 5
83+
bottomMargin: 5
84+
}
85+
height: 40
86+
width: parent.width * 0.6
87+
color: "#eee"
88+
border.color: "#999"
89+
90+
MouseArea {
91+
anchors.fill: parent
92+
onClicked: {
93+
chart.chartData.datasets[0].data = myWindow.generateData();
94+
chart.animateToNewData();
95+
}
96+
}
97+
98+
Text {
99+
anchors.horizontalCenter: parent.horizontalCenter
100+
anchors.verticalCenter: parent.verticalCenter
101+
text: "Randomize data"
102+
}
103+
}
104+
}

main.qml

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*!
2+
* Elypson's Chart.qml adaptor to Chart.js
3+
* (c) 2020 ChartJs2QML contributors (starting with Elypson, Michael A. Voelkel, https://github.com/Elypson)
4+
* Released under the MIT License
5+
*/
6+
17
import QtQuick 2.0
28
import QtQuick.Window 2.0
39
import "Chart.bundle.js" as Chart
@@ -17,8 +23,6 @@ Window
1723
anchors.fill: parent
1824

1925
Chart {
20-
21-
2226
chartType: 'scatter'
2327
chartData: {
2428
return {

0 commit comments

Comments
 (0)