Skip to content

Commit 43ff5d5

Browse files
author
Jelte Lagendijk
committed
Fix #78 On click microflows for Pie, Doughnut and Polar charts
1 parent e6d8c2b commit 43ff5d5

File tree

10 files changed

+34
-15
lines changed

10 files changed

+34
-15
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ define([
88

99
return declare("ChartJS.widgets.BarChart.widget.BarChart", [ Core ], {
1010

11+
_chartType: "bar",
12+
1113
_processData : function () {
1214
logger.debug(this.id + "._processData");
1315
var sets = [],
@@ -101,7 +103,7 @@ define([
101103
this._chart.bindEvents(); // tooltips otherwise won't work
102104
} else {
103105
var chartProperties = {
104-
type: "bar",
106+
type: this._chartType,
105107
data: data,
106108
options: this._chartOptions({
107109

src/ChartJS/widgets/Core.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ define([
6767
_mxObj: null,
6868
_handle: null,
6969

70+
_chartType: null,
71+
7072
_resizeTimer: null,
7173

7274
_currentContext: null,
@@ -319,9 +321,7 @@ define([
319321

320322
_onClickChart: function (evt) {
321323
logger.debug(this.id + "._onClickChart");
322-
323324
var elements = this._chart.getElementAtEvent(evt);
324-
325325
if (elements.length) {
326326
var el = elements[0],
327327
datasetIndex = el._datasetIndex,
@@ -331,6 +331,11 @@ define([
331331
dataPointObject = dataset && dataset.points ? dataset.points[pointIndex] : null;
332332

333333
if (this.onclickDataSetMf && datasetObject) {
334+
if (this._chartType === "pie" || this._chartType === "doughnut" || this._chartType === "polarArea") {
335+
// These chartTypes use a single series data set, so the datasetobject is different
336+
datasetObject = this._activeDatasets[pointIndex].obj;
337+
}
338+
334339
this._executeMicroflow(this.onclickDataSetMf, null, datasetObject);
335340
}
336341

@@ -431,7 +436,7 @@ define([
431436
},
432437

433438
_createDataSets: function (data) {
434-
logger.debug(this.id + "._createDataSets", data);
439+
logger.debug(this.id + "._createDataSets");
435440
var _chartData = {
436441
labels: [],
437442
datasets: [
@@ -516,7 +521,7 @@ define([
516521
},
517522

518523
_hexToRgb: function (hex, alpha) {
519-
logger.debug(this.id + "._hexToRgb", hex, alpha);
524+
//logger.debug(this.id + "._hexToRgb", hex, alpha);
520525
if (hex !== null) {
521526
var regex = null,
522527
shorthandRegex = null,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ define([
1010

1111
return declare("ChartJS.widgets.DoughnutChart.widget.DoughnutChart", [ Core ], {
1212

13+
_chartType: "doughnut",
14+
1315
_processData : function () {
1416
logger.debug(this.id + "._processData");
1517
var sets = [],
@@ -46,6 +48,7 @@ define([
4648

4749
chartData.push(point);
4850
this._activeDatasets.push({
51+
obj: set.dataset,
4952
dataset : point,
5053
idx : j,
5154
active : true
@@ -95,7 +98,7 @@ define([
9598
this._chart.destroy();
9699
}
97100
this._chart = new this._chartJS(this._ctx, {
98-
type: "doughnut",
101+
type: this._chartType,
99102
data: this._createDataSets(data),
100103
options: this._chartOptions({
101104

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ define([
99

1010
return declare("ChartJS.widgets.LineChart.widget.LineChart", [ Core ], {
1111

12-
// Overwrite functions from _core here...
12+
_chartType: "line",
1313

1414
_processData : function () {
1515
logger.debug(this.id + "._processData");
@@ -100,8 +100,8 @@ define([
100100
}
101101
this._chartData.labels = xlabels;
102102

103-
logger.debug(this.id + " Created LineChart data");
104-
logger.debug(this.id + " " + JSON.stringify(this._chartData));
103+
//logger.debug(this.id + " Created LineChart data");
104+
//logger.debug(this.id + " " + JSON.stringify(this._chartData));
105105

106106
this._createChart(this._chartData);
107107

@@ -121,7 +121,7 @@ define([
121121
//logger.debug("stacked:" + this.isStacked);
122122

123123
var chartProperties = {
124-
type: "line",
124+
type: this._chartType,
125125
data: data,
126126
options: this._chartOptions({
127127

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ define([
1111

1212
return declare("ChartJS.widgets.PieChart.widget.PieChart", [ Core ], {
1313

14+
_chartType: "pie",
15+
1416
_processData : function () {
1517
logger.debug(this.id + "._processData");
1618
var sets = [],
@@ -46,14 +48,14 @@ define([
4648

4749
chartData.push(point);
4850
this._activeDatasets.push({
51+
obj: set.dataset,
4952
dataset : point,
5053
idx : j,
5154
active : true
5255
});
5356
}
5457

5558
this._createChart(chartData);
56-
5759
this._createLegend(true);
5860
},
5961

@@ -100,7 +102,7 @@ define([
100102
this._chart.bindEvents(); // tooltips otherwise won't work
101103
} else {
102104
var chartProperties = {
103-
type: "pie",
105+
type: this._chartType,
104106
data: this._createDataSets(data),
105107
options: this._chartOptions({
106108

src/ChartJS/widgets/PolarChart/widget/PolarChart.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ define([
1111
// Declare widget.
1212
return declare("ChartJS.widgets.PolarChart.widget.PolarChart", [ _core ], {
1313

14+
_chartType: "polarArea",
15+
1416
_processData : function () {
1517
logger.debug(this.id + "._processData");
1618
var sets = [],
@@ -46,6 +48,7 @@ define([
4648

4749
chartData.push(point);
4850
this._activeDatasets.push({
51+
obj: set.dataset,
4952
dataset : point,
5053
idx : j,
5154
active : true
@@ -94,7 +97,7 @@ define([
9497
logger.debug(this.id + "._createChart");
9598

9699
this._chart = new this._chartJS(this._ctx, {
97-
type: "polarArea",
100+
type: this._chartType,
98101
data: this._createDataSets(data),
99102
options: {
100103
title: {

src/ChartJS/widgets/RadarChart/widget/RadarChart.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ define([
99

1010
return declare("ChartJS.widgets.RadarChart.widget.RadarChart", [ Core ], {
1111

12+
_chartType: "radar",
13+
1214
_processData : function () {
1315
logger.debug(this.id + "._processData");
1416
var sets = [],
@@ -105,7 +107,7 @@ define([
105107
} else {
106108

107109
this._chart = new this._chartJS(this._ctx, {
108-
type: "radar",
110+
type: this._chartType,
109111
data: data,
110112
options: this._chartOptions({
111113

src/ChartJS/widgets/StackedBarChart/widget/StackedBarChart.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ define([
99

1010
return declare("ChartJS.widgets.StackedBarChart.widget.StackedBarChart", [ Core ], {
1111

12+
_chartType: "bar",
13+
1214
_processData : function () {
1315
logger.debug(this.id + "._processData");
1416
var sets = [],
@@ -104,7 +106,7 @@ define([
104106
} else {
105107

106108
var chartProperties = {
107-
type: "bar",
109+
type: this._chartType,
108110
data: data,
109111
options: this._chartOptions({
110112

test/[Test] ChartJS.mpr

0 Bytes
Binary file not shown.

test/widgets/ChartJS.mpk

235 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)