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