| @@ -46,10 +46,9 @@ | ||
| 46 | 46 | case 'column': |
| 47 | 47 | type = 'bar'; |
| 48 | 48 | break; |
| 49 | 49 | case 'bar': |
| 50 | - type = 'bar'; | |
| 51 | - settings.indexAxis = 'y'; | |
| 50 | + type = 'horizontalBar'; | |
| 52 | 51 | break; |
| 53 | 52 | case 'pie': |
| 54 | 53 | // donut is not a setting but a separate chart type. |
| 55 | 54 | if(typeof settings['custom'] !== 'undefined' && settings['custom']['donut'] === 'true'){ |
| @@ -64,9 +63,9 @@ | ||
| 64 | 63 | |
| 65 | 64 | for (i = 0; i < data.length; i++) { |
| 66 | 65 | row = []; |
| 67 | 66 | for (j = 0; j < series.length; j++) { |
| 68 | - if (series[j].type === 'date' || series[j].type === 'datetime') { | |
| 67 | + if (series[j].type === 'date' || series[j].type === 'datetime') { | |
| 69 | 68 | date = new Date(data[i][j]); |
| 70 | 69 | data[i][j] = null; |
| 71 | 70 | if (Object.prototype.toString.call(date) === "[object Date]") { |
| 72 | 71 | if (!isNaN(date.getTime())) { |
| @@ -112,43 +111,8 @@ | ||
| 112 | 111 | } |
| 113 | 112 | |
| 114 | 113 | handleSettings(settings, chart); |
| 115 | 114 | |
| 116 | - const getChart = Chart.getChart(context); | |
| 117 | - if ( getChart ) { | |
| 118 | - return; | |
| 119 | - } | |
| 120 | - | |
| 121 | - // Format series label. | |
| 122 | - settings.plugins.tooltip = { | |
| 123 | - callbacks: { | |
| 124 | - label: function(context) { | |
| 125 | - var label = ''; | |
| 126 | - if ( 'object' === typeof context.dataset.label ) { | |
| 127 | - label = context.label || ''; | |
| 128 | - } else { | |
| 129 | - label = context.dataset.label || ''; | |
| 130 | - } | |
| 131 | - if ( label ) { | |
| 132 | - label += ': '; | |
| 133 | - } | |
| 134 | - var format = context.dataset.format || ''; | |
| 135 | - if ( format ) { | |
| 136 | - var lastSuffix = numeral(context.formattedValue).format(format).replace(/[0-9]/g, ''); | |
| 137 | - label += context.formattedValue + lastSuffix; | |
| 138 | - } else { | |
| 139 | - format = 'undefined' !== typeof context.chart.config._config.options.format ? context.chart.config._config.options.format : ''; | |
| 140 | - if ( format ) { | |
| 141 | - label += format_datum( context.formattedValue, format ); | |
| 142 | - } else { | |
| 143 | - label += context.formattedValue; | |
| 144 | - } | |
| 145 | - } | |
| 146 | - return label; | |
| 147 | - } | |
| 148 | - } | |
| 149 | - }; | |
| 150 | - | |
| 151 | 115 | var chartjs = new Chart(context, { |
| 152 | 116 | type: type, |
| 153 | 117 | data: { |
| 154 | 118 | labels: labels, |
| @@ -153,17 +117,9 @@ | ||
| 153 | 117 | data: { |
| 154 | 118 | labels: labels, |
| 155 | 119 | datasets: datasets |
| 156 | 120 | }, |
| 157 | - options: settings, | |
| 158 | - plugins: [{ | |
| 159 | - afterRender: function () { | |
| 160 | - var canvas = $( 'canvas' )[0]; | |
| 161 | - if ( $( '#chart-img' ).length ) { | |
| 162 | - $( '#chart-img' ).val( canvas.toDataURL() ); | |
| 163 | - } | |
| 164 | - } | |
| 165 | - }], | |
| 121 | + options: settings | |
| 166 | 122 | }); |
| 167 | 123 | |
| 168 | 124 | // this line needs to be included twice. This is not an error. |
| 169 | 125 | $.extend(settings, { responsive: true, maintainAspectRatio: false }); |
| @@ -208,14 +164,14 @@ | ||
| 208 | 164 | settings['tooltip']['intersect'] = settings['tooltip']['intersect'] == true || parseInt(settings['tooltip']['intersect']) === 1; // jshint ignore:line |
| 209 | 165 | } |
| 210 | 166 | |
| 211 | 167 | if(typeof settings['fontName'] !== 'undefined' && settings['fontName'] !== ''){ |
| 212 | - Chart.defaults.font.family = settings['fontName']; | |
| 168 | + Chart.defaults.global.defaultFontFamily = settings['fontName']; | |
| 213 | 169 | delete settings['fontName']; |
| 214 | 170 | } |
| 215 | 171 | |
| 216 | 172 | if(typeof settings['fontSize'] !== 'undefined' && settings['fontSize'] !== ''){ |
| 217 | - Chart.defaults.font.size = parseInt(settings['fontSize']); | |
| 173 | + Chart.defaults.global.defaultFontSize = settings['fontSize']; | |
| 218 | 174 | delete settings['fontSize']; |
| 219 | 175 | } |
| 220 | 176 | |
| 221 | 177 | // handle legend defaults. |
| @@ -226,12 +182,8 @@ | ||
| 226 | 182 | } |
| 227 | 183 | } |
| 228 | 184 | } |
| 229 | 185 | |
| 230 | - settings.plugins = { | |
| 231 | - legend: settings.legend, | |
| 232 | - }; | |
| 233 | - | |
| 234 | 186 | handleAxes(settings, chart); |
| 235 | 187 | |
| 236 | 188 | override(settings, chart); |
| 237 | 189 | } |
| @@ -239,27 +191,13 @@ | ||
| 239 | 191 | function handleAxes(settings, chart){ |
| 240 | 192 | if(typeof settings['yAxes'] !== 'undefined' && typeof settings['xAxes'] !== 'undefined'){ |
| 241 | 193 | // stacking has to be defined on both axes. |
| 242 | 194 | if(typeof settings['yAxes']['stacked_bool'] !== 'undefined'){ |
| 243 | - settings['yAxes']['stacked_bool'] = 'true'; | |
| 195 | + settings['xAxes']['stacked_bool'] = 'true'; | |
| 244 | 196 | } |
| 245 | 197 | if(typeof settings['xAxes']['stacked_bool'] !== 'undefined'){ |
| 246 | - settings['xAxes']['stacked_bool'] = 'true'; | |
| 198 | + settings['yAxes']['stacked_bool'] = 'true'; | |
| 247 | 199 | } |
| 248 | - // Bar percentage. | |
| 249 | - if (typeof settings['yAxes']['barPercentage_int'] !=='undefined' && ''!== settings['yAxes']['barPercentage_int']){ | |
| 250 | - settings['barPercentage'] = settings['yAxes']['barPercentage_int']; | |
| 251 | - } | |
| 252 | - if (typeof settings['xAxes']['barPercentage_int'] !=='undefined' && ''!== settings['xAxes']['barPercentage_int']){ | |
| 253 | - settings['barPercentage'] = settings['xAxes']['barPercentage_int']; | |
| 254 | - } | |
| 255 | - // Bar thickness. | |
| 256 | - if (typeof settings['yAxes']['barThickness'] !=='undefined' && ''!== settings['yAxes']['barThickness']){ | |
| 257 | - settings['barThickness'] = settings['yAxes']['barThickness']; | |
| 258 | - } | |
| 259 | - if (typeof settings['xAxes']['barThickness'] !=='undefined' && ''!== settings['xAxes']['barThickness']){ | |
| 260 | - settings['barThickness'] = settings['xAxes']['barThickness']; | |
| 261 | - } | |
| 262 | 200 | } |
| 263 | 201 | configureAxes(settings, 'yAxes', chart); |
| 264 | 202 | configureAxes(settings, 'xAxes', chart); |
| 265 | 203 | } |
| @@ -328,56 +266,8 @@ | ||
| 328 | 266 | } |
| 329 | 267 | var $axis = $scales['scales'][axis]; |
| 330 | 268 | |
| 331 | 269 | $axis.push($features); |
| 332 | - // Migrate xAxes settings to v3.0+ | |
| 333 | - if ( $scales.scales && $scales.scales.xAxes ) { | |
| 334 | - for (var x in $scales.scales.xAxes) { | |
| 335 | - $scales.scales.x = { | |
| 336 | - display: $scales.scales.xAxes[x].scaleLabel.display, | |
| 337 | - title: { | |
| 338 | - display:true, | |
| 339 | - text: $scales.scales.xAxes[x].scaleLabel.labelString, | |
| 340 | - color: $scales.scales.xAxes[x].scaleLabel.fontColor, | |
| 341 | - font: { | |
| 342 | - family: $scales.scales.xAxes[x].scaleLabel.fontFamily, | |
| 343 | - size: $scales.scales.xAxes[x].scaleLabel.fontSize | |
| 344 | - } | |
| 345 | - }, | |
| 346 | - suggestedMax: $scales.scales.xAxes[x].ticks.suggestedMax || '', | |
| 347 | - suggestedMin: $scales.scales.xAxes[x].ticks.suggestedMin || '', | |
| 348 | - ticks: { | |
| 349 | - maxTicksLimit: $scales.scales.xAxes[x].ticks.maxTicksLimit | |
| 350 | - }, | |
| 351 | - stacked: $scales.scales.xAxes[x].stacked || false | |
| 352 | - } | |
| 353 | - } | |
| 354 | - delete $scales.scales.xAxes; | |
| 355 | - } | |
| 356 | - // Migrate yAxes settings to v3.0+ | |
| 357 | - if ( $scales.scales && $scales.scales.yAxes ) { | |
| 358 | - for (var y in $scales.scales.yAxes) { | |
| 359 | - $scales.scales.y = { | |
| 360 | - display: $scales.scales.yAxes[y].scaleLabel.display, | |
| 361 | - title: { | |
| 362 | - display:true, | |
| 363 | - text: $scales.scales.yAxes[y].scaleLabel.labelString, | |
| 364 | - color: $scales.scales.yAxes[y].scaleLabel.fontColor, | |
| 365 | - font: { | |
| 366 | - family: $scales.scales.yAxes[y].scaleLabel.fontFamily, | |
| 367 | - size: $scales.scales.yAxes[y].scaleLabel.fontSize | |
| 368 | - } | |
| 369 | - }, | |
| 370 | - suggestedMax: $scales.scales.yAxes[y].ticks.suggestedMax || '', | |
| 371 | - suggestedMin: $scales.scales.yAxes[y].ticks.suggestedMin || '', | |
| 372 | - ticks: { | |
| 373 | - maxTicksLimit: $scales.scales.yAxes[y].ticks.maxTicksLimit | |
| 374 | - }, | |
| 375 | - stacked: $scales.scales.yAxes[y].stacked || false | |
| 376 | - } | |
| 377 | - } | |
| 378 | - delete $scales.scales.yAxes; | |
| 379 | - } | |
| 380 | 270 | $.extend(settings, $scales); |
| 381 | 271 | |
| 382 | 272 | // to prevent duplication, indicates that the axis has been set. |
| 383 | 273 | var $custom = {}; |
| @@ -387,24 +277,21 @@ | ||
| 387 | 277 | |
| 388 | 278 | // format the axes labels. |
| 389 | 279 | if(typeof settings[axis + '_format'] !== 'undefined' && settings[axis + '_format'] !== ''){ |
| 390 | 280 | var format = settings[axis + '_format']; |
| 391 | - var isDateFormat = moment( moment().format( format ),format, true ).isValid(); | |
| 392 | - if ( ! isDateFormat ) { | |
| 393 | - switch(axis){ | |
| 394 | - case 'xAxes': | |
| 395 | - settings.scales.x.ticks.callback = function(value, index, values){ | |
| 396 | - return format_datum(value, format); | |
| 397 | - }; | |
| 398 | - break; | |
| 399 | - case 'yAxes': | |
| 400 | - settings.scales.y.ticks.callback = function(value, index, values){ | |
| 401 | - return format_datum(value, format); | |
| 402 | - }; | |
| 403 | - break; | |
| 404 | - } | |
| 405 | - delete settings[axis + '_format']; | |
| 406 | - } | |
| 281 | + switch(axis){ | |
| 282 | + case 'xAxes': | |
| 283 | + settings.scales.xAxes[0].ticks.callback = function(value, index, values){ | |
| 284 | + return format_datum(value, format); | |
| 285 | + }; | |
| 286 | + break; | |
| 287 | + case 'yAxes': | |
| 288 | + settings.scales.yAxes[0].ticks.callback = function(value, index, values){ | |
| 289 | + return format_datum(value, format); | |
| 290 | + }; | |
| 291 | + break; | |
| 292 | + } | |
| 293 | + delete settings[axis + '_format']; | |
| 407 | 294 | } |
| 408 | 295 | delete settings[axis]; |
| 409 | 296 | } |
| 410 | 297 | |
| @@ -441,11 +328,8 @@ | ||
| 441 | 328 | return; |
| 442 | 329 | } |
| 443 | 330 | for(var i in settings.series[j]){ |
| 444 | 331 | var $attribute = {}; |
| 445 | - if ( settings.series[j].backgroundColor == '' ) { | |
| 446 | - delete settings.series[j].backgroundColor; | |
| 447 | - } | |
| 448 | 332 | $attribute[i] = settings.series[j][i]; |
| 449 | 333 | $.extend($attributes, $attribute); |
| 450 | 334 | } |
| 451 | 335 | } |
| @@ -467,9 +351,9 @@ | ||
| 467 | 351 | |
| 468 | 352 | switch(type) { |
| 469 | 353 | case 'number': |
| 470 | 354 | // numeral.js works on 0 instead of # so we just replace that in the ICU pattern set. |
| 471 | - format = format.replace(/#/g, '0').replace(/%/g, ''); | |
| 355 | + format = format.replace(/#/g, '0'); | |
| 472 | 356 | // we also replace all instance of '$' as that is more relevant for ticks. |
| 473 | 357 | if(removeDollar){ |
| 474 | 358 | format = format.replace(/\$/g, ''); |
| 475 | 359 | } |
| @@ -486,13 +370,8 @@ | ||
| 486 | 370 | |
| 487 | 371 | function format_data(datum, j, settings, series){ |
| 488 | 372 | j = j - 1; |
| 489 | 373 | var format = typeof settings.series !== 'undefined' && typeof settings.series[j] !== 'undefined' ? settings.series[j].format : ''; |
| 490 | - if ( '' === format && typeof settings.yAxes_format !== 'undefined' ) { | |
| 491 | - format = settings.yAxes_format; | |
| 492 | - } else if ( '' === format && typeof settings.xAxes_format !== 'undefined' ) { | |
| 493 | - format = settings.xAxes_format; | |
| 494 | - } | |
| 495 | 374 | return format_datum(datum, format, series[j + 1].type); |
| 496 | 375 | } |
| 497 | 376 | |
| 498 | 377 | function override(settings, chart) { |