| 1 |
(function($) { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
function ChartBuilderGoogleCharts(element, options) { |
| 5 |
this.el = element; |
| 6 |
this.$el = $(element); |
| 7 |
this.htmlClassPrefix = 'ays-chart-'; |
| 8 |
this.htmlNamePrefix = 'ays_'; |
| 9 |
this.uniqueId; |
| 10 |
this.dbData = undefined; |
| 11 |
this.chartSourceData = undefined; |
| 12 |
this.chartObj = undefined; |
| 13 |
this.chartOptions = null; |
| 14 |
this.chartData = null; |
| 15 |
this.chartTempData = null; |
| 16 |
this.chartType = 'pie_chart'; |
| 17 |
this.chartId = null; |
| 18 |
|
| 19 |
this.chartSources = { |
| 20 |
'line_chart' : 'Line Chart', |
| 21 |
'bar_chart' : 'Bar Chart', |
| 22 |
'pie_chart' : 'Pie Chart', |
| 23 |
'column_chart' : 'Column Chart', |
| 24 |
'org_chart' : 'Org Chart', |
| 25 |
'donut_chart' : 'Donut Chart', |
| 26 |
} |
| 27 |
|
| 28 |
this.init(); |
| 29 |
|
| 30 |
return this; |
| 31 |
} |
| 32 |
|
| 33 |
ChartBuilderGoogleCharts.prototype.init = function() { |
| 34 |
var _this = this; |
| 35 |
_this.uniqueId = _this.$el.data('id'); |
| 36 |
|
| 37 |
if ( typeof window['aysChartOptions'+_this.uniqueId] != 'undefined' ) { |
| 38 |
_this.dbData = JSON.parse( atob( window['aysChartOptions'+_this.uniqueId]['aysChartOptions'] ) ); |
| 39 |
} |
| 40 |
|
| 41 |
_this.setEvents(); |
| 42 |
} |
| 43 |
|
| 44 |
ChartBuilderGoogleCharts.prototype.setEvents = function(e){ |
| 45 |
var _this = this; |
| 46 |
|
| 47 |
_this.chartId = _this.dbData.id; |
| 48 |
_this.chartType = _this.dbData.chart_type; |
| 49 |
|
| 50 |
_this.loadChartBySource(); |
| 51 |
_this.setClickEventOnExportButtons(); |
| 52 |
|
| 53 |
$(document).on('click', '.elementor-tab-title, .e-n-tab-title, .ays-load-chart-source', function (e) { |
| 54 |
_this.loadChartBySource(); |
| 55 |
}); |
| 56 |
$(document).on('change', '.ays-load-chart-source', function (e) { |
| 57 |
_this.loadChartBySource(); |
| 58 |
}); |
| 59 |
} |
| 60 |
|
| 61 |
// Load charts by given type main function |
| 62 |
ChartBuilderGoogleCharts.prototype.loadChartBySource = function(){ |
| 63 |
var _this = this; |
| 64 |
|
| 65 |
if(typeof _this.chartType !== undefined && _this.chartType){ |
| 66 |
switch (_this.chartType) { |
| 67 |
case 'pie_chart': |
| 68 |
_this.pieChartView(); |
| 69 |
break; |
| 70 |
case 'bar_chart': |
| 71 |
_this.barChartView(); |
| 72 |
break; |
| 73 |
case 'column_chart': |
| 74 |
_this.columnChartView(); |
| 75 |
break; |
| 76 |
case 'line_chart': |
| 77 |
_this.lineChartView(); |
| 78 |
break; |
| 79 |
case 'donut_chart': |
| 80 |
_this.donutChartView(); |
| 81 |
break; |
| 82 |
case 'org_chart': |
| 83 |
_this.orgChartView(); |
| 84 |
break; |
| 85 |
default: |
| 86 |
_this.pieChartView(); |
| 87 |
break; |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
// Load chart by pie chart |
| 93 |
ChartBuilderGoogleCharts.prototype.pieChartView = function(){ |
| 94 |
var _this = this; |
| 95 |
var getChartSource = _this.dbData.source; |
| 96 |
|
| 97 |
var dataTypes = _this.chartConvertData( getChartSource ); |
| 98 |
|
| 99 |
var settings = _this.dbData.options; |
| 100 |
var nSettings = _this.configOptionsForCharts(settings); |
| 101 |
|
| 102 |
var userLocale = navigator.language || navigator.userLanguage || 'en'; |
| 103 |
|
| 104 |
/* == Google part == */ |
| 105 |
google.charts.load('current', {'packages':['corechart'], 'language': userLocale}); |
| 106 |
google.charts.setOnLoadCallback(drawChart); |
| 107 |
|
| 108 |
function drawChart() { |
| 109 |
_this.chartData = google.visualization.arrayToDataTable( dataTypes ); |
| 110 |
|
| 111 |
_this.chartOptions = { |
| 112 |
fontSize: nSettings.chartFontSize, |
| 113 |
chartArea: { |
| 114 |
left: nSettings.chartLeftMargin, |
| 115 |
right: nSettings.chartRightMargin, |
| 116 |
top: nSettings.chartTopMargin, |
| 117 |
bottom: nSettings.chartBottomMargin, |
| 118 |
}, |
| 119 |
backgroundColor: { |
| 120 |
fill: nSettings.backgroundColor, |
| 121 |
// strokeWidth: nSettings.borderWidth, |
| 122 |
// stroke: nSettings.borderColor |
| 123 |
}, |
| 124 |
enableInteractivity: nSettings.enableInteractivity, |
| 125 |
legend: { |
| 126 |
position: nSettings.legendPosition, |
| 127 |
alignment: nSettings.legendAlignment, |
| 128 |
textStyle: { |
| 129 |
color: nSettings.legendColor, |
| 130 |
fontSize: nSettings.legendFontSize, |
| 131 |
italic: nSettings.legendItalicText, |
| 132 |
bold: nSettings.legendBoldText, |
| 133 |
} |
| 134 |
}, |
| 135 |
tooltip: { |
| 136 |
trigger: nSettings.tooltipTrigger, |
| 137 |
showColorCode: nSettings.showColorCode, |
| 138 |
text: nSettings.tooltipText, |
| 139 |
textStyle: { |
| 140 |
color: nSettings.tooltipTextColor, |
| 141 |
fontSize: nSettings.tooltipFontSize, |
| 142 |
italic: nSettings.tooltipItalicText, |
| 143 |
bold: nSettings.tooltipBoldText, |
| 144 |
} |
| 145 |
}, |
| 146 |
pieStartAngle: nSettings.rotationDegree, |
| 147 |
pieSliceBorderColor: nSettings.sliceBorderColor, |
| 148 |
reverseCategories: nSettings.reverseCategories, |
| 149 |
pieSliceText: nSettings.sliceText, |
| 150 |
sliceVisibilityThreshold: nSettings.dataGroupingLimit, |
| 151 |
pieResidueSliceLabel: nSettings.dataGroupingLabel, |
| 152 |
pieResidueSliceColor: nSettings.dataGroupingColor, |
| 153 |
slices: {} |
| 154 |
}; |
| 155 |
|
| 156 |
for (var i = 0; i < dataTypes.length - 1; i++) { |
| 157 |
_this.chartOptions.slices[i] = { |
| 158 |
color: nSettings.sliceColor[i], |
| 159 |
offset: typeof nSettings.sliceOffset[i] !== 'undefined' ? nSettings.sliceOffset[i] : 0, |
| 160 |
textStyle: { |
| 161 |
color: nSettings.sliceTextColor[i], |
| 162 |
}, |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
_this.chartObj = new google.visualization.PieChart( document.getElementById(_this.htmlClassPrefix + _this.chartType + _this.uniqueId)); |
| 167 |
|
| 168 |
_this.chartObj.draw( _this.chartData, _this.chartOptions ); |
| 169 |
_this.resizeChart(); |
| 170 |
// Fix ARIA attributes for accessibility compliance |
| 171 |
setTimeout(function() { |
| 172 |
_this.fixAriaAttributes(); |
| 173 |
}, 100); |
| 174 |
} |
| 175 |
/* */ |
| 176 |
} |
| 177 |
|
| 178 |
// Load chart by bar chart |
| 179 |
ChartBuilderGoogleCharts.prototype.barChartView = function(){ |
| 180 |
var _this = this; |
| 181 |
var getChartSource = _this.dbData.source; |
| 182 |
var dataTypes = _this.multiColumnChartConvertData( getChartSource ); |
| 183 |
|
| 184 |
var settings = _this.dbData.options; |
| 185 |
var nSettings = _this.configOptionsForCharts(settings); |
| 186 |
|
| 187 |
var userLocale = navigator.language || navigator.userLanguage || 'en'; |
| 188 |
|
| 189 |
/* == Google part == */ |
| 190 |
google.charts.load('current', {'packages':['corechart'], 'language': userLocale}); |
| 191 |
google.charts.setOnLoadCallback(drawChart); |
| 192 |
|
| 193 |
function drawChart() { |
| 194 |
dataTypes = nSettings.enableRowSettings ? _this.setRowOptions(dataTypes, nSettings, true) : dataTypes; |
| 195 |
|
| 196 |
_this.chartData = google.visualization.arrayToDataTable(dataTypes); |
| 197 |
|
| 198 |
_this.chartOptions = { |
| 199 |
fontSize: nSettings.chartFontSize, |
| 200 |
backgroundColor: { |
| 201 |
fill: nSettings.backgroundColor, |
| 202 |
// strokeWidth: nSettings.borderWidth, |
| 203 |
// stroke: nSettings.borderColor |
| 204 |
}, |
| 205 |
chartArea: { |
| 206 |
backgroundColor: { |
| 207 |
fill: nSettings.chartBackgroundColor, |
| 208 |
stroke: nSettings.chartBorderColor, |
| 209 |
strokeWidth: nSettings.chartBorderWidth |
| 210 |
}, |
| 211 |
left: nSettings.chartLeftMargin, |
| 212 |
right: nSettings.chartRightMargin, |
| 213 |
top: nSettings.chartTopMargin, |
| 214 |
bottom: nSettings.chartBottomMargin, |
| 215 |
}, |
| 216 |
enableInteractivity: nSettings.enableInteractivity, |
| 217 |
theme: nSettings.maximizedView, |
| 218 |
legend: { |
| 219 |
position: nSettings.legendPosition, |
| 220 |
alignment: nSettings.legendAlignment, |
| 221 |
textStyle: { |
| 222 |
color: nSettings.legendColor, |
| 223 |
fontSize: nSettings.legendFontSize, |
| 224 |
italic: nSettings.legendItalicText, |
| 225 |
bold: nSettings.legendBoldText, |
| 226 |
} |
| 227 |
}, |
| 228 |
tooltip: { |
| 229 |
trigger: nSettings.tooltipTrigger, |
| 230 |
showColorCode: nSettings.showColorCode, |
| 231 |
textStyle: { |
| 232 |
color: nSettings.tooltipTextColor, |
| 233 |
fontSize: nSettings.tooltipFontSize, |
| 234 |
italic: nSettings.tooltipItalicText, |
| 235 |
bold: nSettings.tooltipBoldText, |
| 236 |
} |
| 237 |
}, |
| 238 |
hAxis: { |
| 239 |
title: nSettings.hAxisTitle, |
| 240 |
textPosition: nSettings.hAxisTextPosition, |
| 241 |
direction: nSettings.hAxisDirection, |
| 242 |
baselineColor: nSettings.hAxisBaselineColor, |
| 243 |
textStyle: { |
| 244 |
color: nSettings.hAxisTextColor, |
| 245 |
fontSize: nSettings.hAxisTextFontSize, |
| 246 |
italic: nSettings.hAxisItalicText, |
| 247 |
bold: nSettings.hAxisBoldText, |
| 248 |
}, |
| 249 |
slantedText: nSettings.hAxisSlantedText, |
| 250 |
slantedTextAngle: nSettings.hAxisSlantedTextAngle, |
| 251 |
format: nSettings.hAxisFormat, |
| 252 |
titleTextStyle: { |
| 253 |
fontSize: nSettings.hAxisLabelFontSize, |
| 254 |
color: nSettings.hAxisLabelColor, |
| 255 |
italic: nSettings.hAxisItalicTitle, |
| 256 |
bold: nSettings.hAxisBoldTitle, |
| 257 |
}, |
| 258 |
viewWindow: { |
| 259 |
min: nSettings.hAxisMinValue, |
| 260 |
max: nSettings.hAxisMaxValue, |
| 261 |
}, |
| 262 |
gridlines: { |
| 263 |
count: nSettings.hAxisGridlinesCount, |
| 264 |
color: nSettings.hAxisGridlinesColor, |
| 265 |
}, |
| 266 |
minorGridlines: { |
| 267 |
color: nSettings.hAxisMinorGridlinesColor, |
| 268 |
}, |
| 269 |
}, |
| 270 |
vAxis: { |
| 271 |
title: nSettings.vAxisTitle, |
| 272 |
textPosition: nSettings.vAxisTextPosition, |
| 273 |
direction: nSettings.vAxisDirection, |
| 274 |
baselineColor: nSettings.vAxisBaselineColor, |
| 275 |
textStyle: { |
| 276 |
color: nSettings.vAxisTextColor, |
| 277 |
fontSize: nSettings.vAxisTextFontSize, |
| 278 |
italic: nSettings.vAxisItalicText, |
| 279 |
bold: nSettings.vAxisBoldText, |
| 280 |
}, |
| 281 |
format: nSettings.vAxisFormat, |
| 282 |
titleTextStyle: { |
| 283 |
fontSize: nSettings.vAxisLabelFontSize, |
| 284 |
color: nSettings.vAxisLabelColor, |
| 285 |
italic: nSettings.vAxisItalicTitle, |
| 286 |
bold: nSettings.vAxisBoldTitle, |
| 287 |
}, |
| 288 |
viewWindow: { |
| 289 |
min: nSettings.vAxisMinValue, |
| 290 |
max: nSettings.vAxisMaxValue, |
| 291 |
}, |
| 292 |
gridlines: { |
| 293 |
count: nSettings.vAxisGridlinesCount, |
| 294 |
color: nSettings.vAxisGridlinesColor, |
| 295 |
}, |
| 296 |
minorGridlines: { |
| 297 |
color: nSettings.vAxisMinorGridlinesColor, |
| 298 |
}, |
| 299 |
}, |
| 300 |
focusTarget: nSettings.focusTarget, |
| 301 |
isStacked: nSettings.isStacked, |
| 302 |
dataOpacity: nSettings.opacity, |
| 303 |
bar: { |
| 304 |
groupWidth: nSettings.groupWidth |
| 305 |
}, |
| 306 |
series: {}, |
| 307 |
}; |
| 308 |
|
| 309 |
for (var i = 0; i < dataTypes[0].length; i++) { |
| 310 |
_this.chartOptions.series[i] = { |
| 311 |
color: nSettings.seriesColor[i], |
| 312 |
visibleInLegend: nSettings.seriesVisibleInLegend[i] == 'on' ? true : (typeof nSettings.seriesColor[i] !== 'undefined' ? false : true), |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
if (nSettings.enableAnimation) { |
| 317 |
_this.chartOptions.animation = { |
| 318 |
startup: nSettings.animationStartup, |
| 319 |
duration: nSettings.animationDuration, |
| 320 |
easing: nSettings.animationEasing, |
| 321 |
} |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
if(_this.chartOptions.hAxis.format == 'percent' && nSettings.hAxisEnableDividePercent){ |
| 326 |
for (var i = 0; i < dataTypes[0].length - 1; i++) { |
| 327 |
nSettings.seriesFormat[i] = '#%'; |
| 328 |
} |
| 329 |
|
| 330 |
for (var row = 0; row < _this.chartData.getNumberOfRows(); row++) { |
| 331 |
for (var col = 0; col < _this.chartData.getNumberOfColumns(); col++) { |
| 332 |
var value = _this.chartData.getValue(row, col); |
| 333 |
if (typeof value === 'number' && !isNaN(value)) { |
| 334 |
var updatedValue = value / 100; |
| 335 |
_this.chartData.setValue(row, col, updatedValue); |
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
}else { |
| 341 |
for (var i = 0; i < dataTypes[0].length - 1; i++) { |
| 342 |
if (nSettings.seriesFormat[i] === '#%') { |
| 343 |
nSettings.seriesFormat[i] = ''; |
| 344 |
} |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
for (var i = 1; i < dataTypes[0].length; i++) { |
| 349 |
if (nSettings.seriesFormat[i - 1]) { |
| 350 |
var formatter = new google.visualization.NumberFormat({ |
| 351 |
pattern: nSettings.seriesFormat[i - 1] |
| 352 |
}); |
| 353 |
formatter.format(_this.chartData, i); |
| 354 |
} |
| 355 |
} |
| 356 |
_this.chartObj = new google.visualization.BarChart(document.getElementById(_this.htmlClassPrefix + _this.chartType + _this.uniqueId)); |
| 357 |
|
| 358 |
_this.chartObj.draw( _this.chartData, _this.chartOptions ); |
| 359 |
_this.resizeChart(); |
| 360 |
// Fix ARIA attributes for accessibility compliance |
| 361 |
setTimeout(function() { |
| 362 |
_this.fixAriaAttributes(); |
| 363 |
}, 100); |
| 364 |
} |
| 365 |
/* */ |
| 366 |
} |
| 367 |
|
| 368 |
// Load chart by column chart |
| 369 |
ChartBuilderGoogleCharts.prototype.columnChartView = function(){ |
| 370 |
var _this = this; |
| 371 |
var getChartSource = _this.dbData.source; |
| 372 |
|
| 373 |
// Collect data in new array for chart rendering (Column chart) |
| 374 |
var dataTypes = _this.multiColumnChartConvertData( getChartSource ); |
| 375 |
|
| 376 |
var settings = _this.dbData.options; |
| 377 |
var nSettings = _this.configOptionsForCharts(settings); |
| 378 |
|
| 379 |
var userLocale = navigator.language || navigator.userLanguage || 'en'; |
| 380 |
|
| 381 |
/* == Google part == */ |
| 382 |
google.charts.load('current', {'packages':['corechart'], 'language': userLocale}); |
| 383 |
google.charts.setOnLoadCallback(drawChart); |
| 384 |
|
| 385 |
function drawChart() { |
| 386 |
dataTypes = nSettings.enableRowSettings ? _this.setRowOptions(dataTypes, nSettings, true) : dataTypes; |
| 387 |
|
| 388 |
_this.chartData = google.visualization.arrayToDataTable(dataTypes); |
| 389 |
|
| 390 |
_this.chartOptions = { |
| 391 |
fontSize: nSettings.chartFontSize, |
| 392 |
backgroundColor: { |
| 393 |
fill: nSettings.backgroundColor, |
| 394 |
// strokeWidth: nSettings.borderWidth, |
| 395 |
// stroke: nSettings.borderColor |
| 396 |
}, |
| 397 |
chartArea: { |
| 398 |
backgroundColor: { |
| 399 |
fill: nSettings.chartBackgroundColor, |
| 400 |
stroke: nSettings.chartBorderColor, |
| 401 |
strokeWidth: nSettings.chartBorderWidth |
| 402 |
}, |
| 403 |
left: nSettings.chartLeftMargin, |
| 404 |
right: nSettings.chartRightMargin, |
| 405 |
top: nSettings.chartTopMargin, |
| 406 |
bottom: nSettings.chartBottomMargin, |
| 407 |
}, |
| 408 |
enableInteractivity: nSettings.enableInteractivity, |
| 409 |
theme: nSettings.maximizedView, |
| 410 |
legend: { |
| 411 |
position: nSettings.legendPosition, |
| 412 |
alignment: nSettings.legendAlignment, |
| 413 |
textStyle: { |
| 414 |
color: nSettings.legendColor, |
| 415 |
fontSize: nSettings.legendFontSize, |
| 416 |
italic: nSettings.legendItalicText, |
| 417 |
bold: nSettings.legendBoldText, |
| 418 |
} |
| 419 |
}, |
| 420 |
tooltip: { |
| 421 |
trigger: nSettings.tooltipTrigger, |
| 422 |
showColorCode: nSettings.showColorCode, |
| 423 |
textStyle: { |
| 424 |
color: nSettings.tooltipTextColor, |
| 425 |
fontSize: nSettings.tooltipFontSize, |
| 426 |
italic: nSettings.tooltipItalicText, |
| 427 |
bold: nSettings.tooltipBoldText, |
| 428 |
} |
| 429 |
}, |
| 430 |
hAxis: { |
| 431 |
title: nSettings.hAxisTitle, |
| 432 |
textPosition: nSettings.hAxisTextPosition, |
| 433 |
direction: nSettings.hAxisDirection, |
| 434 |
baselineColor: nSettings.hAxisBaselineColor, |
| 435 |
textStyle: { |
| 436 |
color: nSettings.hAxisTextColor, |
| 437 |
fontSize: nSettings.hAxisTextFontSize, |
| 438 |
italic: nSettings.hAxisItalicText, |
| 439 |
bold: nSettings.hAxisBoldText, |
| 440 |
}, |
| 441 |
slantedText: nSettings.hAxisSlantedText, |
| 442 |
slantedTextAngle: nSettings.hAxisSlantedTextAngle, |
| 443 |
format: nSettings.hAxisFormat, |
| 444 |
titleTextStyle: { |
| 445 |
fontSize: nSettings.hAxisLabelFontSize, |
| 446 |
color: nSettings.hAxisLabelColor, |
| 447 |
italic: nSettings.hAxisItalicTitle, |
| 448 |
bold: nSettings.hAxisBoldTitle, |
| 449 |
}, |
| 450 |
viewWindow: { |
| 451 |
min: nSettings.hAxisMinValue, |
| 452 |
max: nSettings.hAxisMaxValue, |
| 453 |
}, |
| 454 |
gridlines: { |
| 455 |
count: nSettings.hAxisGridlinesCount, |
| 456 |
color: nSettings.hAxisGridlinesColor, |
| 457 |
}, |
| 458 |
minorGridlines: { |
| 459 |
color: nSettings.hAxisMinorGridlinesColor, |
| 460 |
}, |
| 461 |
showTextEvery: nSettings.hAxisShowTextEvery |
| 462 |
}, |
| 463 |
vAxis: { |
| 464 |
title: nSettings.vAxisTitle, |
| 465 |
textPosition: nSettings.vAxisTextPosition, |
| 466 |
direction: nSettings.vAxisDirection, |
| 467 |
baselineColor: nSettings.vAxisBaselineColor, |
| 468 |
textStyle: { |
| 469 |
color: nSettings.vAxisTextColor, |
| 470 |
fontSize: nSettings.vAxisTextFontSize, |
| 471 |
italic: nSettings.vAxisItalicText, |
| 472 |
bold: nSettings.vAxisBoldText, |
| 473 |
}, |
| 474 |
format: nSettings.vAxisFormat, |
| 475 |
titleTextStyle: { |
| 476 |
fontSize: nSettings.vAxisLabelFontSize, |
| 477 |
color: nSettings.vAxisLabelColor, |
| 478 |
italic: nSettings.vAxisItalicTitle, |
| 479 |
bold: nSettings.vAxisBoldTitle, |
| 480 |
}, |
| 481 |
viewWindow: { |
| 482 |
min: nSettings.vAxisMinValue, |
| 483 |
max: nSettings.vAxisMaxValue, |
| 484 |
}, |
| 485 |
gridlines: { |
| 486 |
count: nSettings.vAxisGridlinesCount, |
| 487 |
color: nSettings.vAxisGridlinesColor, |
| 488 |
}, |
| 489 |
minorGridlines: { |
| 490 |
color: nSettings.vAxisMinorGridlinesColor, |
| 491 |
}, |
| 492 |
}, |
| 493 |
focusTarget: nSettings.focusTarget, |
| 494 |
isStacked: nSettings.isStacked, |
| 495 |
dataOpacity: nSettings.opacity, |
| 496 |
bar: { |
| 497 |
groupWidth: nSettings.groupWidth |
| 498 |
}, |
| 499 |
series: {}, |
| 500 |
}; |
| 501 |
|
| 502 |
for (var i = 0; i < dataTypes[0].length; i++) { |
| 503 |
_this.chartOptions.series[i] = { |
| 504 |
color: nSettings.seriesColor[i], |
| 505 |
visibleInLegend: nSettings.seriesVisibleInLegend[i] == 'on' ? true : (typeof nSettings.seriesColor[i] !== 'undefined' ? false : true), |
| 506 |
} |
| 507 |
} |
| 508 |
|
| 509 |
if(_this.chartOptions.vAxis.format == 'percent' && nSettings.vAxisEnableDividePercent){ |
| 510 |
for (var i = 0; i < dataTypes[0].length - 1; i++) { |
| 511 |
nSettings.seriesFormat[i] = '#%'; |
| 512 |
} |
| 513 |
|
| 514 |
|
| 515 |
for (var row = 0; row < _this.chartData.getNumberOfRows(); row++) { |
| 516 |
for (var col = 0; col < _this.chartData.getNumberOfColumns(); col++) { |
| 517 |
var value = _this.chartData.getValue(row, col); |
| 518 |
if (typeof value === 'number' && !isNaN(value)) { |
| 519 |
var updatedValue = value / 100; |
| 520 |
_this.chartData.setValue(row, col, updatedValue); |
| 521 |
} |
| 522 |
} |
| 523 |
} |
| 524 |
|
| 525 |
}else { |
| 526 |
for (var i = 0; i < dataTypes[0].length - 1; i++) { |
| 527 |
if (nSettings.seriesFormat[i] === '#%') { |
| 528 |
nSettings.seriesFormat[i] = ''; |
| 529 |
} |
| 530 |
} |
| 531 |
} |
| 532 |
for (var i = 1; i < dataTypes[0].length; i++) { |
| 533 |
if (nSettings.seriesFormat[i - 1]) { |
| 534 |
var formatter = new google.visualization.NumberFormat({ |
| 535 |
pattern: nSettings.seriesFormat[i - 1] |
| 536 |
}); |
| 537 |
formatter.format(_this.chartData, i); |
| 538 |
} |
| 539 |
} |
| 540 |
if (nSettings.enableAnimation) { |
| 541 |
_this.chartOptions.animation = { |
| 542 |
startup: nSettings.animationStartup, |
| 543 |
duration: nSettings.animationDuration, |
| 544 |
easing: nSettings.animationEasing, |
| 545 |
} |
| 546 |
} |
| 547 |
|
| 548 |
_this.chartObj = new google.visualization.ColumnChart(document.getElementById(_this.htmlClassPrefix + _this.chartType + _this.uniqueId)); |
| 549 |
|
| 550 |
_this.chartObj.draw( _this.chartData, _this.chartOptions ); |
| 551 |
_this.resizeChart(); |
| 552 |
// Fix ARIA attributes for accessibility compliance |
| 553 |
setTimeout(function() { |
| 554 |
_this.fixAriaAttributes(); |
| 555 |
}, 100); |
| 556 |
} |
| 557 |
/* */ |
| 558 |
} |
| 559 |
|
| 560 |
// Load chart by line chart |
| 561 |
ChartBuilderGoogleCharts.prototype.lineChartView = function(){ |
| 562 |
var _this = this; |
| 563 |
var getChartSource = _this.dbData.source; |
| 564 |
var dataTypes = _this.multiColumnChartConvertData(getChartSource); |
| 565 |
|
| 566 |
var settings = _this.dbData.options; |
| 567 |
var nSettings = _this.configOptionsForCharts(settings); |
| 568 |
|
| 569 |
var userLocale = navigator.language || navigator.userLanguage || 'en'; |
| 570 |
|
| 571 |
/* == Google part == */ |
| 572 |
google.charts.load('current', {'packages':['corechart'], 'language': userLocale}); |
| 573 |
google.charts.setOnLoadCallback(drawChart); |
| 574 |
|
| 575 |
function drawChart() { |
| 576 |
dataTypes = nSettings.enableRowSettings ? _this.setRowOptions(dataTypes, nSettings, true) : dataTypes; |
| 577 |
|
| 578 |
_this.chartData = google.visualization.arrayToDataTable(dataTypes); |
| 579 |
|
| 580 |
_this.chartOptions = { |
| 581 |
fontSize: nSettings.chartFontSize, |
| 582 |
backgroundColor: { |
| 583 |
fill: nSettings.backgroundColor, |
| 584 |
// strokeWidth: nSettings.borderWidth, |
| 585 |
// stroke: nSettings.borderColor |
| 586 |
}, |
| 587 |
chartArea: { |
| 588 |
backgroundColor: { |
| 589 |
fill: nSettings.chartBackgroundColor, |
| 590 |
stroke: nSettings.chartBorderColor, |
| 591 |
strokeWidth: nSettings.chartBorderWidth |
| 592 |
}, |
| 593 |
left: nSettings.chartLeftMargin, |
| 594 |
right: nSettings.chartRightMargin, |
| 595 |
top: nSettings.chartTopMargin, |
| 596 |
bottom: nSettings.chartBottomMargin, |
| 597 |
}, |
| 598 |
enableInteractivity: nSettings.enableInteractivity, |
| 599 |
theme: nSettings.maximizedView, |
| 600 |
legend: { |
| 601 |
position: nSettings.legendPosition, |
| 602 |
alignment: nSettings.legendAlignment, |
| 603 |
textStyle: { |
| 604 |
color: nSettings.legendColor, |
| 605 |
fontSize: nSettings.legendFontSize, |
| 606 |
italic: nSettings.legendItalicText, |
| 607 |
bold: nSettings.legendBoldText, |
| 608 |
} |
| 609 |
}, |
| 610 |
tooltip: { |
| 611 |
trigger: nSettings.tooltipTrigger, |
| 612 |
showColorCode: nSettings.showColorCode, |
| 613 |
textStyle: { |
| 614 |
color: nSettings.tooltipTextColor, |
| 615 |
fontSize: nSettings.tooltipFontSize, |
| 616 |
italic: nSettings.tooltipItalicText, |
| 617 |
bold: nSettings.tooltipBoldText, |
| 618 |
} |
| 619 |
}, |
| 620 |
hAxis: { |
| 621 |
title: nSettings.hAxisTitle, |
| 622 |
textPosition: nSettings.hAxisTextPosition, |
| 623 |
direction: nSettings.hAxisDirection, |
| 624 |
baselineColor: nSettings.hAxisBaselineColor, |
| 625 |
textStyle: { |
| 626 |
color: nSettings.hAxisTextColor, |
| 627 |
fontSize: nSettings.hAxisTextFontSize, |
| 628 |
italic: nSettings.hAxisItalicText, |
| 629 |
bold: nSettings.hAxisBoldText, |
| 630 |
}, |
| 631 |
slantedText: nSettings.hAxisSlantedText, |
| 632 |
slantedTextAngle: nSettings.hAxisSlantedTextAngle, |
| 633 |
format: nSettings.hAxisFormat, |
| 634 |
titleTextStyle: { |
| 635 |
fontSize: nSettings.hAxisLabelFontSize, |
| 636 |
color: nSettings.hAxisLabelColor, |
| 637 |
italic: nSettings.hAxisItalicTitle, |
| 638 |
bold: nSettings.hAxisBoldTitle, |
| 639 |
}, |
| 640 |
viewWindow: { |
| 641 |
min: nSettings.hAxisMinValue, |
| 642 |
max: nSettings.hAxisMaxValue, |
| 643 |
}, |
| 644 |
gridlines: { |
| 645 |
count: nSettings.hAxisGridlinesCount, |
| 646 |
color: nSettings.hAxisGridlinesColor, |
| 647 |
}, |
| 648 |
minorGridlines: { |
| 649 |
color: nSettings.hAxisMinorGridlinesColor, |
| 650 |
}, |
| 651 |
showTextEvery: nSettings.hAxisShowTextEvery |
| 652 |
}, |
| 653 |
vAxis: { |
| 654 |
title: nSettings.vAxisTitle, |
| 655 |
textPosition: nSettings.vAxisTextPosition, |
| 656 |
direction: nSettings.vAxisDirection, |
| 657 |
baselineColor: nSettings.vAxisBaselineColor, |
| 658 |
textStyle: { |
| 659 |
color: nSettings.vAxisTextColor, |
| 660 |
fontSize: nSettings.vAxisTextFontSize, |
| 661 |
italic: nSettings.vAxisItalicText, |
| 662 |
bold: nSettings.vAxisBoldText, |
| 663 |
}, |
| 664 |
format: nSettings.vAxisFormat, |
| 665 |
titleTextStyle: { |
| 666 |
fontSize: nSettings.vAxisLabelFontSize, |
| 667 |
color: nSettings.vAxisLabelColor, |
| 668 |
italic: nSettings.vAxisItalicTitle, |
| 669 |
bold: nSettings.vAxisBoldTitle, |
| 670 |
}, |
| 671 |
viewWindow: { |
| 672 |
min: nSettings.vAxisMinValue, |
| 673 |
max: nSettings.vAxisMaxValue, |
| 674 |
}, |
| 675 |
gridlines: { |
| 676 |
count: nSettings.vAxisGridlinesCount, |
| 677 |
color: nSettings.vAxisGridlinesColor, |
| 678 |
}, |
| 679 |
minorGridlines: { |
| 680 |
color: nSettings.vAxisMinorGridlinesColor, |
| 681 |
}, |
| 682 |
}, |
| 683 |
crosshair: { |
| 684 |
opacity: nSettings.crosshairOpacity, |
| 685 |
orientation: nSettings.crosshairOrientation, |
| 686 |
trigger: nSettings.crosshairTrigger, |
| 687 |
}, |
| 688 |
focusTarget: nSettings.focusTarget, |
| 689 |
dataOpacity: nSettings.opacity, |
| 690 |
lineWidth: nSettings.lineWidth, |
| 691 |
selectionMode: nSettings.multipleSelection, |
| 692 |
aggregationTarget: nSettings.multipleDataFormat, |
| 693 |
pointShape: nSettings.pointShape, |
| 694 |
pointSize: nSettings.pointSize, |
| 695 |
orientation: nSettings.orientation, |
| 696 |
interpolateNulls: nSettings.fillNulls, |
| 697 |
lineDashStyle: nSettings.dashStyle, |
| 698 |
series: {}, |
| 699 |
}; |
| 700 |
|
| 701 |
for (var i = 0; i < dataTypes[0].length; i++) { |
| 702 |
_this.chartOptions.series[i] = { |
| 703 |
color: nSettings.seriesColor[i], |
| 704 |
visibleInLegend: nSettings.seriesVisibleInLegend[i] == 'on' ? true : (typeof nSettings.seriesColor[i] !== 'undefined' ? false : true), |
| 705 |
lineWidth: nSettings.seriesLineWidth[i], |
| 706 |
pointSize: nSettings.seriesPointSize[i], |
| 707 |
pointShape: nSettings.seriesPointShape[i], |
| 708 |
} |
| 709 |
} |
| 710 |
|
| 711 |
if(_this.chartOptions.vAxis.format == 'percent' && nSettings.vAxisEnableDividePercent){ |
| 712 |
for (var i = 0; i < dataTypes[0].length - 1; i++) { |
| 713 |
nSettings.seriesFormat[i] = '#%'; |
| 714 |
} |
| 715 |
|
| 716 |
for (var row = 0; row < _this.chartData.getNumberOfRows(); row++) { |
| 717 |
for (var col = 0; col < _this.chartData.getNumberOfColumns(); col++) { |
| 718 |
var value = _this.chartData.getValue(row, col); |
| 719 |
if (typeof value === 'number' && !isNaN(value)) { |
| 720 |
var updatedValue = value / 100; |
| 721 |
_this.chartData.setValue(row, col, updatedValue); |
| 722 |
} |
| 723 |
} |
| 724 |
} |
| 725 |
}else { |
| 726 |
for (var i = 0; i < dataTypes[0].length - 1; i++) { |
| 727 |
if (nSettings.seriesFormat[i] === '#%') { |
| 728 |
nSettings.seriesFormat[i] = ''; |
| 729 |
} |
| 730 |
} |
| 731 |
} |
| 732 |
for (var i = 1; i < dataTypes[0].length; i++) { |
| 733 |
if (nSettings.seriesFormat[i - 1]) { |
| 734 |
var formatter = new google.visualization.NumberFormat({ |
| 735 |
pattern: nSettings.seriesFormat[i - 1] |
| 736 |
}); |
| 737 |
formatter.format(_this.chartData, i); |
| 738 |
} |
| 739 |
} |
| 740 |
if (nSettings.enableAnimation) { |
| 741 |
_this.chartOptions.animation = { |
| 742 |
startup: nSettings.animationStartup, |
| 743 |
duration: nSettings.animationDuration, |
| 744 |
easing: nSettings.animationEasing, |
| 745 |
} |
| 746 |
} |
| 747 |
|
| 748 |
_this.chartObj = new google.visualization.LineChart(document.getElementById(_this.htmlClassPrefix + _this.chartType + _this.uniqueId)); |
| 749 |
|
| 750 |
|
| 751 |
_this.chartObj.draw( _this.chartData, _this.chartOptions ); |
| 752 |
_this.resizeChart(); |
| 753 |
// Fix ARIA attributes for accessibility compliance |
| 754 |
setTimeout(function() { |
| 755 |
_this.fixAriaAttributes(); |
| 756 |
}, 100); |
| 757 |
} |
| 758 |
/* */ |
| 759 |
} |
| 760 |
|
| 761 |
// Load chart by donut chart |
| 762 |
ChartBuilderGoogleCharts.prototype.donutChartView = function(){ |
| 763 |
var _this = this; |
| 764 |
var getChartSource = _this.dbData.source; |
| 765 |
|
| 766 |
var dataTypes = _this.chartConvertData(getChartSource); |
| 767 |
|
| 768 |
var settings = _this.dbData.options; |
| 769 |
var nSettings = _this.configOptionsForCharts(settings); |
| 770 |
|
| 771 |
var userLocale = navigator.language || navigator.userLanguage || 'en'; |
| 772 |
|
| 773 |
/* == Google part == */ |
| 774 |
google.charts.load('current', {'packages':['corechart'], 'language': userLocale}); |
| 775 |
google.charts.setOnLoadCallback(drawChart); |
| 776 |
|
| 777 |
function drawChart() { |
| 778 |
_this.chartData = google.visualization.arrayToDataTable( dataTypes ); |
| 779 |
|
| 780 |
_this.chartOptions = { |
| 781 |
fontSize: nSettings.chartFontSize, |
| 782 |
chartArea: { |
| 783 |
left: nSettings.chartLeftMargin, |
| 784 |
right: nSettings.chartRightMargin, |
| 785 |
top: nSettings.chartTopMargin, |
| 786 |
bottom: nSettings.chartBottomMargin, |
| 787 |
}, |
| 788 |
backgroundColor: { |
| 789 |
fill: nSettings.backgroundColor, |
| 790 |
// strokeWidth: nSettings.borderWidth, |
| 791 |
// stroke: nSettings.borderColor |
| 792 |
}, |
| 793 |
enableInteractivity: nSettings.enableInteractivity, |
| 794 |
legend: { |
| 795 |
position: nSettings.legendPosition, |
| 796 |
alignment: nSettings.legendAlignment, |
| 797 |
textStyle: { |
| 798 |
color: nSettings.legendColor, |
| 799 |
fontSize: nSettings.legendFontSize, |
| 800 |
italic: nSettings.legendItalicText, |
| 801 |
bold: nSettings.legendBoldText, |
| 802 |
} |
| 803 |
}, |
| 804 |
tooltip: { |
| 805 |
trigger: nSettings.tooltipTrigger, |
| 806 |
showColorCode: nSettings.showColorCode, |
| 807 |
text: nSettings.tooltipText, |
| 808 |
textStyle: { |
| 809 |
color: nSettings.tooltipTextColor, |
| 810 |
fontSize: nSettings.tooltipFontSize, |
| 811 |
italic: nSettings.tooltipItalicText, |
| 812 |
bold: nSettings.tooltipBoldText, |
| 813 |
} |
| 814 |
}, |
| 815 |
pieStartAngle: nSettings.rotationDegree, |
| 816 |
pieSliceBorderColor: nSettings.sliceBorderColor, |
| 817 |
reverseCategories: nSettings.reverseCategories, |
| 818 |
pieSliceText: nSettings.sliceText, |
| 819 |
sliceVisibilityThreshold: nSettings.dataGroupingLimit, |
| 820 |
pieResidueSliceLabel: nSettings.dataGroupingLabel, |
| 821 |
pieResidueSliceColor: nSettings.dataGroupingColor, |
| 822 |
pieHole: nSettings.holeSize, |
| 823 |
slices: {} |
| 824 |
}; |
| 825 |
|
| 826 |
for (var i = 0; i < dataTypes.length - 1; i++) { |
| 827 |
_this.chartOptions.slices[i] = { |
| 828 |
color: nSettings.sliceColor[i], |
| 829 |
offset: typeof nSettings.sliceOffset[i] !== 'undefined' ? nSettings.sliceOffset[i] : 0, |
| 830 |
textStyle: { |
| 831 |
color: nSettings.sliceTextColor[i], |
| 832 |
}, |
| 833 |
} |
| 834 |
} |
| 835 |
|
| 836 |
_this.chartObj = new google.visualization.PieChart( document.getElementById(_this.htmlClassPrefix + _this.chartType + _this.uniqueId) ); |
| 837 |
|
| 838 |
_this.chartObj.draw( _this.chartData, _this.chartOptions ); |
| 839 |
_this.resizeChart(); |
| 840 |
// Fix ARIA attributes for accessibility compliance |
| 841 |
setTimeout(function() { |
| 842 |
_this.fixAriaAttributes(); |
| 843 |
}, 100); |
| 844 |
} |
| 845 |
/* */ |
| 846 |
} |
| 847 |
|
| 848 |
// Load chart by org chart |
| 849 |
ChartBuilderGoogleCharts.prototype.orgChartView = function(){ |
| 850 |
var _this = this; |
| 851 |
var getChartSource = _this.dbData.source; |
| 852 |
var dataTypes = _this.orgChartConvertData(getChartSource); |
| 853 |
|
| 854 |
var settings = _this.dbData.options; |
| 855 |
var nSettings = _this.configOptionsForCharts(settings); |
| 856 |
|
| 857 |
var userLocale = navigator.language || navigator.userLanguage || 'en'; |
| 858 |
|
| 859 |
/* == Google part == */ |
| 860 |
google.charts.load('current', {'packages':['orgchart'], 'language': userLocale}); |
| 861 |
google.charts.setOnLoadCallback(drawChart); |
| 862 |
|
| 863 |
function drawChart() { |
| 864 |
_this.chartData = new google.visualization.arrayToDataTable(dataTypes); |
| 865 |
|
| 866 |
var view = new google.visualization.DataView(_this.chartData); |
| 867 |
view.setColumns([0, 1, 2]); |
| 868 |
|
| 869 |
_this.chartOptions = { |
| 870 |
allowHtml: true, |
| 871 |
size: nSettings.orgChartFontSize, |
| 872 |
allowCollapse: nSettings.allowCollapse, |
| 873 |
nodeClass: nSettings.orgClassname, |
| 874 |
selectedNodeClass: nSettings.orgSelectedClassname, |
| 875 |
}; |
| 876 |
|
| 877 |
_this.chartObj = new google.visualization.OrgChart(document.getElementById(_this.htmlClassPrefix + _this.chartType + _this.uniqueId)); |
| 878 |
|
| 879 |
google.visualization.events.addListener(_this.chartObj, 'select', function () { |
| 880 |
var selection = _this.chartObj.getSelection(); |
| 881 |
if (selection.length > 0) { |
| 882 |
if (_this.chartData.getValue(selection[0].row, 3) != '') { |
| 883 |
window.open(_this.chartData.getValue(selection[0].row, 3), '_blank'); |
| 884 |
} |
| 885 |
} |
| 886 |
}); |
| 887 |
|
| 888 |
google.visualization.events.addListener(_this.chartObj, 'collapse', function () { |
| 889 |
_this.setOrgChartCustomStyles(); |
| 890 |
}); |
| 891 |
|
| 892 |
_this.chartObj.draw( _this.chartData, _this.chartOptions ); |
| 893 |
_this.resizeChart(); |
| 894 |
_this.setOrgChartCustomStyles(); |
| 895 |
// Fix ARIA attributes for accessibility compliance |
| 896 |
setTimeout(function() { |
| 897 |
_this.fixAriaAttributes(); |
| 898 |
}, 100); |
| 899 |
} |
| 900 |
|
| 901 |
_this.$el.on('click', '.google-visualization-orgchart-node-small, .google-visualization-orgchart-node-medium, .google-visualization-orgchart-node-large', function(e) { |
| 902 |
if (nSettings.orgSelectedClassname !== '') { |
| 903 |
_this.setOrgChartCustomStyles(); |
| 904 |
} |
| 905 |
}); |
| 906 |
} |
| 907 |
|
| 908 |
/* |
| 909 |
Configure all settings for all chart types |
| 910 |
Getting settings for each chart type in respective function |
| 911 |
*/ |
| 912 |
ChartBuilderGoogleCharts.prototype.configOptionsForCharts = function (settings) { |
| 913 |
var newSettings = {}; |
| 914 |
|
| 915 |
newSettings.chartFontSize = settings['font_size']; |
| 916 |
newSettings.backgroundColor = settings['transparent_background'] && settings['transparent_background'] === 'on' ? 'transparent' : settings['background_color']; |
| 917 |
// newSettings.borderWidth = settings['border_width']; |
| 918 |
// newSettings.borderColor = settings['border_color']; |
| 919 |
newSettings.tooltipTrigger = settings['tooltip_trigger']; |
| 920 |
newSettings.tooltipText = settings['tooltip_text']; |
| 921 |
newSettings.showColorCode = (settings['show_color_code'] == 'on') ? true : false; |
| 922 |
newSettings.tooltipItalicText = (settings['tooltip_italic'] == 'on') ? true : false; |
| 923 |
newSettings.tooltipBoldText = settings['tooltip_bold']; |
| 924 |
newSettings.legendItalicText = (settings['legend_italic'] == 'on') ? true : false; |
| 925 |
newSettings.legendBoldText = (settings['legend_bold'] == 'on') ? true : false; |
| 926 |
newSettings.tooltipTextColor = settings['tooltip_text_color']; |
| 927 |
newSettings.tooltipFontSize = settings['tooltip_font_size']; |
| 928 |
newSettings.legendPosition = settings['legend_position']; |
| 929 |
newSettings.legendAlignment = settings['legend_alignment']; |
| 930 |
newSettings.legendFontSize = settings['legend_font_size']; |
| 931 |
newSettings.rotationDegree = settings['rotation_degree']; |
| 932 |
newSettings.sliceBorderColor = settings['slice_border_color']; |
| 933 |
newSettings.reverseCategories = (settings['reverse_categories'] == 'on') ? true : false; |
| 934 |
newSettings.sliceText = settings['slice_text']; |
| 935 |
newSettings.legendColor = settings['legend_color']; |
| 936 |
newSettings.dataGroupingLimit = settings['data_grouping_limit']/100; |
| 937 |
newSettings.dataGroupingLabel = settings['data_grouping_label']; |
| 938 |
newSettings.dataGroupingColor = settings['data_grouping_color']; |
| 939 |
newSettings.sliceColor = settings['slice_color']; |
| 940 |
newSettings.sliceOffset = settings['slice_offset']; |
| 941 |
newSettings.sliceTextColor = settings['slice_text_color']; |
| 942 |
newSettings.chartBackgroundColor = settings['transparent_background'] && settings['transparent_background'] === 'on' ? 'transparent' : settings['chart_background_color']; |
| 943 |
newSettings.chartBorderWidth = settings['chart_border_width']; |
| 944 |
newSettings.chartBorderColor = settings['chart_border_color']; |
| 945 |
newSettings.chartLeftMargin = settings['chart_left_margin_for_js']; |
| 946 |
newSettings.chartRightMargin = settings['chart_right_margin_for_js']; |
| 947 |
newSettings.chartTopMargin = settings['chart_top_margin_for_js']; |
| 948 |
newSettings.chartBottomMargin = settings['chart_bottom_margin_for_js']; |
| 949 |
newSettings.isStacked = (settings['is_stacked'] == 'on') ? true : false; |
| 950 |
newSettings.focusTarget = settings['focus_target']; |
| 951 |
newSettings.groupWidthFormat = settings['group_width_format'] == '%' ? '%' : ''; |
| 952 |
newSettings.groupWidth = settings['group_width'] + newSettings.groupWidthFormat; |
| 953 |
newSettings.hAxisTitle = settings['haxis_title']; |
| 954 |
newSettings.vAxisTitle = settings['vaxis_title']; |
| 955 |
newSettings.hAxisEnableDividePercent = (settings['haxis_enable_divide_percent'] == 'on' && settings['haxis_format'] == 'percent') ? true : false; |
| 956 |
newSettings.vAxisEnableDividePercent = (settings['vaxis_enable_divide_percent'] == 'on' && settings['vaxis_format'] == 'percent') ? true : false; |
| 957 |
newSettings.hAxisLabelFontSize = settings['haxis_label_font_size']; |
| 958 |
newSettings.vAxisLabelFontSize = settings['vaxis_label_font_size']; |
| 959 |
newSettings.hAxisLabelColor = settings['haxis_label_color']; |
| 960 |
newSettings.vAxisLabelColor = settings['vaxis_label_color']; |
| 961 |
newSettings.hAxisTextPosition = settings['haxis_text_position']; |
| 962 |
newSettings.vAxisTextPosition = settings['vaxis_text_position']; |
| 963 |
newSettings.vAxisDirection = (settings['vaxis_direction'] == '-1') ? -1 : 1; |
| 964 |
newSettings.hAxisDirection = (settings['haxis_direction'] == '-1') ? -1 : 1; |
| 965 |
newSettings.hAxisTextColor = settings['haxis_text_color']; |
| 966 |
newSettings.vAxisTextColor = settings['vaxis_text_color']; |
| 967 |
newSettings.hAxisBaselineColor = settings['haxis_baseline_color']; |
| 968 |
newSettings.vAxisBaselineColor = settings['vaxis_baseline_color']; |
| 969 |
newSettings.hAxisTextFontSize = settings['haxis_text_font_size']; |
| 970 |
newSettings.vAxisTextFontSize = settings['vaxis_text_font_size']; |
| 971 |
newSettings.hAxisSlantedText = settings['haxis_slanted']; |
| 972 |
newSettings.hAxisSlantedTextAngle = settings['haxis_slanted_text_angle']; |
| 973 |
newSettings.hAxisShowTextEvery = settings['haxis_show_text_every']; |
| 974 |
newSettings.vAxisFormat = settings['vaxis_format']; |
| 975 |
newSettings.hAxisFormat = settings['haxis_format']; |
| 976 |
newSettings.hAxisMinValue = settings['haxis_min_value']; |
| 977 |
newSettings.hAxisMaxValue = settings['haxis_max_value']; |
| 978 |
newSettings.vAxisMinValue = settings['vaxis_min_value']; |
| 979 |
newSettings.vAxisMaxValue = settings['vaxis_max_value']; |
| 980 |
newSettings.hAxisGridlinesCount = settings['haxis_gridlines_count']; |
| 981 |
newSettings.hAxisGridlinesColor = settings['haxis_gridlines_color']; |
| 982 |
newSettings.hAxisMinorGridlinesColor = settings['haxis_minor_gridlines_color']; |
| 983 |
newSettings.vAxisGridlinesCount = settings['vaxis_gridlines_count']; |
| 984 |
newSettings.vAxisGridlinesColor = settings['vaxis_gridlines_color']; |
| 985 |
newSettings.vAxisMinorGridlinesColor = settings['vaxis_minor_gridlines_color']; |
| 986 |
newSettings.hAxisItalicText = (settings['haxis_italic'] == 'on') ? true : false; |
| 987 |
newSettings.hAxisBoldText = (settings['haxis_bold'] == 'on') ? true : false; |
| 988 |
newSettings.vAxisItalicText = (settings['vaxis_italic'] == 'on') ? true : false; |
| 989 |
newSettings.vAxisBoldText = (settings['vaxis_bold'] == 'on') ? true : false; |
| 990 |
newSettings.hAxisItalicTitle = (settings['haxis_title_italic'] == 'on') ? true : false; |
| 991 |
newSettings.hAxisBoldTitle = (settings['haxis_title_bold'] == 'on') ? true : false; |
| 992 |
newSettings.vAxisItalicTitle = (settings['vaxis_title_italic'] == 'on') ? true : false; |
| 993 |
newSettings.vAxisBoldTitle = (settings['vaxis_title_bold'] == 'on') ? true : false; |
| 994 |
newSettings.opacity = settings['opacity']; |
| 995 |
newSettings.enableInteractivity = (settings['enable_interactivity'] == 'off') ? false : true; |
| 996 |
newSettings.maximizedView = (settings['maximized_view'] == 'on') ? 'maximized' : null; |
| 997 |
newSettings.enableAnimation = (settings['enable_animation'] == 'on') ? true : false; |
| 998 |
newSettings.animationDuration = settings['animation_duration']; |
| 999 |
newSettings.animationStartup = (settings['animation_startup'] == 'off') ? false : true; |
| 1000 |
newSettings.animationEasing = settings['animation_easing']; |
| 1001 |
newSettings.seriesColor = settings['series_color']; |
| 1002 |
newSettings.seriesFormat = settings['series_format']; |
| 1003 |
newSettings.seriesVisibleInLegend = settings['series_visible_in_legend']; |
| 1004 |
newSettings.seriesLineWidth = settings['series_line_width']; |
| 1005 |
newSettings.seriesPointSize = settings['series_point_size']; |
| 1006 |
newSettings.seriesPointShape = settings['series_point_shape']; |
| 1007 |
newSettings.enableRowSettings = (settings['enable_row_settings'] == 'on') ? true : false; |
| 1008 |
newSettings.rowsColor = settings['rows_color']; |
| 1009 |
newSettings.rowsOpacity = settings['rows_opacity']; |
| 1010 |
newSettings.multipleSelection = (settings['multiple_selection'] == 'on') ? 'multiple' : 'single'; |
| 1011 |
newSettings.multipleDataFormat = settings['multiple_data_format']; |
| 1012 |
newSettings.pointShape = settings['point_shape']; |
| 1013 |
newSettings.pointSize = settings['point_size']; |
| 1014 |
newSettings.lineWidth = settings['line_width']; |
| 1015 |
newSettings.crosshairTrigger = settings['crosshair_trigger']; |
| 1016 |
newSettings.crosshairOrientation = settings['crosshair_orientation']; |
| 1017 |
newSettings.crosshairOpacity = settings['crosshair_opacity']; |
| 1018 |
newSettings.dashStyle = settings['dash_style'] ? settings['dash_style'].split(',') : null; |
| 1019 |
newSettings.orientation = (settings['orientation'] == 'on') ? 'vertical' : 'horizontal'; |
| 1020 |
newSettings.fillNulls = (settings['fill_nulls'] == 'on') ? true : false; |
| 1021 |
newSettings.holeSize = settings['donut_hole_size']; |
| 1022 |
newSettings.orgChartFontSize = settings['org_chart_font_size']; |
| 1023 |
newSettings.allowCollapse = (settings['allow_collapse'] == 'on') ? true : false; |
| 1024 |
newSettings.orgClassname = settings['org_classname']; |
| 1025 |
newSettings.orgSelectedClassname = settings['org_selected_classname']; |
| 1026 |
|
| 1027 |
return newSettings; |
| 1028 |
} |
| 1029 |
|
| 1030 |
ChartBuilderGoogleCharts.prototype.setRowOptions = function (data, options, isJS = true) { |
| 1031 |
var _this = this; |
| 1032 |
|
| 1033 |
if (data && data.length > 0) { |
| 1034 |
if (data[0] && data[0].length == 2) { |
| 1035 |
data[0].push({ role: 'style' }); |
| 1036 |
for (var i = 1; i < data.length; i++) { |
| 1037 |
var opts = []; |
| 1038 |
|
| 1039 |
var color = isJS ? options.rowsColor[i - 1] : options.rows_color[i - 1]; |
| 1040 |
opts.push(color ? 'color:'+color : ''); |
| 1041 |
|
| 1042 |
var opacity = isJS ? options.rowsOpacity[i - 1] : options.rows_opacity[i - 1]; |
| 1043 |
opts.push(opacity ? 'opacity:'+opacity : ''); |
| 1044 |
|
| 1045 |
|
| 1046 |
data[i].push(opts.join(';')); |
| 1047 |
} |
| 1048 |
} |
| 1049 |
} |
| 1050 |
|
| 1051 |
return data; |
| 1052 |
} |
| 1053 |
|
| 1054 |
ChartBuilderGoogleCharts.prototype.removeRowOptions = function (data) { |
| 1055 |
var _this = this; |
| 1056 |
|
| 1057 |
if (data && data.length > 0) { |
| 1058 |
if (data[0] && data[0].length == 2) { |
| 1059 |
for (var i = 0; i < data.length; i++) { |
| 1060 |
data[i].splice(2, 1); |
| 1061 |
} |
| 1062 |
} |
| 1063 |
} |
| 1064 |
|
| 1065 |
return data; |
| 1066 |
} |
| 1067 |
|
| 1068 |
// Detect window resize moment to draw charts responsively |
| 1069 |
ChartBuilderGoogleCharts.prototype.resizeChart = function(){ |
| 1070 |
var _this = this; |
| 1071 |
|
| 1072 |
//create trigger to resizeEnd event |
| 1073 |
$(window).resize(function() { |
| 1074 |
if(this.resizeTO) clearTimeout(this.resizeTO); |
| 1075 |
this.resizeTO = setTimeout(function() { |
| 1076 |
$(this).trigger('resizeEnd'); |
| 1077 |
}, 100); |
| 1078 |
}); |
| 1079 |
|
| 1080 |
//redraw graph when window resize is completed |
| 1081 |
$(window).on('resizeEnd', function() { |
| 1082 |
_this.drawChartFunction( _this.chartData, _this.chartOptions ); |
| 1083 |
}); |
| 1084 |
} |
| 1085 |
|
| 1086 |
ChartBuilderGoogleCharts.prototype.setOrgChartCustomStyles = function () { |
| 1087 |
var _this = this; |
| 1088 |
var settings = _this.dbData.options; |
| 1089 |
|
| 1090 |
var orgClassname = settings.org_classname; |
| 1091 |
var bgColor = settings.org_node_background_color; |
| 1092 |
var padding = settings.org_node_padding; |
| 1093 |
var borderRadius = settings.org_node_border_radius; |
| 1094 |
var borderWidth = settings.org_node_border_width; |
| 1095 |
var borderColor = settings.org_node_border_color; |
| 1096 |
var textColor = settings.org_node_text_color; |
| 1097 |
var textSize = settings.org_node_text_font_size; |
| 1098 |
var descriptionColor = settings.org_node_description_font_color; |
| 1099 |
var descriptionSize = settings.org_node_description_font_size; |
| 1100 |
|
| 1101 |
var orgSelectedClassname = settings.org_selected_classname; |
| 1102 |
var selectedBgColor = settings.org_selected_node_background_color; |
| 1103 |
var selectedTextColor = settings.org_selected_node_text_color; |
| 1104 |
|
| 1105 |
if (orgClassname != '') { |
| 1106 |
var node = _this.$el.find('.' + orgClassname); |
| 1107 |
node.css({ |
| 1108 |
'background-color' : bgColor, |
| 1109 |
'padding' : padding + 'px', |
| 1110 |
'border-radius' : borderRadius + 'px', |
| 1111 |
'color' : textColor, |
| 1112 |
'font-size' : textSize + 'px', |
| 1113 |
'border' : 'none', |
| 1114 |
'outline' : borderWidth + 'px solid ' + borderColor, |
| 1115 |
}); |
| 1116 |
} |
| 1117 |
|
| 1118 |
if (orgSelectedClassname != '') { |
| 1119 |
var selectedNode = _this.$el.find('.' + orgSelectedClassname); |
| 1120 |
selectedNode.css({ |
| 1121 |
'background-color' : selectedBgColor, |
| 1122 |
// 'padding' : padding + 'px', |
| 1123 |
// 'border-radius' : borderRadius + 'px', |
| 1124 |
'color' : selectedTextColor, |
| 1125 |
// 'font-size' : textSize + 'px', |
| 1126 |
// 'border' : 'none', |
| 1127 |
// 'outline' : borderWidth + 'px solid ' + borderColor, |
| 1128 |
}); |
| 1129 |
} |
| 1130 |
|
| 1131 |
var description = _this.$el.find('.' + _this.htmlClassPrefix + 'org-chart-tree-description'); |
| 1132 |
description.css({ |
| 1133 |
'color' : descriptionColor, |
| 1134 |
'font-size' : descriptionSize + 'px', |
| 1135 |
}); |
| 1136 |
|
| 1137 |
// var image = _this.$el.find('.' + _this.htmlClassPrefix + 'org-chart-tree-image'); |
| 1138 |
} |
| 1139 |
|
| 1140 |
// Load chart by pie chart |
| 1141 |
ChartBuilderGoogleCharts.prototype.chartConvertData = function( data ){ |
| 1142 |
var _this = this; |
| 1143 |
var dataTypes = []; |
| 1144 |
|
| 1145 |
// Collect data in new array for chart rendering |
| 1146 |
for ( var key in data ) { |
| 1147 |
if ( data.hasOwnProperty( key ) ) { |
| 1148 |
if (key == 0) { |
| 1149 |
if (data[key][0] != '' && data[key][1] != '') { |
| 1150 |
dataTypes.push([ |
| 1151 |
_this.htmlDecode(data[key][0]), _this.htmlDecode(data[key][1]) |
| 1152 |
]); |
| 1153 |
} |
| 1154 |
} else { |
| 1155 |
if (data[key][0] != '' && data[key][1] != '') { |
| 1156 |
dataTypes.push([ |
| 1157 |
_this.htmlDecode(data[key][0]), +(data[key][1]) |
| 1158 |
]); |
| 1159 |
} |
| 1160 |
} |
| 1161 |
} |
| 1162 |
} |
| 1163 |
|
| 1164 |
return dataTypes; |
| 1165 |
} |
| 1166 |
|
| 1167 |
// Converting chart data for multicolumn chart |
| 1168 |
ChartBuilderGoogleCharts.prototype.multiColumnChartConvertData = function( data ){ |
| 1169 |
var _this = this; |
| 1170 |
var dataTypes = []; |
| 1171 |
var titleRow = []; |
| 1172 |
|
| 1173 |
for (var key in data) { |
| 1174 |
var dataRow = []; |
| 1175 |
if (data.hasOwnProperty(key)) { |
| 1176 |
if (key == 0) { |
| 1177 |
for (var index in data[key]) { |
| 1178 |
if (data[key][index] != '') { |
| 1179 |
titleRow.push(_this.htmlDecode(data[key][index])); |
| 1180 |
} |
| 1181 |
} |
| 1182 |
dataTypes.push(titleRow); |
| 1183 |
} else { |
| 1184 |
for (var index in data[key]) { |
| 1185 |
if (data[key][index] != '') { |
| 1186 |
if (index == 0) { |
| 1187 |
dataRow.push(_this.htmlDecode(data[key][index])); |
| 1188 |
} else { |
| 1189 |
dataRow.push(+data[key][index]); |
| 1190 |
} |
| 1191 |
} |
| 1192 |
} |
| 1193 |
dataTypes.push(dataRow); |
| 1194 |
} |
| 1195 |
} |
| 1196 |
} |
| 1197 |
|
| 1198 |
return dataTypes; |
| 1199 |
} |
| 1200 |
|
| 1201 |
// Converting chart data for org chart type |
| 1202 |
ChartBuilderGoogleCharts.prototype.orgChartConvertData = function( data ){ |
| 1203 |
var _this = this; |
| 1204 |
var dataTypes = [['Name', 'Manager', 'Tooltip', 'Url']]; |
| 1205 |
|
| 1206 |
var ordering = (_this.dbData && Array.isArray(_this.dbData.source_ordering)) |
| 1207 |
? _this.dbData.source_ordering.slice() |
| 1208 |
: []; |
| 1209 |
|
| 1210 |
ordering = ordering.map(String); |
| 1211 |
|
| 1212 |
Object.keys(data).forEach(function(key) { |
| 1213 |
if (!ordering.includes(key)) { |
| 1214 |
ordering.push(key); |
| 1215 |
} |
| 1216 |
}); |
| 1217 |
|
| 1218 |
// var name = ""; |
| 1219 |
// Collect data in new array for chart rendering |
| 1220 |
ordering.forEach(function(key) { |
| 1221 |
if (!data.hasOwnProperty(key) || key == 0) return; |
| 1222 |
|
| 1223 |
var row = data[key]; |
| 1224 |
var name = row[0]; |
| 1225 |
var description = row[1]; |
| 1226 |
var image = (row.length > 6) ? row[2] : ''; |
| 1227 |
var parent_name = (row.length > 6) ? row[3] : row[2]; |
| 1228 |
var tooltip = (row.length > 6) ? row[4] : row[3]; |
| 1229 |
var url = (row.length > 6) ? row[5] : ''; |
| 1230 |
|
| 1231 |
if (description) { |
| 1232 |
name += _this.orgChartFormatName(description); |
| 1233 |
} |
| 1234 |
if (image && image !== '') { |
| 1235 |
name = _this.orgChartFormatImage(image) + name; |
| 1236 |
} |
| 1237 |
|
| 1238 |
name = {'v': row[0], 'f': name}; |
| 1239 |
dataTypes.push([name, parent_name, tooltip, url]); |
| 1240 |
}); |
| 1241 |
|
| 1242 |
return dataTypes; |
| 1243 |
} |
| 1244 |
|
| 1245 |
ChartBuilderGoogleCharts.prototype.orgChartFormatName = function( description ){ |
| 1246 |
return `<div class="${this.htmlClassPrefix}org-chart-tree-description">${description}</div>`; |
| 1247 |
} |
| 1248 |
|
| 1249 |
ChartBuilderGoogleCharts.prototype.orgChartFormatImage = function( image ){ |
| 1250 |
return `<div class="${this.htmlClassPrefix}org-chart-tree-image"><img width="128px" src="${image}"></div>`; |
| 1251 |
} |
| 1252 |
|
| 1253 |
// Set onclick event on export buttons |
| 1254 |
ChartBuilderGoogleCharts.prototype.setClickEventOnExportButtons = function(){ |
| 1255 |
var _this = this; |
| 1256 |
$(document).find(".ays-chart-export-button-" + _this.uniqueId).on("click" , function(e){ |
| 1257 |
e.preventDefault(); |
| 1258 |
var buttonVal = $(this).val(); |
| 1259 |
$(this).attr('data-clicked','true'); |
| 1260 |
switch (buttonVal){ |
| 1261 |
case 'image': |
| 1262 |
_this.exportOpenChartPrintWindow($(this).parent(),'image',_this.uniqueId); |
| 1263 |
break; |
| 1264 |
default: |
| 1265 |
break; |
| 1266 |
} |
| 1267 |
}); |
| 1268 |
} |
| 1269 |
|
| 1270 |
ChartBuilderGoogleCharts.prototype.exportOpenChartPrintWindow = function (buttonsContainer, type) { |
| 1271 |
var _this = this; |
| 1272 |
buttonsContainer.find(".ays-chart-export-button-" + _this.uniqueId + "[data-clicked='true']").removeAttr('data-clicked'); |
| 1273 |
if(typeof _this.chartOptions !== undefined){ |
| 1274 |
_this.chartOptions.width = '800'; |
| 1275 |
} |
| 1276 |
|
| 1277 |
var iframe = buttonsContainer.find("iframe"); |
| 1278 |
iframe.attr('id','iframe-' + _this.uniqueId); |
| 1279 |
_this.resizeChart(); |
| 1280 |
|
| 1281 |
if (_this.chartType == 'word_tree' ){ // without this condition it resets chart view |
| 1282 |
iframe.contents().find('body').append($(document).find('#' + _this.htmlClassPrefix + _this.chartType + _this.uniqueId).clone()); |
| 1283 |
|
| 1284 |
if(type == 'image' && typeof _this.chartObj.getImageURI != "undefined"){ |
| 1285 |
var imageURI = _this.chartObj.getImageURI(); |
| 1286 |
var downloadTag = $('<a>'); |
| 1287 |
downloadTag.attr('href',imageURI); |
| 1288 |
downloadTag.text('download link'); |
| 1289 |
downloadTag.attr('download',_this.chartType); |
| 1290 |
|
| 1291 |
downloadTag[0].click(); |
| 1292 |
} |
| 1293 |
if(type != 'image'){ |
| 1294 |
window.frames['iframe-' + _this.uniqueId].contentWindow.print(); |
| 1295 |
} |
| 1296 |
iframe.removeAttr('id'); |
| 1297 |
iframe.contents().find('head').html(""); |
| 1298 |
iframe.contents().find('body').html(""); |
| 1299 |
return ; |
| 1300 |
} |
| 1301 |
|
| 1302 |
var listener = google.visualization.events.addListener(_this.chartObj, 'ready',function () { |
| 1303 |
google.visualization.events.removeListener(listener) |
| 1304 |
var clonedContent = $(document).find('#' + _this.htmlClassPrefix + _this.chartType + _this.uniqueId).clone(); |
| 1305 |
_this.chartOptions.height = ''; |
| 1306 |
_this.chartOptions.width = ''; |
| 1307 |
// _this.drawChartFunction( _this.chartData, _this.chartOptions , _this.chartType); |
| 1308 |
_this.loadChartBySource(); |
| 1309 |
|
| 1310 |
setTimeout(function(){ //setting timeout for complete init |
| 1311 |
|
| 1312 |
|
| 1313 |
// check if can create image for download |
| 1314 |
if(type == 'image' && typeof _this.chartObj.getImageURI != "undefined"){ |
| 1315 |
var imageURI = _this.chartObj.getImageURI(); |
| 1316 |
var downloadTag = $('<a>'); |
| 1317 |
downloadTag.attr('href',imageURI); |
| 1318 |
downloadTag.text('download link'); |
| 1319 |
downloadTag.attr('download',_this.chartType); |
| 1320 |
|
| 1321 |
downloadTag[0].click(); |
| 1322 |
} |
| 1323 |
|
| 1324 |
iframe.contents().find('body').append(clonedContent); |
| 1325 |
if (_this.chartType == 'org_chart' || _this.chartType == 'table_chart'){ |
| 1326 |
var linkHref = ""; |
| 1327 |
var linkScript = $('<link>'); |
| 1328 |
switch (_this.chartType){ |
| 1329 |
case 'org_chart': |
| 1330 |
linkHref = "https://www.gstatic.com/charts/48.1/css/orgchart/orgchart.css"; //48.1 is google chart version , check current version |
| 1331 |
break; |
| 1332 |
case 'table_chart': |
| 1333 |
linkHref = "https://www.gstatic.com/charts/48.1/css/table/table.css"; //48.1 is google chart version , check current version |
| 1334 |
break; |
| 1335 |
default: |
| 1336 |
break; |
| 1337 |
} |
| 1338 |
linkScript.attr('rel','stylesheet'); |
| 1339 |
linkScript.attr('href',linkHref); |
| 1340 |
|
| 1341 |
var oHead = iframe.contents().find('body'); |
| 1342 |
linkScript.ready(function(){ |
| 1343 |
oHead.append(linkScript); |
| 1344 |
}); |
| 1345 |
} |
| 1346 |
|
| 1347 |
if(type != 'image'){ |
| 1348 |
window.frames['iframe-' + _this.uniqueId].contentWindow.print(); |
| 1349 |
|
| 1350 |
} |
| 1351 |
|
| 1352 |
iframe.contents().find('head').html(""); |
| 1353 |
iframe.contents().find('body').html(""); |
| 1354 |
iframe.removeAttr('id'); |
| 1355 |
},200); |
| 1356 |
|
| 1357 |
}); |
| 1358 |
_this.drawChartFunction( _this.chartData, _this.chartOptions); |
| 1359 |
} |
| 1360 |
|
| 1361 |
// Update chart data and display immediately |
| 1362 |
ChartBuilderGoogleCharts.prototype.updateChartData = function( newData ){ |
| 1363 |
var _this = this; |
| 1364 |
_this.chartObj.draw( newData, _this.chartOptions ); |
| 1365 |
} |
| 1366 |
|
| 1367 |
ChartBuilderGoogleCharts.prototype.htmlDecode = function (input) { |
| 1368 |
var e = document.createElement('div'); |
| 1369 |
e.innerHTML = input; |
| 1370 |
return e.childNodes[0].nodeValue; |
| 1371 |
} |
| 1372 |
|
| 1373 |
// Fix ARIA attributes for WCAG compliance |
| 1374 |
ChartBuilderGoogleCharts.prototype.fixAriaAttributes = function() { |
| 1375 |
var _this = this; |
| 1376 |
var chartContainer = document.getElementById(_this.htmlClassPrefix + _this.chartType + _this.uniqueId); |
| 1377 |
|
| 1378 |
if (!chartContainer) { |
| 1379 |
return; |
| 1380 |
} |
| 1381 |
|
| 1382 |
// Find all divs with aria-label |
| 1383 |
var divsWithAriaLabel = chartContainer.querySelectorAll('div[aria-label]'); |
| 1384 |
divsWithAriaLabel.forEach(function(div) { |
| 1385 |
// Check if this div contains a table (the data table representation) |
| 1386 |
if (div.querySelector('table')) { |
| 1387 |
// Add role="region" to the table container div |
| 1388 |
if (!div.hasAttribute('role')) { |
| 1389 |
div.setAttribute('role', 'region'); |
| 1390 |
} |
| 1391 |
} else { |
| 1392 |
// Remove aria-label from divs without roles (not table containers) |
| 1393 |
if (!div.hasAttribute('role')) { |
| 1394 |
div.removeAttribute('aria-label'); |
| 1395 |
} |
| 1396 |
} |
| 1397 |
}); |
| 1398 |
|
| 1399 |
// Add role="img" to SVG elements with aria-label |
| 1400 |
var svgElements = chartContainer.querySelectorAll('svg[aria-label]'); |
| 1401 |
svgElements.forEach(function(svg) { |
| 1402 |
if (!svg.hasAttribute('role')) { |
| 1403 |
svg.setAttribute('role', 'img'); |
| 1404 |
} |
| 1405 |
}); |
| 1406 |
} |
| 1407 |
|
| 1408 |
ChartBuilderGoogleCharts.prototype.drawChartFunction = function (source, options) { |
| 1409 |
var _this = this; |
| 1410 |
|
| 1411 |
var view = new google.visualization.DataView(source); |
| 1412 |
_this.chartData = source; |
| 1413 |
|
| 1414 |
// Set role="img" on the chart container |
| 1415 |
var chartContainer = document.getElementById(_this.htmlClassPrefix + _this.chartType + _this.uniqueId); |
| 1416 |
if (chartContainer) { |
| 1417 |
chartContainer.setAttribute('role', 'img'); |
| 1418 |
} |
| 1419 |
|
| 1420 |
// Fix ARIA attributes after chart is drawn |
| 1421 |
var drawCallback = function() { |
| 1422 |
_this.fixAriaAttributes(); |
| 1423 |
}; |
| 1424 |
|
| 1425 |
// Add callback to options if it doesn't exist |
| 1426 |
if (typeof options.chartArea === 'object') { |
| 1427 |
options.chartArea.chartReady = drawCallback; |
| 1428 |
} else { |
| 1429 |
options.chartReady = drawCallback; |
| 1430 |
} |
| 1431 |
|
| 1432 |
if (_this.chartType == 'org_chart') { |
| 1433 |
view.setColumns([0, 1, 2]); |
| 1434 |
} |
| 1435 |
|
| 1436 |
_this.chartObj.draw(view, options); |
| 1437 |
|
| 1438 |
if (_this.chartType == 'org_chart') { |
| 1439 |
_this.setOrgChartCustomStyles(); |
| 1440 |
} |
| 1441 |
} |
| 1442 |
|
| 1443 |
$.fn.ChartBuilderGoogleChartsMain = function(options) { |
| 1444 |
return this.each(function() { |
| 1445 |
if (!$.data(this, 'ChartBuilderGoogleChartsMain')) { |
| 1446 |
$.data(this, 'ChartBuilderGoogleChartsMain', new ChartBuilderGoogleCharts(this, options)); |
| 1447 |
} else { |
| 1448 |
try { |
| 1449 |
$(this).data('ChartBuilderGoogleChartsMain').init(); |
| 1450 |
} catch (err) { |
| 1451 |
console.error('ChartBuilderGoogleChartsMain has not initiated properly'); |
| 1452 |
} |
| 1453 |
} |
| 1454 |
}); |
| 1455 |
}; |
| 1456 |
|
| 1457 |
})(jQuery); |
| 1458 |
|