Skip to content

Commit ebcc3e2

Browse files
author
Mostafa Kamal
committed
new flag
Co-Authored-By: Mostafa Kamal <radionishi@gmail.com>
1 parent 0c03134 commit ebcc3e2

2 files changed

Lines changed: 78 additions & 11 deletions

File tree

dist/setup.js

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,88 @@
33
module.exports = function setup(chartEl) {
44
/* import chart js */
55
var Chart = require('chart.js');
6+
7+
/* https://twitter.com/0devco */
8+
69
/* chartEl data access by variable */
710
var datasetsArray = [];
811
for (var i = 0; i < chartEl.multiple; i++) {
912
var dataSet = {
1013
label: chartEl.label[i],
11-
fill: chartEl.fill[i],
1214
data: chartEl.data[i],
13-
borderDash: [chartEl.bdrDash[i]],
1415
backgroundColor: chartEl.bgColor[i],
1516
borderColor: chartEl.bdrColor[i],
16-
borderWidth: chartEl.bdrWidth[i]
1717
};
1818
datasetsArray.push(dataSet);
1919
}
20+
datasetsArray.forEach((d, index) => {
21+
/* fill flag */
22+
if (chartEl.fill !== undefined) {
23+
d['fill'] = (chartEl.fill[index] !== undefined) ? chartEl.fill[index] : true
24+
}
25+
/* border dash */
26+
if (chartEl.bdrDash !== undefined) {
27+
d['borderDash'] = (chartEl.bdrDash[index] !== undefined) ? [chartEl.bdrDash[index]] : [0]
28+
}
29+
/* border width */
30+
if (chartEl.bdrWidth !== undefined) {
31+
d['borderWidth'] = (chartEl.bdrWidth[index] !== undefined) ? chartEl.bdrWidth[index] : 1
32+
}
33+
/* tension (curve style)*/
34+
if (chartEl.tension !== undefined) {
35+
d['tension'] = (chartEl.tension[index] !== undefined) ? chartEl.tension[index] : 0.4
36+
}
37+
/* line step style */
38+
if (chartEl.stepLine !== undefined) {
39+
d['steppedLine'] = (chartEl.stepLine[index] !== undefined) ? chartEl.stepLine[index] : false
40+
}
41+
42+
43+
/* pointBackgroundColor */
44+
if (chartEl.pointBg !== undefined) {
45+
d['pointBackgroundColor'] = (chartEl.pointBg[index] !== undefined) ? chartEl.pointBg[index] : chartEl.pointBg[0]
46+
}
47+
/* pointRadius */
48+
49+
if (chartEl.pointRd !== undefined) {
50+
d['pointRadius'] = (chartEl.pointRd[index] !== undefined) ? chartEl.pointRd[index] : chartEl.pointRd[0]
51+
}
52+
/* pointBorderWidth */
53+
if (chartEl.pointBdrWd !== undefined) {
54+
d['pointBorderWidth'] = (chartEl.pointBdrWd[index] !== undefined) ? chartEl.pointBdrWd[index] : chartEl.pointBdrWd[0]
55+
}
56+
if (chartEl.pointBdrColor !== undefined) {
57+
d['pointBorderColor'] = (chartEl.pointBdrColor[index] !== undefined) ? chartEl.pointBdrColor[index] : chartEl.pointBdrColor[0]
58+
}
59+
/* point hover radius */
60+
if (chartEl.pointHvRd !== undefined) {
61+
d['pointHoverRadius'] = (chartEl.pointHvRd[index] !== undefined) ? chartEl.pointHvRd[index] : chartEl.pointHvRd[0]
62+
}
63+
/* pointHoverBackgroundColor */
64+
if (chartEl.pointHvBg !== undefined) {
65+
d['pointHoverBackgroundColor'] = (chartEl.pointHvBg[index] !== undefined) ? chartEl.pointHvBg[index] : chartEl.pointHvBg[0]
66+
}
67+
/* pointHoverBorderColor */
68+
if (chartEl.pointHvBdrColor !== undefined) {
69+
d['pointHoverBorderColor'] = (chartEl.pointHvBdrColor[index] !== undefined) ? chartEl.pointHvBdrColor[index] : chartEl.pointHvBdrColor[0]
70+
}
71+
/* point style */
72+
if (chartEl.pointStyle !== undefined) {
73+
d['pointStyle'] = (chartEl.pointStyle[index] !== undefined) ? chartEl.pointStyle[index] : chartEl.pointStyle[0]
74+
}
75+
})
2076
var is_animated = chartEl.animated === false ? 0 : 1500;
2177
var is_title = chartEl.title ? true : false;
2278
var is_legend = chartEl.legend === false ? false : true;
2379
var is_drawOnChartArea = chartEl.drawOnChartArea === false ? false : true;
2480
var is_tooltips = chartEl.tooltips === false ? false : true;
81+
var is_hover = chartEl.tooltips === false ? 'null' : 'point';
2582
var is_BeginZeroY = chartEl.beginZeroY === true ? true : false;
2683
var is_BeginZeroX = chartEl.beginZeroX === true ? true : false;
2784
var is_hideX = chartEl.hideX === true ? false : true;
2885
var is_hideY = chartEl.hideY === true ? false : true;
2986

87+
3088
/* create chart */
3189
var chartID = document.getElementById(chartEl.id);
3290
var ctx = chartID.getContext("2d");
@@ -49,7 +107,11 @@ module.exports = function setup(chartEl) {
49107
text: chartEl.title
50108
},
51109
tooltips: {
52-
enabled: is_tooltips
110+
enabled: is_tooltips,
111+
// backgroundColor: 'red'
112+
},
113+
hover: {
114+
mode: is_hover
53115
},
54116
animation: {
55117
duration: is_animated
@@ -58,20 +120,22 @@ module.exports = function setup(chartEl) {
58120
xAxes: [{
59121
stacked: chartEl.stackX || false,
60122
gridLines: {
61-
display: true,
123+
display: is_hideX,
62124
drawBorder: is_hideX,
63125
drawOnChartArea: is_drawOnChartArea,
64126
position: 'bottom'
65127
},
66128
ticks: {
67129
beginAtZero: is_BeginZeroX,
68-
display: is_hideX
130+
display: is_hideX,
131+
fontSize: 30,
132+
fontColor: 'red'
69133
}
70134
}],
71135
yAxes: [{
72136
stacked: chartEl.stackY || false,
73137
gridLines: {
74-
display: true,
138+
display: is_hideY,
75139
drawBorder: is_hideY,
76140
drawOnChartArea: is_drawOnChartArea,
77141
position: 'left'
@@ -84,4 +148,4 @@ module.exports = function setup(chartEl) {
84148
}
85149
}
86150
});
87-
};
151+
};

docs/readme.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@ id: 'canvas_id',
3838
type: 'chart_type',
3939
multiple: 2 /* multi chart n */
4040
labels: array
41-
fill: multi array according (multiple n) ex => [true,false]
4241
label: multi array according (multiple n)
4342
data: multi array according (multiple n)
4443
bgColor: multi array according (multiple n)
4544
bdrColor: multi array according (multiple n)
46-
bdrDash: [0,0] multi array according (multiple n)
4745
```
4846

4947
# extra rules
@@ -60,7 +58,12 @@ beginZeroY: true,
6058
hideX: true,
6159
hideY: true,
6260
stackX: true,
63-
stackY: true
61+
stackY: true,
62+
bdrDash: [0,0] multi array according (multiple n),
63+
fill: multi array according (multiple n) ex => [true,false],
64+
bdrWidth: multi array according (multiple n)
65+
tension: multi array according (multiple n) => ex = [false,0.4] => 0.4 means true
66+
stepLine: multi array according (multiple n) => ex = [true,false]
6467
```
6568

6669

0 commit comments

Comments
 (0)