Skip to content

Commit b18deb2

Browse files
committed
implemented Base64 attribute on DonutChart
1 parent 5ecd2e0 commit b18deb2

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

src/ChartJS/widgets/Core.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,21 @@ define([
667667

668668
_animationComplete: function () {
669669
logger.debug(this.id + "._animationComplete");
670+
if(this.base64Attr) {
671+
var ctx = this.canvasNode.getContext('2d');
672+
var imgData=ctx.getImageData(0,0,this.canvasNode.width,this.canvasNode.height);
673+
var data=imgData.data;
674+
for(var i=0;i<data.length;i+=4){
675+
if(data[i+3]<255){
676+
data[i]=255;
677+
data[i+1]=255;
678+
data[i+2]=255;
679+
data[i+3]=255;
680+
}
681+
}
682+
ctx.putImageData(imgData,0,0);
683+
this._mxObj.set(this.base64Attr, this.canvasNode.toDataURL("image/jpeg"));
684+
}
670685
// Use this.canvasNode.toDataURL() to get an image
671686
}
672687

src/ChartJS/widgets/DoughnutChart/DoughnutChart.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@
205205
<description>Microflow to invoke when chart canvas is clicked. This Microflow will pass the Dataset object 'Data set entity'</description>
206206
<returnType type="Void"></returnType>
207207
</property>
208+
<property key="base64Attr" type="attribute" required="false">
209+
<caption>Base 64 Attribute</caption>
210+
<category>Behavior</category>
211+
<description>The attribute to store the base64 encoding of the chart when rendered.</description>
212+
<attributeTypes>
213+
<attributeType name="String"/>
214+
</attributeTypes>
215+
</property>
208216
<!-- Settings -->
209217
<property key="responsive" type="boolean" required="true" defaultValue="true">
210218
<caption>Responsive</caption>

src/ChartJS/widgets/DoughnutChart/widget/DoughnutChart.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ define([
140140
}));
141141

142142
// Set the con
143-
html.set(this._numberNode, this._data.object.get(this.numberInside).toString());
143+
if(this.numberInside) {
144+
html.set(this._numberNode, this._data.object.get(this.numberInside).toString());
145+
}
144146

145147
// Add class to determain chart type
146148
this._addChartClass("chartjs-doughnut-chart");

test/widgets/ChartJS.mpk

-828 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)