Skip to content

Commit 4262b35

Browse files
author
Jelte Lagendijk
committed
Update to MX 5.21.2 (testing) and fix #66, add On Click Dataset & DataPoint Microflow
1 parent 2ef163f commit 4262b35

File tree

17 files changed

+99
-25
lines changed

17 files changed

+99
-25
lines changed

src/ChartJS/widgets/BarChart/BarChart.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,18 @@
187187
<description>Microflow to invoke when chart canvas is clicked</description>
188188
<returnType type="Void"></returnType>
189189
</property>
190+
<property key="onclickDataSetMf" type="microflow" required="false" entityProperty="datasetentity">
191+
<caption>On Click Dataset Microflow</caption>
192+
<category>Behavior</category>
193+
<description>Microflow to invoke when chart canvas is clicked. This Microflow will pass the Dataset object 'Data set entity'</description>
194+
<returnType type="Void"></returnType>
195+
</property>
196+
<property key="onclickDataPointMf" type="microflow" required="false" entityProperty="datapointentity">
197+
<caption>On Click Datapoint Microflow</caption>
198+
<category>Behavior</category>
199+
<description>Microflow to invoke when chart canvas is clicked. This Microflow will pass the Datapoint object 'Data point entity'</description>
200+
<returnType type="Void"></returnType>
201+
</property>
190202
<!-- Settings -->
191203
<property key="responsive" type="boolean" required="true" defaultValue="true">
192204
<caption>Responsive</caption>

src/ChartJS/widgets/BarChart/widget/BarChart.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,7 @@ define([
182182
// Add class to determain chart type
183183
this._addChartClass("chartjs-bar-chart");
184184

185-
if (this.onclickmf) {
186-
on(this._chart.chart.canvas, "click", lang.hitch(this, this._onClickChart));
187-
}
185+
on(this._chart.chart.canvas, "click", lang.hitch(this, this._onClickChart));
188186
}
189187
}
190188
});

src/ChartJS/widgets/Core.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ define([
7676

7777
var domNode = null;
7878

79-
// Activate chartJS (and clone it).
79+
// Activate chartJS (and clone it, making sure globals are not overwritten for other instances).
8080
this._chartJS = lang.clone(_charts);
8181

8282
// Fonts
@@ -313,8 +313,31 @@ define([
313313
console.error("_createChart: This is placeholder function that should be overwritten by the implementing widget.", data);
314314
},
315315

316-
_onClickChart: function () {
316+
_onClickChart: function (evt) {
317317
logger.debug(this.id + "._onClickChart");
318+
319+
var elements = this._chart.getElementAtEvent(evt);
320+
321+
if (elements.length) {
322+
var el = elements[0],
323+
datasetIndex = el._datasetIndex,
324+
pointIndex = el._index,
325+
dataset = this._data.datasets[datasetIndex],
326+
datasetObject = dataset ? dataset.dataset : null,
327+
dataPointObject = dataset && dataset.points ? dataset.points[pointIndex] : null;
328+
329+
if (this.onclickDataSetMf && datasetObject) {
330+
this._executeMicroflow(this.onclickDataSetMf, null, datasetObject);
331+
}
332+
333+
if (this.onclickDataPointMf && dataPointObject) {
334+
this._executeMicroflow(this.onclickDataPointMf, null, dataPointObject);
335+
}
336+
337+
console.log(JSON.stringify(datasetObject.jsonData));
338+
console.log(JSON.stringify(dataPointObject.jsonData));
339+
}
340+
318341
if (this.onclickmf) {
319342
this._executeMicroflow(this.onclickmf);
320343
}
@@ -569,7 +592,7 @@ define([
569592
caller: this.mxform
570593
},
571594
callback: lang.hitch(this, function (obj) {
572-
if (typeof callback !== "undefined") {
595+
if (typeof callback === "function") {
573596
callback(obj);
574597
}
575598
}),

src/ChartJS/widgets/DoughnutChart/DoughnutChart.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@
150150
<description>Microflow to invoke when chart canvas is clicked</description>
151151
<returnType type="Void"></returnType>
152152
</property>
153+
<property key="onclickDataSetMf" type="microflow" required="false" entityProperty="datasetentity">
154+
<caption>On Click Dataset Microflow</caption>
155+
<category>Behavior</category>
156+
<description>Microflow to invoke when chart canvas is clicked. This Microflow will pass the Dataset object 'Data set entity'</description>
157+
<returnType type="Void"></returnType>
158+
</property>
153159
<!-- Settings -->
154160
<property key="responsive" type="boolean" required="true" defaultValue="true">
155161
<caption>Responsive</caption>

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,7 @@ define([
137137
// Add class to determain chart type
138138
this._addChartClass("chartjs-doughnut-chart");
139139

140-
if (this.onclickmf) {
141-
on(this._chart.chart.canvas, "click", lang.hitch(this, this._onClickChart));
142-
}
143-
140+
on(this._chart.chart.canvas, "click", lang.hitch(this, this._onClickChart));
144141
}
145142
});
146143
});

src/ChartJS/widgets/LineChart/LineChart.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,18 @@
204204
<description>Microflow to invoke when chart canvas is clicked</description>
205205
<returnType type="Void"></returnType>
206206
</property>
207+
<property key="onclickDataSetMf" type="microflow" required="false" entityProperty="datasetentity">
208+
<caption>On Click Dataset Microflow</caption>
209+
<category>Behavior</category>
210+
<description>Microflow to invoke when chart canvas is clicked. This Microflow will pass the Dataset object 'Data set entity'</description>
211+
<returnType type="Void"></returnType>
212+
</property>
213+
<property key="onclickDataPointMf" type="microflow" required="false" entityProperty="datapointentity">
214+
<caption>On Click Datapoint Microflow</caption>
215+
<category>Behavior</category>
216+
<description>Microflow to invoke when chart canvas is clicked. This Microflow will pass the Datapoint object 'Data point entity'</description>
217+
<returnType type="Void"></returnType>
218+
</property>
207219
<!-- Settings -->
208220
<property key="responsive" type="boolean" required="true" defaultValue="true">
209221
<caption>Responsive</caption>

src/ChartJS/widgets/LineChart/widget/LineChart.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,7 @@ define([
222222
// Add class to determain chart type
223223
this._addChartClass("chartjs-line-chart");
224224

225-
if (this.onclickmf) {
226-
on(this._chart.chart.canvas, "click", lang.hitch(this, this._onClickChart));
227-
}
225+
on(this._chart.chart.canvas, "click", lang.hitch(this, this._onClickChart));
228226
}
229227
}
230228

src/ChartJS/widgets/PieChart/PieChart.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@
152152
<description>Microflow to invoke when chart canvas is clicked</description>
153153
<returnType type="Void"></returnType>
154154
</property>
155+
<property key="onclickDataSetMf" type="microflow" required="false" entityProperty="datasetentity">
156+
<caption>On Click Dataset Microflow</caption>
157+
<category>Behavior</category>
158+
<description>Microflow to invoke when chart canvas is clicked. This Microflow will pass the Dataset object 'Data set entity'</description>
159+
<returnType type="Void"></returnType>
160+
</property>
155161
<!-- Settings -->
156162
<property key="responsive" type="boolean" required="true" defaultValue="true">
157163
<caption>Responsive</caption>

src/ChartJS/widgets/PieChart/widget/PieChart.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,7 @@ define([
140140
// Add class to determain chart type
141141
this._addChartClass("chartjs-pie-chart");
142142

143-
if (this.onclickmf) {
144-
on(this._chart.chart.canvas, "click", lang.hitch(this, this._onClickChart));
145-
}
143+
on(this._chart.chart.canvas, "click", lang.hitch(this, this._onClickChart));
146144
}
147145
}
148146
});

src/ChartJS/widgets/PolarChart/PolarChart.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@
148148
<description></description>
149149
<returnType type="Void"></returnType>
150150
</property>
151+
<property key="onclickDataSetMf" type="microflow" required="false" entityProperty="datasetentity">
152+
<caption>On Click Dataset Microflow</caption>
153+
<category>Behavior</category>
154+
<description>Microflow to invoke when chart canvas is clicked. This Microflow will pass the Dataset object 'Data set entity'</description>
155+
<returnType type="Void"></returnType>
156+
</property>
151157
<!-- Settings -->
152158
<property key="responsive" type="boolean" required="true" defaultValue="true">
153159
<caption>Responsive</caption>

0 commit comments

Comments
 (0)