vendor: 4,683 bytes, lines 1-178
1/*! 2 * Chartkick.js v5.0.0 3 * Create beautiful charts with one line of JavaScript 4 * https://github.com/ankane/chartkick.js 5 * MIT License 6 */ 7 8(function (global, factory) { 9 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : 10 typeof define === 'function' && define.amd ? define(factory) : 11 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Chartkick = factory()); 12})(this, (function () { 'use strict'; 13 14 function isArray(variable) { 15 return Object.prototype.toString.call(variable) === "[object Array]"; 16 } 17 18 function isFunction(variable) { 19 return variable instanceof Function; 20 } 21 22 function isPlainObject(variable) { 23 // protect against prototype pollution, defense 2 24 return Object.prototype.toString.call(variable) === "[object Object]" && !isFunction(variable) && variable instanceof Object; 25 } 26 27 // https://github.com/madrobby/zepto/blob/master/src/zepto.js 28 function extend(target, source) { 29 for (var key in source) { 30 // protect against prototype pollution, defense 1 31 if (key === "__proto__") { continue; } 32 33 if (isPlainObject(source[key]) || isArray(source[key])) { 34 if (isPlainObject(source[key]) && !isPlainObject(target[key])) { 35 target[key] = {}; 36 } 37 if (isArray(source[key]) && !isArray(target[key])) { 38 target[key] = []; 39 } 40 extend(target[key], source[key]); 41 } else if (source[key] !== undefined) { 42 target[key] = source[key]; 43 } 44 } 45 } 46 47 function merge(obj1, obj2) { 48 var target = {}; 49 extend(target, obj1); 50 extend(target, obj2); 51 return target; 52 } 53 54 var DATE_PATTERN = /^(\d\d\d\d)(?:-)?(\d\d)(?:-)?(\d\d)$/i; 55 56 function negativeValues(series) { 57 for (var i = 0; i < series.length; i++) { 58 var data = series[i].data; 59 for (var j = 0; j < data.length; j++) { 60 if (data[j][1] < 0) { 61 return true; 62 } 63 } 64 } 65 return false; 66 } 67 68 function toStr(obj) { 69 return "" + obj; 70 } 71 72 function toFloat(obj) { 73 return parseFloat(obj); 74 } 75 76 function toDate(obj) { 77 if (obj instanceof Date) { 78 return obj; 79 } else if (typeof obj === "number") { 80 return new Date(obj * 1000); // ms 81 } else { 82 var s = toStr(obj); 83 var matches = s.match(DATE_PATTERN); 84 if (matches) { 85 var year = parseInt(matches[1], 10); 86 var month = parseInt(matches[2], 10) - 1; 87 var day = parseInt(matches[3], 10); 88 return new Date(year, month, day); 89 } else { 90 // try our best to get the str into iso8601 91 // TODO be smarter about this 92 var str = s.replace(/ /, "T").replace(" ", "").replace("UTC", "Z"); 93 // Date.parse returns milliseconds if valid and NaN if invalid 94 return new Date(Date.parse(str) || s); 95 } 96 } 97 } 98 99 function toArr(obj) { 100 if (isArray(obj)) { 101 return obj; 102 } else { 103 var arr = []; 104 for (var i in obj) { 105 if (Object.prototype.hasOwnProperty.call(obj, i)) { 106 arr.push([i, obj[i]]); 107 } 108 } 109 return arr; 110 } 111 } 112 113 function jsOptionsFunc(defaultOptions, hideLegend, setTitle, setMin, setMax, setStacked, setXtitle, setYtitle) { 114 return function (chart, opts, chartOptions) { 115 var series = chart.data; 116 var options = merge({}, defaultOptions); 117 options = merge(options, chartOptions || {}); 118 119 if (chart.singleSeriesFormat || "legend" in opts) { 120 hideLegend(options, opts.legend, chart.singleSeriesFormat); 121 } 122 123 if (opts.title) { 124 setTitle(options, opts.title); 125 } 126 127 // min 128 if ("min" in opts) { 129 setMin(options, opts.min); 130 } else if (!negativeValues(series)) { 131 setMin(options, 0); 132 } 133 134 // max 135 if (opts.max) { 136 setMax(options, opts.max); 137 } 138 139 if ("stacked" in opts) { 140 setStacked(options, opts.stacked); 141 } 142 143 if (opts.colors) { 144 options.colors = opts.colors; 145 } 146 147 if (opts.xtitle) { 148 setXtitle(options, opts.xtitle); 149 } 150 151 if (opts.ytitle) { 152 setYtitle(options, opts.ytitle); 153 } 154 155 // merge library last 156 options = merge(options, opts.library || {}); 157 158 return options; 159 }; 160 } 161 162 function sortByTime(a, b) { 163 return a[0].getTime() - b[0].getTime(); 164 } 165 166 function sortByNumberSeries(a, b) { 167 return a[0] - b[0]; 168 } 169 170 // needed since sort() without arguments does string comparison 171 function sortByNumber(a, b) { 172 return a - b; 173 } 174 175 function every(values, fn) { 176 for (var i = 0; i < values.length; i++) { 177 if (!fn(values[i])) { 178 return false;
vendor: 10,329 bytes, lines 179-580
179 } 180 } 181 return true; 182 } 183 184 function isDay(timeUnit) { 185 return timeUnit === "day" || timeUnit === "week" || timeUnit === "month" || timeUnit === "year"; 186 } 187 188 function calculateTimeUnit(values, maxDay) { 189 if ( maxDay === void 0 ) maxDay = false; 190 191 if (values.length === 0) { 192 return null; 193 } 194 195 var minute = every(values, function (d) { return d.getMilliseconds() === 0 && d.getSeconds() === 0; }); 196 if (!minute) { 197 return null; 198 } 199 200 var hour = every(values, function (d) { return d.getMinutes() === 0; }); 201 if (!hour) { 202 return "minute"; 203 } 204 205 var day = every(values, function (d) { return d.getHours() === 0; }); 206 if (!day) { 207 return "hour"; 208 } 209 210 if (maxDay) { 211 return "day"; 212 } 213 214 var dayOfWeek = values[0].getDay(); 215 var week = every(values, function (d) { return d.getDay() === dayOfWeek; }); 216 if (!week) { 217 return "day"; 218 } 219 220 var month = every(values, function (d) { return d.getDate() === 1; }); 221 if (!month) { 222 return "week"; 223 } 224 225 var year = every(values, function (d) { return d.getMonth() === 0; }); 226 if (!year) { 227 return "month"; 228 } 229 230 return "year"; 231 } 232 233 function isDate(obj) { 234 return !isNaN(toDate(obj)) && toStr(obj).length >= 6; 235 } 236 237 function isNumber(obj) { 238 return typeof obj === "number"; 239 } 240 241 var byteSuffixes = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB"]; 242 243 function formatValue(pre, value, options, axis) { 244 pre = pre || ""; 245 if (options.prefix) { 246 if (value < 0) { 247 value = value * -1; 248 pre += "-"; 249 } 250 pre += options.prefix; 251 } 252 253 var suffix = options.suffix || ""; 254 var precision = options.precision; 255 var round = options.round; 256 257 if (options.byteScale) { 258 var positive = value >= 0; 259 if (!positive) { 260 value *= -1; 261 } 262 263 var baseValue = axis ? options.byteScale : value; 264 265 var suffixIdx; 266 if (baseValue >= 1152921504606846976) { 267 value /= 1152921504606846976; 268 suffixIdx = 6; 269 } else if (baseValue >= 1125899906842624) { 270 value /= 1125899906842624; 271 suffixIdx = 5; 272 } else if (baseValue >= 1099511627776) { 273 value /= 1099511627776; 274 suffixIdx = 4; 275 } else if (baseValue >= 1073741824) { 276 value /= 1073741824; 277 suffixIdx = 3; 278 } else if (baseValue >= 1048576) { 279 value /= 1048576; 280 suffixIdx = 2; 281 } else if (baseValue >= 1024) { 282 value /= 1024; 283 suffixIdx = 1; 284 } else { 285 suffixIdx = 0; 286 } 287 288 // TODO handle manual precision case 289 if (precision === undefined && round === undefined) { 290 if (value >= 1023.5) { 291 if (suffixIdx < byteSuffixes.length - 1) { 292 value = 1.0; 293 suffixIdx += 1; 294 } 295 } 296 precision = value >= 1000 ? 4 : 3; 297 } 298 suffix = " " + byteSuffixes[suffixIdx]; 299 300 // flip value back 301 if (!positive) { 302 value *= -1; 303 } 304 } 305 306 if (precision !== undefined && round !== undefined) { 307 throw Error("Use either round or precision, not both"); 308 } 309 310 if (!axis) { 311 if (precision !== undefined) { 312 value = value.toPrecision(precision); 313 if (!options.zeros) { 314 value = parseFloat(value); 315 } 316 } 317 318 if (round !== undefined) { 319 if (round < 0) { 320 var num = Math.pow(10, -1 * round); 321 value = parseInt((1.0 * value / num).toFixed(0)) * num; 322 } else { 323 value = value.toFixed(round); 324 if (!options.zeros) { 325 value = parseFloat(value); 326 } 327 } 328 } 329 } 330 331 if (options.thousands || options.decimal) { 332 value = toStr(value); 333 var parts = value.split("."); 334 value = parts[0]; 335 if (options.thousands) { 336 value = value.replace(/\B(?=(\d{3})+(?!\d))/g, options.thousands); 337 } 338 if (parts.length > 1) { 339 value += (options.decimal || ".") + parts[1]; 340 } 341 } 342 343 return pre + value + suffix; 344 } 345 346 function seriesOption(chart, series, option) { 347 if (option in series) { 348 return series[option]; 349 } else if (option in chart.options) { 350 return chart.options[option]; 351 } 352 return null; 353 } 354 355 var baseOptions = { 356 maintainAspectRatio: false, 357 animation: false, 358 plugins: { 359 legend: {}, 360 tooltip: { 361 displayColors: false, 362 callbacks: {} 363 }, 364 title: { 365 font: { 366 size: 20 367 }, 368 color: "#333" 369 } 370 }, 371 interaction: {} 372 }; 373 374 var defaultOptions$2 = { 375 scales: { 376 y: { 377 ticks: { 378 maxTicksLimit: 4 379 }, 380 title: { 381 font: { 382 size: 16 383 }, 384 color: "#333" 385 }, 386 grid: {} 387 }, 388 x: { 389 grid: { 390 drawOnChartArea: false 391 }, 392 title: { 393 font: { 394 size: 16 395 }, 396 color: "#333" 397 }, 398 time: {}, 399 ticks: {} 400 } 401 } 402 }; 403 404 // http://there4.io/2012/05/02/google-chart-color-list/ 405 var defaultColors = [ 406 "#3366CC", "#DC3912", "#FF9900", "#109618", "#990099", "#3B3EAC", "#0099C6", 407 "#DD4477", "#66AA00", "#B82E2E", "#316395", "#994499", "#22AA99", "#AAAA11", 408 "#6633CC", "#E67300", "#8B0707", "#329262", "#5574A6", "#651067" 409 ]; 410 411 function hideLegend$2(options, legend, hideLegend) { 412 if (legend !== undefined) { 413 options.plugins.legend.display = !!legend; 414 if (legend && legend !== true) { 415 options.plugins.legend.position = legend; 416 } 417 } else if (hideLegend) { 418 options.plugins.legend.display = false; 419 } 420 } 421 422 function setTitle$2(options, title) { 423 options.plugins.title.display = true; 424 options.plugins.title.text = title; 425 } 426 427 function setMin$2(options, min) { 428 if (min !== null) { 429 options.scales.y.min = toFloat(min); 430 } 431 } 432 433 function setMax$2(options, max) { 434 options.scales.y.max = toFloat(max); 435 } 436 437 function setBarMin$1(options, min) { 438 if (min !== null) { 439 options.scales.x.min = toFloat(min); 440 } 441 } 442 443 function setBarMax$1(options, max) { 444 options.scales.x.max = toFloat(max); 445 } 446 447 function setStacked$2(options, stacked) { 448 options.scales.x.stacked = !!stacked; 449 options.scales.y.stacked = !!stacked; 450 } 451 452 function setXtitle$2(options, title) { 453 options.scales.x.title.display = true; 454 options.scales.x.title.text = title; 455 } 456 457 function setYtitle$2(options, title) { 458 options.scales.y.title.display = true; 459 options.scales.y.title.text = title; 460 } 461 462 // https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb 463 function addOpacity(hex, opacity) { 464 var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); 465 return result ? "rgba(" + parseInt(result[1], 16) + ", " + parseInt(result[2], 16) + ", " + parseInt(result[3], 16) + ", " + opacity + ")" : hex; 466 } 467 468 function notnull(x) { 469 return x !== null && x !== undefined; 470 } 471 472 function setLabelSize(chart, data, options) { 473 var maxLabelSize = Math.ceil(chart.element.offsetWidth / 4.0 / data.labels.length); 474 if (maxLabelSize > 25) { 475 maxLabelSize = 25; 476 } else if (maxLabelSize < 10) { 477 maxLabelSize = 10; 478 } 479 if (!options.scales.x.ticks.callback) { 480 options.scales.x.ticks.callback = function (value) { 481 value = toStr(this.getLabelForValue(value)); 482 if (value.length > maxLabelSize) { 483 return value.substring(0, maxLabelSize - 2) + "..."; 484 } else { 485 return value; 486 } 487 }; 488 } 489 } 490 491 function calculateScale(series) { 492 var scale = 1; 493 var max = maxAbsY(series); 494 while (max >= 1024) { 495 scale *= 1024; 496 max /= 1024; 497 } 498 return scale; 499 } 500 501 function setFormatOptions$1(chart, options, chartType) { 502 var formatOptions = { 503 prefix: chart.options.prefix, 504 suffix: chart.options.suffix, 505 thousands: chart.options.thousands, 506 decimal: chart.options.decimal, 507 precision: chart.options.precision, 508 round: chart.options.round, 509 zeros: chart.options.zeros 510 }; 511 512 if (chart.options.bytes) { 513 var series = chart.data; 514 if (chartType === "pie") { 515 series = [{data: series}]; 516 } 517 518 // set step size 519 formatOptions.byteScale = calculateScale(series); 520 } 521 522 if (chartType !== "pie") { 523 var axis = options.scales.y; 524 if (chartType === "bar") { 525 axis = options.scales.x; 526 } 527 528 if (formatOptions.byteScale) { 529 if (!axis.ticks.stepSize) { 530 axis.ticks.stepSize = formatOptions.byteScale / 2; 531 } 532 if (!axis.ticks.maxTicksLimit) { 533 axis.ticks.maxTicksLimit = 4; 534 } 535 } 536 537 if (!axis.ticks.callback) { 538 axis.ticks.callback = function (value) { 539 return formatValue("", value, formatOptions, true); 540 }; 541 } 542 } 543 544 if (!options.plugins.tooltip.callbacks.label) { 545 if (chartType === "scatter") { 546 options.plugins.tooltip.callbacks.label = function (context) { 547 var label = context.dataset.label || ''; 548 if (label) { 549 label += ': '; 550 } 551 552 return label + context.formattedValue; 553 }; 554 } else if (chartType === "bubble") { 555 options.plugins.tooltip.callbacks.label = function (context) { 556 var label = context.dataset.label || ''; 557 if (label) { 558 label += ': '; 559 } 560 var dataPoint = context.raw; 561 return label + '(' + dataPoint.x + ', ' + dataPoint.y + ', ' + dataPoint.v + ')'; 562 }; 563 } else if (chartType === "pie") { 564 // need to use separate label for pie charts 565 options.plugins.tooltip.callbacks.label = function (context) { 566 return formatValue('', context.parsed, formatOptions); 567 }; 568 } else { 569 var valueLabel = chartType === "bar" ? "x" : "y"; 570 options.plugins.tooltip.callbacks.label = function (context) { 571 // don't show null values for stacked charts 572 if (context.parsed[valueLabel] === null) { 573 return; 574 } 575 576 var label = context.dataset.label || ''; 577 if (label) { 578 label += ': '; 579 } 580 return formatValue(label, context.parsed[valueLabel], formatOptions
vendor: 8,448 bytes, lines 580-884
580); 581 }; 582 } 583 } 584 } 585 586 function maxAbsY(series) { 587 var max = 0; 588 for (var i = 0; i < series.length; i++) { 589 var data = series[i].data; 590 for (var j = 0; j < data.length; j++) { 591 var v = Math.abs(data[j][1]); 592 if (v > max) { 593 max = v; 594 } 595 } 596 } 597 return max; 598 } 599 600 function maxR(series) { 601 // start at zero since radius must be positive 602 var max = 0; 603 for (var i = 0; i < series.length; i++) { 604 var data = series[i].data; 605 for (var j = 0; j < data.length; j++) { 606 var v = data[j][2]; 607 if (v > max) { 608 max = v; 609 } 610 } 611 } 612 return max; 613 } 614 615 var jsOptions$2 = jsOptionsFunc(merge(baseOptions, defaultOptions$2), hideLegend$2, setTitle$2, setMin$2, setMax$2, setStacked$2, setXtitle$2, setYtitle$2); 616 617 function prepareDefaultData(chart) { 618 var series = chart.data; 619 var rows = {}; 620 var keys = []; 621 var labels = []; 622 var values = []; 623 624 for (var i = 0; i < series.length; i++) { 625 var data = series[i].data; 626 627 for (var j = 0; j < data.length; j++) { 628 var d = data[j]; 629 var key = chart.xtype === "datetime" ? d[0].getTime() : d[0]; 630 if (!rows[key]) { 631 rows[key] = new Array(series.length); 632 keys.push(key); 633 } 634 rows[key][i] = d[1]; 635 } 636 } 637 638 if (chart.xtype === "datetime" || chart.xtype === "number") { 639 keys.sort(sortByNumber); 640 } 641 642 for (var i$1 = 0; i$1 < series.length; i$1++) { 643 values.push([]); 644 } 645 646 for (var i$2 = 0; i$2 < keys.length; i$2++) { 647 var key$1 = keys[i$2]; 648 649 var label = chart.xtype === "datetime" ? new Date(key$1) : key$1; 650 labels.push(label); 651 652 var row = rows[key$1]; 653 for (var j$1 = 0; j$1 < series.length; j$1++) { 654 var v = row[j$1]; 655 // Chart.js doesn't like undefined 656 values[j$1].push(v === undefined ? null : v); 657 } 658 } 659 660 return { 661 labels: labels, 662 values: values 663 }; 664 } 665 666 function prepareBubbleData(chart) { 667 var series = chart.data; 668 var values = []; 669 var max = maxR(series); 670 671 for (var i = 0; i < series.length; i++) { 672 var data = series[i].data; 673 var points = []; 674 for (var j = 0; j < data.length; j++) { 675 var v = data[j]; 676 points.push({ 677 x: v[0], 678 y: v[1], 679 r: v[2] * 20 / max, 680 // custom attribute, for tooltip 681 v: v[2] 682 }); 683 } 684 values.push(points); 685 } 686 687 return { 688 labels: [], 689 values: values 690 }; 691 } 692 693 // scatter or numeric line/area 694 function prepareNumberData(chart) { 695 var series = chart.data; 696 var values = []; 697 698 for (var i = 0; i < series.length; i++) { 699 var data = series[i].data; 700 701 data.sort(sortByNumberSeries); 702 703 var points = []; 704 for (var j = 0; j < data.length; j++) { 705 var v = data[j]; 706 points.push({ 707 x: v[0], 708 y: v[1] 709 }); 710 } 711 values.push(points); 712 } 713 714 return { 715 labels: [], 716 values: values 717 }; 718 } 719 720 function prepareData(chart, chartType) { 721 if (chartType === "bubble") { 722 return prepareBubbleData(chart); 723 } else if (chart.xtype === "number" && chartType !== "bar" && chartType !== "column") { 724 return prepareNumberData(chart); 725 } else { 726 return prepareDefaultData(chart); 727 } 728 } 729 730 function createDataTable(chart, options, chartType) { 731 var ref = prepareData(chart, chartType); 732 var labels = ref.labels; 733 var values = ref.values; 734 735 var series = chart.data; 736 var datasets = []; 737 var colors = chart.options.colors || defaultColors; 738 for (var i = 0; i < series.length; i++) { 739 var s = series[i]; 740 741 // use colors for each bar for single series format 742 var color = (void 0); 743 var backgroundColor = (void 0); 744 if (chart.options.colors && chart.singleSeriesFormat && (chartType === "bar" || chartType === "column") && !s.color && isArray(chart.options.colors) && !isArray(chart.options.colors[0])) { 745 color = colors; 746 backgroundColor = []; 747 for (var j = 0; j < colors.length; j++) { 748 backgroundColor[j] = addOpacity(color[j], 0.5); 749 } 750 } else { 751 color = s.color || colors[i]; 752 backgroundColor = chartType !== "line" ? addOpacity(color, 0.5) : color; 753 } 754 755 var dataset = { 756 label: s.name || "", 757 data: values[i], 758 fill: chartType === "area", 759 borderColor: color, 760 backgroundColor: backgroundColor, 761 borderWidth: 2 762 }; 763 764 var pointChart = chartType === "line" || chartType === "area" || chartType === "scatter" || chartType === "bubble"; 765 if (pointChart) { 766 dataset.pointBackgroundColor = color; 767 dataset.pointHoverBackgroundColor = color; 768 dataset.pointHitRadius = 50; 769 } 770 771 if (chartType === "bubble") { 772 dataset.pointBackgroundColor = backgroundColor; 773 dataset.pointHoverBackgroundColor = backgroundColor; 774 dataset.pointHoverBorderWidth = 2; 775 } 776 777 if (s.stack) { 778 dataset.stack = s.stack; 779 } 780 781 var curve = seriesOption(chart, s, "curve"); 782 if (curve === false) { 783 dataset.tension = 0; 784 } else if (pointChart) { 785 dataset.tension = 0.4; 786 } 787 788 var points = seriesOption(chart, s, "points"); 789 if (points === false) { 790 dataset.pointRadius = 0; 791 dataset.pointHoverRadius = 0; 792 } 793 794 dataset = merge(dataset, chart.options.dataset || {}); 795 dataset = merge(dataset, s.library || {}); 796 dataset = merge(dataset, s.dataset || {}); 797 798 datasets.push(dataset); 799 } 800 801 var xmin = chart.options.xmin; 802 var xmax = chart.options.xmax; 803 804 if (chart.xtype === "datetime") { 805 if (notnull(xmin)) { 806 options.scales.x.min = toDate(xmin).getTime(); 807 } 808 if (notnull(xmax)) { 809 options.scales.x.max = toDate(xmax).getTime(); 810 } 811 } else if (chart.xtype === "number") { 812 if (notnull(xmin)) { 813 options.scales.x.min = xmin; 814 } 815 if (notnull(xmax)) { 816 options.scales.x.max = xmax; 817 } 818 } 819 820 if (chart.xtype === "datetime") { 821 var timeUnit = calculateTimeUnit(labels); 822 823 // for empty datetime chart 824 if (labels.length === 0) { 825 if (notnull(xmin)) { 826 labels.push(toDate(xmin)); 827 } 828 if (notnull(xmax)) { 829 labels.push(toDate(xmax)); 830 } 831 } 832 833 if (labels.length > 0) { 834 var minTime = (notnull(xmin) ? toDate(xmin) : labels[0]).getTime(); 835 var maxTime = (notnull(xmax) ? toDate(xmax) : labels[0]).getTime(); 836 837 for (var i$1 = 1; i$1 < labels.length; i$1++) { 838 var value = labels[i$1].getTime(); 839 if (value < minTime) { 840 minTime = value; 841 } 842 if (value > maxTime) { 843 maxTime = value; 844 } 845 } 846 847 var timeDiff = (maxTime - minTime) / (86400 * 1000.0); 848 849 if (!options.scales.x.time.unit) { 850 var step; 851 if (timeUnit === "year" || timeDiff > 365 * 10) { 852 options.scales.x.time.unit = "year"; 853 step = 365; 854 } else if (timeUnit === "month" || timeDiff > 30 * 10) { 855 options.scales.x.time.unit = "month"; 856 step = 30; 857 } else if (timeUnit === "week" || timeUnit === "day" || timeDiff > 10) { 858 options.scales.x.time.unit = "day"; 859 step = 1; 860 } else if (timeUnit === "hour" || timeDiff > 0.5) { 861 options.scales.x.time.displayFormats = {hour: "MMM d, h a"}; 862 options.scales.x.time.unit = "hour"; 863 step = 1 / 24.0; 864 } else if (timeUnit === "minute") { 865 options.scales.x.time.displayFormats = {minute: "h:mm a"}; 866 options.scales.x.time.unit = "minute"; 867 step = 1 / 24.0 / 60.0; 868 } 869 870 if (step && timeDiff > 0) { 871 // width not available for hidden elements 872 var width = chart.element.offsetWidth; 873 if (width > 0) { 874 var unitStepSize = Math.ceil(timeDiff / step / (width / 100.0)); 875 if (timeUnit === "week" && step === 1) { 876 unitStepSize = Math.ceil(unitStepSize / 7.0) * 7; 877 } 878 options.scales.x.ticks.stepSize = unitStepSize; 879 } 880 } 881 } 882 883 if (!options.scales.x.time.tooltipFormat) { 884 if (
884isDay(timeUnit)) { 885 options.scales.x.time.tooltipFormat = "PP"; 886 } else if (timeUnit === "hour") { 887 options.scales.x.time.tooltipFormat = "MMM d, h a"; 888 } else if (timeUnit === "minute") { 889 options.scales.x.time.tooltipFormat = "h:mm a"; 890 } 891 } 892 } 893 } 894 895 return { 896 labels: labels, 897 datasets: datasets 898 }; 899 } 900 901 var defaultExport$2 = function defaultExport(library) { 902 this.name = "chartjs"; 903 this.library = library; 904 }; 905 906 defaultExport$2.prototype.renderLineChart = function renderLineChart (chart, chartType) { 907 var chartOptions = {}; 908 909 var options = jsOptions$2(chart, merge(chartOptions, chart.options)); 910 setFormatOptions$1(chart, options, chartType); 911 912 var data = createDataTable(chart, options, chartType || "line"
vendor: 45,824 bytes, lines 912-2538
912); 913 914 if (chart.xtype === "number") { 915 options.scales.x.type = options.scales.x.type || "linear"; 916 options.scales.x.position = options.scales.x.position || "bottom"; 917 } else { 918 options.scales.x.type = chart.xtype === "string" ? "category" : "time"; 919 } 920 921 this.drawChart(chart, "line", data, options); 922 }; 923 924 defaultExport$2.prototype.renderPieChart = function renderPieChart (chart) { 925 var options = merge({}, baseOptions); 926 if (chart.options.donut) { 927 options.cutout = "50%"; 928 } 929 930 if ("legend" in chart.options) { 931 hideLegend$2(options, chart.options.legend); 932 } 933 934 if (chart.options.title) { 935 setTitle$2(options, chart.options.title); 936 } 937 938 options = merge(options, chart.options.library || {}); 939 setFormatOptions$1(chart, options, "pie"); 940 941 var labels = []; 942 var values = []; 943 for (var i = 0; i < chart.data.length; i++) { 944 var point = chart.data[i]; 945 labels.push(point[0]); 946 values.push(point[1]); 947 } 948 949 var dataset = { 950 data: values, 951 backgroundColor: chart.options.colors || defaultColors 952 }; 953 dataset = merge(dataset, chart.options.dataset || {}); 954 955 var data = { 956 labels: labels, 957 datasets: [dataset] 958 }; 959 960 this.drawChart(chart, "pie", data, options); 961 }; 962 963 defaultExport$2.prototype.renderColumnChart = function renderColumnChart (chart, chartType) { 964 var options; 965 if (chartType === "bar") { 966 var barOptions = merge(baseOptions, defaultOptions$2); 967 barOptions.indexAxis = "y"; 968 969 // ensure gridlines have proper orientation 970 barOptions.scales.x.grid.drawOnChartArea = true; 971 barOptions.scales.y.grid.drawOnChartArea = false; 972 delete barOptions.scales.y.ticks.maxTicksLimit; 973 974 options = jsOptionsFunc(barOptions, hideLegend$2, setTitle$2, setBarMin$1, setBarMax$1, setStacked$2, setXtitle$2, setYtitle$2)(chart, chart.options); 975 } else { 976 options = jsOptions$2(chart, chart.options); 977 } 978 setFormatOptions$1(chart, options, chartType); 979 var data = createDataTable(chart, options, "column"); 980 if (chartType !== "bar") { 981 setLabelSize(chart, data, options); 982 } 983 if (!("mode" in options.interaction)) { 984 options.interaction.mode = "index"; 985 } 986 this.drawChart(chart, "bar", data, options); 987 }; 988 989 defaultExport$2.prototype.renderAreaChart = function renderAreaChart (chart) { 990 this.renderLineChart(chart, "area"); 991 }; 992 993 defaultExport$2.prototype.renderBarChart = function renderBarChart (chart) { 994 this.renderColumnChart(chart, "bar"); 995 }; 996 997 defaultExport$2.prototype.renderScatterChart = function renderScatterChart (chart, chartType) { 998 chartType = chartType || "scatter"; 999 1000 var options = jsOptions$2(chart, chart.options); 1001 setFormatOptions$1(chart, options, chartType); 1002 1003 if (!("showLine" in options)) { 1004 options.showLine = false; 1005 } 1006 1007 var data = createDataTable(chart, options, chartType); 1008 1009 options.scales.x.type = options.scales.x.type || "linear"; 1010 options.scales.x.position = options.scales.x.position || "bottom"; 1011 1012 // prevent grouping hover and tooltips 1013 if (!("mode" in options.interaction)) { 1014 options.interaction.mode = "nearest"; 1015 } 1016 1017 this.drawChart(chart, chartType, data, options); 1018 }; 1019 1020 defaultExport$2.prototype.renderBubbleChart = function renderBubbleChart (chart) { 1021 this.renderScatterChart(chart, "bubble"); 1022 }; 1023 1024 defaultExport$2.prototype.destroy = function destroy (chart) { 1025 if (chart.chart) { 1026 chart.chart.destroy(); 1027 } 1028 }; 1029 1030 defaultExport$2.prototype.drawChart = function drawChart (chart, type, data, options) { 1031 this.destroy(chart); 1032 if (chart.destroyed) { return; } 1033 1034 var chartOptions = { 1035 type: type, 1036 data: data, 1037 options: options 1038 }; 1039 1040 if (chart.options.code) { 1041 window.console.log("new Chart(ctx, " + JSON.stringify(chartOptions) + ");"); 1042 } 1043 1044 chart.element.innerHTML = "<canvas></canvas>"; 1045 var ctx = chart.element.getElementsByTagName("CANVAS")[0]; 1046 chart.chart = new this.library(ctx, chartOptions); 1047 }; 1048 1049 var defaultOptions$1 = { 1050 chart: {}, 1051 xAxis: { 1052 title: { 1053 text: null 1054 }, 1055 labels: { 1056 style: { 1057 fontSize: "12px" 1058 } 1059 } 1060 }, 1061 yAxis: { 1062 title: { 1063 text: null 1064 }, 1065 labels: { 1066 style: { 1067 fontSize: "12px" 1068 } 1069 } 1070 }, 1071 title: { 1072 text: null 1073 }, 1074 credits: { 1075 enabled: false 1076 }, 1077 legend: { 1078 borderWidth: 0 1079 }, 1080 tooltip: { 1081 style: { 1082 fontSize: "12px" 1083 } 1084 }, 1085 plotOptions: { 1086 areaspline: {}, 1087 area: {}, 1088 series: { 1089 marker: {} 1090 } 1091 }, 1092 time: { 1093 useUTC: false 1094 } 1095 }; 1096 1097 function hideLegend$1(options, legend, hideLegend) { 1098 if (legend !== undefined) { 1099 options.legend.enabled = !!legend; 1100 if (legend && legend !== true) { 1101 if (legend === "top" || legend === "bottom") { 1102 options.legend.verticalAlign = legend; 1103 } else { 1104 options.legend.layout = "vertical"; 1105 options.legend.verticalAlign = "middle"; 1106 options.legend.align = legend; 1107 } 1108 } 1109 } else if (hideLegend) { 1110 options.legend.enabled = false; 1111 } 1112 } 1113 1114 function setTitle$1(options, title) { 1115 options.title.text = title; 1116 } 1117 1118 function setMin$1(options, min) { 1119 options.yAxis.min = min; 1120 } 1121 1122 function setMax$1(options, max) { 1123 options.yAxis.max = max; 1124 } 1125 1126 function setStacked$1(options, stacked) { 1127 var stackedValue = stacked ? (stacked === true ? "normal" : stacked) : null; 1128 options.plotOptions.series.stacking = stackedValue; 1129 options.plotOptions.area.stacking = stackedValue; 1130 options.plotOptions.areaspline.stacking = stackedValue; 1131 } 1132 1133 function setXtitle$1(options, title) { 1134 options.xAxis.title.text = title; 1135 } 1136 1137 function setYtitle$1(options, title) { 1138 options.yAxis.title.text = title; 1139 } 1140 1141 var jsOptions$1 = jsOptionsFunc(defaultOptions$1, hideLegend$1, setTitle$1, setMin$1, setMax$1, setStacked$1, setXtitle$1, setYtitle$1); 1142 1143 function setFormatOptions(chart, options, chartType) { 1144 var formatOptions = { 1145 prefix: chart.options.prefix, 1146 suffix: chart.options.suffix, 1147 thousands: chart.options.thousands, 1148 decimal: chart.options.decimal, 1149 precision: chart.options.precision, 1150 round: chart.options.round, 1151 zeros: chart.options.zeros 1152 }; 1153 1154 // skip when axis is an array (like with min/max) 1155 if (chartType !== "pie" && !isArray(options.yAxis) && !options.yAxis.labels.formatter) { 1156 options.yAxis.labels.formatter = function () { 1157 return formatValue("", this.value, formatOptions); 1158 }; 1159 } 1160 1161 if (!options.tooltip.pointFormatter && !options.tooltip.pointFormat) { 1162 options.tooltip.pointFormatter = function () { 1163 return '<span style="color:' + this.color + '">\u25CF</span> ' + formatValue(this.series.name + ': <b>', this.y, formatOptions) + '</b><br/>'; 1164 }; 1165 } 1166 } 1167 1168 var defaultExport$1 = function defaultExport(library) { 1169 this.name = "highcharts"; 1170 this.library = library; 1171 }; 1172 1173 defaultExport$1.prototype.renderLineChart = function renderLineChart (chart, chartType) { 1174 chartType = chartType || "spline"; 1175 var chartOptions = {}; 1176 if (chartType === "areaspline") { 1177 chartOptions = { 1178 plotOptions: { 1179 areaspline: { 1180 stacking: "normal" 1181 }, 1182 area: { 1183 stacking: "normal" 1184 }, 1185 series: { 1186 marker: { 1187 enabled: false 1188 } 1189 } 1190 } 1191 }; 1192 } 1193 1194 if (chart.options.curve === false) { 1195 if (chartType === "areaspline") { 1196 chartType = "area"; 1197 } else if (chartType === "spline") { 1198 chartType = "line"; 1199 } 1200 } 1201 1202 var options = jsOptions$1(chart, chart.options, chartOptions); 1203 if (chart.xtype === "number") { 1204 options.xAxis.type = options.xAxis.type || "linear"; 1205 } else { 1206 options.xAxis.type = chart.xtype === "string" ? "category" : "datetime"; 1207 } 1208 if (!options.chart.type) { 1209 options.chart.type = chartType; 1210 } 1211 setFormatOptions(chart, options, chartType); 1212 1213 var series = chart.data; 1214 for (var i = 0; i < series.length; i++) { 1215 series[i].name = series[i].name || "Value"; 1216 var data = series[i].data; 1217 if (chart.xtype === "datetime") { 1218 for (var j = 0; j < data.length; j++) { 1219 data[j][0] = data[j][0].getTime(); 1220 } 1221 } else if (chart.xtype === "number") { 1222 data.sort(sortByNumberSeries); 1223 } 1224 series[i].marker = {symbol: "circle"}; 1225 if (chart.options.points === false) { 1226 series[i].marker.enabled = false; 1227 } 1228 } 1229 1230 this.drawChart(chart, series, options); 1231 }; 1232 1233 defaultExport$1.prototype.renderScatterChart = function renderScatterChart (chart) { 1234 var options = jsOptions$1(chart, chart.options, {}); 1235 options.chart.type = "scatter"; 1236 this.drawChart(chart, chart.data, options); 1237 }; 1238 1239 defaultExport$1.prototype.renderPieChart = function renderPieChart (chart) { 1240 var chartOptions = merge(defaultOptions$1, {}); 1241 1242 if (chart.options.colors) { 1243 chartOptions.colors = chart.options.colors; 1244 } 1245 if (chart.options.donut) { 1246 chartOptions.plotOptions = {pie: {innerSize: "50%"}}; 1247 } 1248 1249 if ("legend" in chart.options) { 1250 hideLegend$1(chartOptions, chart.options.legend); 1251 } 1252 1253 if (chart.options.title) { 1254 setTitle$1(chartOptions, chart.options.title); 1255 } 1256 1257 var options = merge(chartOptions, chart.options.library || {}); 1258 setFormatOptions(chart, options, "pie"); 1259 var series = [{ 1260 type: "pie", 1261 name: chart.options.label || "Value", 1262 data: chart.data 1263 }]; 1264 1265 this.drawChart(chart, series, options); 1266 }; 1267 1268 defaultExport$1.prototype.renderColumnChart = function renderColumnChart (chart, chartType) { 1269 chartType = chartType || "column"; 1270 var series = chart.data; 1271 var options = jsOptions$1(chart, chart.options); 1272 var rows = []; 1273 var categories = []; 1274 options.chart.type = chartType; 1275 setFormatOptions(chart, options, chartType); 1276 1277 for (var i = 0; i < series.length; i++) { 1278 var s = series[i]; 1279 1280 for (var j = 0; j < s.data.length; j++) { 1281 var d = s.data[j]; 1282 if (!rows[d[0]]) { 1283 rows[d[0]] = new Array(series.length); 1284 categories.push(d[0]); 1285 } 1286 rows[d[0]][i] = d[1]; 1287 } 1288 } 1289 1290 if (chart.xtype === "number") { 1291 categories.sort(sortByNumber); 1292 } 1293 1294 options.xAxis.categories = categories; 1295 1296 var newSeries = []; 1297 for (var i$1 = 0; i$1 < series.length; i$1++) { 1298 var d$1 = []; 1299 for (var j$1 = 0; j$1 < categories.length; j$1++) { 1300 d$1.push(rows[categories[j$1]][i$1] || 0); 1301 } 1302 1303 var d2 = { 1304 name: series[i$1].name || "Value", 1305 data: d$1 1306 }; 1307 if (series[i$1].stack) { 1308 d2.stack = series[i$1].stack; 1309 } 1310 1311 newSeries.push(d2); 1312 } 1313 1314 this.drawChart(chart, newSeries, options); 1315 }; 1316 1317 defaultExport$1.prototype.renderBarChart = function renderBarChart (chart) { 1318 this.renderColumnChart(chart, "bar"); 1319 }; 1320 1321 defaultExport$1.prototype.renderAreaChart = function renderAreaChart (chart) { 1322 this.renderLineChart(chart, "areaspline"); 1323 }; 1324 1325 defaultExport$1.prototype.destroy = function destroy (chart) { 1326 if (chart.chart) { 1327 chart.chart.destroy(); 1328 } 1329 }; 1330 1331 defaultExport$1.prototype.drawChart = function drawChart (chart, data, options) { 1332 this.destroy(chart); 1333 if (chart.destroyed) { return; } 1334 1335 options.chart.renderTo = chart.element.id; 1336 options.series = data; 1337 1338 if (chart.options.code) { 1339 window.console.log("new Highcharts.Chart(" + JSON.stringify(options) + ");"); 1340 } 1341 1342 chart.chart = new this.library.Chart(options); 1343 }; 1344 1345 var loaded = {}; 1346 var callbacks = []; 1347 1348 // Set chart options 1349 var defaultOptions = { 1350 chartArea: {}, 1351 fontName: "'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif", 1352 pointSize: 6, 1353 legend: { 1354 textStyle: { 1355 fontSize: 12, 1356 color: "#444" 1357 }, 1358 alignment: "center", 1359 position: "right" 1360 }, 1361 curveType: "function", 1362 hAxis: { 1363 textStyle: { 1364 color: "#666", 1365 fontSize: 12 1366 }, 1367 titleTextStyle: {}, 1368 gridlines: { 1369 color: "transparent" 1370 }, 1371 baselineColor: "#ccc", 1372 viewWindow: {} 1373 }, 1374 vAxis: { 1375 textStyle: { 1376 color: "#666", 1377 fontSize: 12 1378 }, 1379 titleTextStyle: {}, 1380 baselineColor: "#ccc", 1381 viewWindow: {} 1382 }, 1383 tooltip: { 1384 textStyle: { 1385 color: "#666", 1386 fontSize: 12 1387 } 1388 } 1389 }; 1390 1391 function hideLegend(options, legend, hideLegend) { 1392 if (legend !== undefined) { 1393 var position; 1394 if (!legend) { 1395 position = "none"; 1396 } else if (legend === true) { 1397 position = "right"; 1398 } else { 1399 position = legend; 1400 } 1401 options.legend.position = position; 1402 } else if (hideLegend) { 1403 options.legend.position = "none"; 1404 } 1405 } 1406 1407 function setTitle(options, title) { 1408 options.title = title; 1409 options.titleTextStyle = {color: "#333", fontSize: "20px"}; 1410 } 1411 1412 function setMin(options, min) { 1413 options.vAxis.viewWindow.min = min; 1414 } 1415 1416 function setMax(options, max) { 1417 options.vAxis.viewWindow.max = max; 1418 } 1419 1420 function setBarMin(options, min) { 1421 options.hAxis.viewWindow.min = min; 1422 } 1423 1424 function setBarMax(options, max) { 1425 options.hAxis.viewWindow.max = max; 1426 } 1427 1428 function setStacked(options, stacked) { 1429 options.isStacked = stacked || false; 1430 } 1431 1432 function setXtitle(options, title) { 1433 options.hAxis.title = title; 1434 options.hAxis.titleTextStyle.italic = false; 1435 } 1436 1437 function setYtitle(options, title) { 1438 options.vAxis.title = title; 1439 options.vAxis.titleTextStyle.italic = false; 1440 } 1441 1442 var jsOptions = jsOptionsFunc(defaultOptions, hideLegend, setTitle, setMin, setMax, setStacked, setXtitle, setYtitle); 1443 1444 function resize(callback) { 1445 if (window.attachEvent) { 1446 window.attachEvent("onresize", callback); 1447 } else if (window.addEventListener) { 1448 window.addEventListener("resize", callback, true); 1449 } 1450 callback(); 1451 } 1452 1453 var defaultExport = function defaultExport(library) { 1454 this.name = "google"; 1455 this.library = library; 1456 }; 1457 1458 defaultExport.prototype.renderLineChart = function renderLineChart (chart) { 1459 var this$1$1 = this; 1460 1461 this.waitForLoaded(chart, function () { 1462 var chartOptions = {}; 1463 1464 if (chart.options.curve === false) { 1465 chartOptions.curveType = "none"; 1466 } 1467 1468 if (chart.options.points === false) { 1469 chartOptions.pointSize = 0; 1470 } 1471 1472 var options = jsOptions(chart, chart.options, chartOptions); 1473 var data = this$1$1.createDataTable(chart.data, chart.xtype); 1474 1475 this$1$1.drawChart(chart, "LineChart", data, options); 1476 }); 1477 }; 1478 1479 defaultExport.prototype.renderPieChart = function renderPieChart (chart) { 1480 var this$1$1 = this; 1481 1482 this.waitForLoaded(chart, function () { 1483 var chartOptions = { 1484 chartArea: { 1485 top: "10%", 1486 height: "80%" 1487 }, 1488 legend: {} 1489 }; 1490 if (chart.options.colors) { 1491 chartOptions.colors = chart.options.colors; 1492 } 1493 if (chart.options.donut) { 1494 chartOptions.pieHole = 0.5; 1495 } 1496 if ("legend" in chart.options) { 1497 hideLegend(chartOptions, chart.options.legend); 1498 } 1499 if (chart.options.title) { 1500 setTitle(chartOptions, chart.options.title); 1501 } 1502 var options = merge(merge(defaultOptions, chartOptions), chart.options.library || {}); 1503 1504 var data = new this$1$1.library.visualization.DataTable(); 1505 data.addColumn("string", ""); 1506 data.addColumn("number", "Value"); 1507 data.addRows(chart.data); 1508 1509 this$1$1.drawChart(chart, "PieChart", data, options); 1510 }); 1511 }; 1512 1513 defaultExport.prototype.renderColumnChart = function renderColumnChart (chart) { 1514 var this$1$1 = this; 1515 1516 this.waitForLoaded(chart, function () { 1517 var options = jsOptions(chart, chart.options); 1518 var data = this$1$1.createDataTable(chart.data, chart.xtype); 1519 1520 this$1$1.drawChart(chart, "ColumnChart", data, options); 1521 }); 1522 }; 1523 1524 defaultExport.prototype.renderBarChart = function renderBarChart (chart) { 1525 var this$1$1 = this; 1526 1527 this.waitForLoaded(chart, function () { 1528 var chartOptions = { 1529 hAxis: { 1530 gridlines: { 1531 color: "#ccc" 1532 } 1533 } 1534 }; 1535 var options = jsOptionsFunc(defaultOptions, hideLegend, setTitle, setBarMin, setBarMax, setStacked, setXtitle, setYtitle)(chart, chart.options, chartOptions); 1536 var data = this$1$1.createDataTable(chart.data, chart.xtype); 1537 1538 this$1$1.drawChart(chart, "BarChart", data, options); 1539 }); 1540 }; 1541 1542 defaultExport.prototype.renderAreaChart = function renderAreaChart (chart) { 1543 var this$1$1 = this; 1544 1545 this.waitForLoaded(chart, function () { 1546 var chartOptions = { 1547 isStacked: true, 1548 pointSize: 0, 1549 areaOpacity: 0.5 1550 }; 1551 1552 var options = jsOptions(chart, chart.options, chartOptions); 1553 var data = this$1$1.createDataTable(chart.data, chart.xtype); 1554 1555 this$1$1.drawChart(chart, "AreaChart", data, options); 1556 }); 1557 }; 1558 1559 defaultExport.prototype.renderGeoChart = function renderGeoChart (chart) { 1560 var this$1$1 = this; 1561 1562 this.waitForLoaded(chart, "geochart", function () { 1563 var chartOptions = { 1564 legend: "none", 1565 colorAxis: { 1566 colors: chart.options.colors || ["#f6c7b6", "#ce502d"] 1567 } 1568 }; 1569 var options = merge(merge(defaultOptions, chartOptions), chart.options.library || {}); 1570 1571 var data = new this$1$1.library.visualization.DataTable(); 1572 data.addColumn("string", ""); 1573 data.addColumn("number", chart.options.label || "Value"); 1574 data.addRows(chart.data); 1575 1576 this$1$1.drawChart(chart, "GeoChart", data, options); 1577 }); 1578 }; 1579 1580 defaultExport.prototype.renderScatterChart = function renderScatterChart (chart) { 1581 var this$1$1 = this; 1582 1583 this.waitForLoaded(chart, function () { 1584 var chartOptions = {}; 1585 var options = jsOptions(chart, chart.options, chartOptions); 1586 1587 var series = chart.data; 1588 var rows2 = []; 1589 for (var i = 0; i < series.length; i++) { 1590 series[i].name = series[i].name || "Value"; 1591 var d = series[i].data; 1592 for (var j = 0; j < d.length; j++) { 1593 var row = new Array(series.length + 1); 1594 row[0] = d[j][0]; 1595 row[i + 1] = d[j][1]; 1596 rows2.push(row); 1597 } 1598 } 1599 1600 var data = new this$1$1.library.visualization.DataTable(); 1601 data.addColumn("number", ""); 1602 for (var i$1 = 0; i$1 < series.length; i$1++) { 1603 data.addColumn("number", series[i$1].name); 1604 } 1605 data.addRows(rows2); 1606 1607 this$1$1.drawChart(chart, "ScatterChart", data, options); 1608 }); 1609 }; 1610 1611 defaultExport.prototype.renderTimeline = function renderTimeline (chart) { 1612 var this$1$1 = this; 1613 1614 this.waitForLoaded(chart, "timeline", function () { 1615 var chartOptions = { 1616 legend: "none" 1617 }; 1618 1619 if (chart.options.colors) { 1620 chartOptions.colors = chart.options.colors; 1621 } 1622 var options = merge(merge(defaultOptions, chartOptions), chart.options.library || {}); 1623 1624 var data = new this$1$1.library.visualization.DataTable(); 1625 data.addColumn({type: "string", id: "Name"}); 1626 data.addColumn({type: "date", id: "Start"}); 1627 data.addColumn({type: "date", id: "End"}); 1628 data.addRows(chart.data); 1629 1630 chart.element.style.lineHeight = "normal"; 1631 1632 this$1$1.drawChart(chart, "Timeline", data, options); 1633 }); 1634 }; 1635 1636 // TODO remove resize events 1637 defaultExport.prototype.destroy = function destroy (chart) { 1638 if (chart.chart) { 1639 chart.chart.clearChart(); 1640 } 1641 }; 1642 1643 defaultExport.prototype.drawChart = function drawChart (chart, type, data, options) { 1644 this.destroy(chart); 1645 if (chart.destroyed) { return; } 1646 1647 if (chart.options.code) { 1648 window.console.log("var data = new google.visualization.DataTable(" + data.toJSON() + ");\nvar chart = new google.visualization." + type + "(element);\nchart.draw(data, " + JSON.stringify(options) + ");"); 1649 } 1650 1651 chart.chart = new this.library.visualization[type](chart.element); 1652 resize(function () { 1653 chart.chart.draw(data, options); 1654 }); 1655 }; 1656 1657 defaultExport.prototype.waitForLoaded = function waitForLoaded (chart, pack, callback) { 1658 var this$1$1 = this; 1659 1660 if (!callback) { 1661 callback = pack; 1662 pack = "corechart"; 1663 } 1664 1665 callbacks.push({pack: pack, callback: callback}); 1666 1667 if (loaded[pack]) { 1668 this.runCallbacks(); 1669 } else { 1670 loaded[pack] = true; 1671 1672 // https://groups.google.com/forum/#!topic/google-visualization-api/fMKJcyA2yyI 1673 var loadOptions = { 1674 packages: [pack], 1675 callback: function () { this$1$1.runCallbacks(); } 1676 }; 1677 var config = chart.__config(); 1678 if (config.language) { 1679 loadOptions.language = config.language; 1680 } 1681 if (pack === "geochart" && config.mapsApiKey) { 1682 loadOptions.mapsApiKey = config.mapsApiKey; 1683 } 1684 1685 this.library.charts.load("current", loadOptions); 1686 } 1687 }; 1688 1689 defaultExport.prototype.runCallbacks = function runCallbacks () { 1690 for (var i = 0; i < callbacks.length; i++) { 1691 var cb = callbacks[i]; 1692 var call = this.library.visualization && ((cb.pack === "corechart" && this.library.visualization.LineChart) || (cb.pack === "timeline" && this.library.visualization.Timeline) || (cb.pack === "geochart" && this.library.visualization.GeoChart)); 1693 if (call) { 1694 cb.callback(); 1695 callbacks.splice(i, 1); 1696 i--; 1697 } 1698 } 1699 }; 1700 1701 // cant use object as key 1702 defaultExport.prototype.createDataTable = function createDataTable (series, columnType) { 1703 var rows = []; 1704 var sortedLabels = []; 1705 for (var i = 0; i < series.length; i++) { 1706 var s = series[i]; 1707 series[i].name = series[i].name || "Value"; 1708 1709 for (var j = 0; j < s.data.length; j++) { 1710 var d = s.data[j]; 1711 var key = columnType === "datetime" ? d[0].getTime() : d[0]; 1712 if (!rows[key]) { 1713 rows[key] = new Array(series.length); 1714 sortedLabels.push(key); 1715 } 1716 rows[key][i] = d[1]; 1717 } 1718 } 1719 1720 var rows2 = []; 1721 var values = []; 1722 for (var j$1 = 0; j$1 < sortedLabels.length; j$1++) { 1723 var i$1 = sortedLabels[j$1]; 1724 var value = (void 0); 1725 if (columnType === "datetime") { 1726 value = new Date(i$1); 1727 values.push(value); 1728 } else { 1729 value = i$1; 1730 } 1731 rows2.push([value].concat(rows[i$1])); 1732 } 1733 1734 var day = true; 1735 if (columnType === "datetime") { 1736 rows2.sort(sortByTime); 1737 1738 var timeUnit = calculateTimeUnit(values, true); 1739 day = isDay(timeUnit); 1740 } else if (columnType === "number") { 1741 rows2.sort(sortByNumberSeries); 1742 1743 for (var i$2 = 0; i$2 < rows2.length; i$2++) { 1744 rows2[i$2][0] = toStr(rows2[i$2][0]); 1745 } 1746 1747 columnType = "string"; 1748 } 1749 1750 // create datatable 1751 var data = new this.library.visualization.DataTable(); 1752 columnType = columnType === "datetime" && day ? "date" : columnType; 1753 data.addColumn(columnType, ""); 1754 for (var i$3 = 0; i$3 < series.length; i$3++) { 1755 data.addColumn("number", series[i$3].name); 1756 } 1757 data.addRows(rows2); 1758 1759 return data; 1760 }; 1761 1762 var adapters = []; 1763 1764 function getAdapterType(library) { 1765 if (library) { 1766 if (library.product === "Highcharts") { 1767 return defaultExport$1; 1768 } else if (library.charts) { 1769 return defaultExport; 1770 } else if (isFunction(library)) { 1771 return defaultExport$2; 1772 } 1773 } 1774 throw new Error("Unknown adapter"); 1775 } 1776 1777 function addAdapter(library) { 1778 var adapterType = getAdapterType(library); 1779 1780 for (var i = 0; i < adapters.length; i++) { 1781 if (adapters[i].library === library) { 1782 return; 1783 } 1784 } 1785 1786 adapters.push(new adapterType(library)); 1787 } 1788 1789 function loadAdapters() { 1790 if ("Chart" in window) { 1791 addAdapter(window.Chart); 1792 } 1793 1794 if ("Highcharts" in window) { 1795 addAdapter(window.Highcharts); 1796 } 1797 1798 if (window.google && window.google.charts) { 1799 addAdapter(window.google); 1800 } 1801 } 1802 1803 // TODO remove chartType if cross-browser way 1804 // to get the name of the chart class 1805 function callAdapter(chartType, chart) { 1806 var fnName = "render" + chartType; 1807 var adapterName = chart.options.adapter; 1808 1809 loadAdapters(); 1810 1811 for (var i = 0; i < adapters.length; i++) { 1812 var adapter = adapters[i]; 1813 if ((!adapterName || adapterName === adapter.name) && isFunction(adapter[fnName])) { 1814 chart.adapter = adapter.name; 1815 chart.__adapterObject = adapter; 1816 return adapter[fnName](chart); 1817 } 1818 } 1819 1820 if (adapters.length > 0) { 1821 throw new Error("No charting library found for " + chartType); 1822 } else { 1823 throw new Error("No charting libraries found - be sure to include one before your charts"); 1824 } 1825 } 1826 1827 var Chartkick = { 1828 charts: {}, 1829 configure: function (options) { 1830 for (var key in options) { 1831 if (Object.prototype.hasOwnProperty.call(options, key)) { 1832 Chartkick.config[key] = options[key]; 1833 } 1834 } 1835 }, 1836 setDefaultOptions: function (opts) { 1837 Chartkick.options = opts; 1838 }, 1839 eachChart: function (callback) { 1840 for (var chartId in Chartkick.charts) { 1841 if (Object.prototype.hasOwnProperty.call(Chartkick.charts, chartId)) { 1842 callback(Chartkick.charts[chartId]); 1843 } 1844 } 1845 }, 1846 destroyAll: function () { 1847 for (var chartId in Chartkick.charts) { 1848 if (Object.prototype.hasOwnProperty.call(Chartkick.charts, chartId)) { 1849 Chartkick.charts[chartId].destroy(); 1850 delete Chartkick.charts[chartId]; 1851 } 1852 } 1853 }, 1854 config: {}, 1855 options: {}, 1856 adapters: adapters, 1857 addAdapter: addAdapter, 1858 use: function (adapter) { 1859 addAdapter(adapter); 1860 return Chartkick; 1861 } 1862 }; 1863 1864 function formatSeriesBubble(data) { 1865 var r = []; 1866 for (var i = 0; i < data.length; i++) { 1867 r.push([toFloat(data[i][0]), toFloat(data[i][1]), toFloat(data[i][2])]); 1868 } 1869 return r; 1870 } 1871 1872 // casts data to proper type 1873 // sorting is left to adapters 1874 function formatSeriesData(data, keyType) { 1875 if (keyType === "bubble") { 1876 return formatSeriesBubble(data); 1877 } 1878 1879 var keyFunc; 1880 if (keyType === "number") { 1881 keyFunc = toFloat; 1882 } else if (keyType === "datetime") { 1883 keyFunc = toDate; 1884 } else { 1885 keyFunc = toStr; 1886 } 1887 1888 var r = []; 1889 for (var i = 0; i < data.length; i++) { 1890 r.push([keyFunc(data[i][0]), toFloat(data[i][1])]); 1891 } 1892 return r; 1893 } 1894 1895 function detectXType(series, noDatetime, options) { 1896 if (dataEmpty(series)) { 1897 if ((options.xmin || options.xmax) && (!options.xmin || isDate(options.xmin)) && (!options.xmax || isDate(options.xmax))) { 1898 return "datetime"; 1899 } else { 1900 return "number"; 1901 } 1902 } else if (detectXTypeWithFunction(series, isNumber)) { 1903 return "number"; 1904 } else if (!noDatetime && detectXTypeWithFunction(series, isDate)) { 1905 return "datetime"; 1906 } else { 1907 return "string"; 1908 } 1909 } 1910 1911 function detectXTypeWithFunction(series, func) { 1912 for (var i = 0; i < series.length; i++) { 1913 var data = toArr(series[i].data); 1914 for (var j = 0; j < data.length; j++) { 1915 if (!func(data[j][0])) { 1916 return false; 1917 } 1918 } 1919 } 1920 return true; 1921 } 1922 1923 // creates a shallow copy of each element of the array 1924 // elements are expected to be objects 1925 function copySeries(series) { 1926 var newSeries = []; 1927 for (var i = 0; i < series.length; i++) { 1928 var copy = {}; 1929 for (var j in series[i]) { 1930 if (Object.prototype.hasOwnProperty.call(series[i], j)) { 1931 copy[j] = series[i][j]; 1932 } 1933 } 1934 newSeries.push(copy); 1935 } 1936 return newSeries; 1937 } 1938 1939 function processSeries(chart, keyType, noDatetime) { 1940 var opts = chart.options; 1941 var series = chart.rawData; 1942 1943 // see if one series or multiple 1944 chart.singleSeriesFormat = !isArray(series) || !isPlainObject(series[0]); 1945 if (chart.singleSeriesFormat) { 1946 series = [{name: opts.label, data: series}]; 1947 } 1948 1949 // convert to array 1950 // must come before dataEmpty check 1951 series = copySeries(series); 1952 for (var i = 0; i < series.length; i++) { 1953 series[i].data = toArr(series[i].data); 1954 } 1955 1956 chart.xtype = keyType || (opts.discrete ? "string" : detectXType(series, noDatetime, opts)); 1957 1958 // right format 1959 for (var i$1 = 0; i$1 < series.length; i$1++) { 1960 series[i$1].data = formatSeriesData(series[i$1].data, chart.xtype); 1961 } 1962 1963 return series; 1964 } 1965 1966 function processSimple(chart) { 1967 var perfectData = toArr(chart.rawData); 1968 for (var i = 0; i < perfectData.length; i++) { 1969 perfectData[i] = [toStr(perfectData[i][0]), toFloat(perfectData[i][1])]; 1970 } 1971 return perfectData; 1972 } 1973 1974 function dataEmpty(data, chartType) { 1975 if (chartType === "PieChart" || chartType === "GeoChart" || chartType === "Timeline") { 1976 return data.length === 0; 1977 } else { 1978 for (var i = 0; i < data.length; i++) { 1979 if (data[i].data.length > 0) { 1980 return false; 1981 } 1982 } 1983 return true; 1984 } 1985 } 1986 1987 function addDownloadButton(chart) { 1988 var download = chart.options.download; 1989 if (download === true) { 1990 download = {}; 1991 } else if (typeof download === "string") { 1992 download = {filename: download}; 1993 } 1994 1995 var link = document.createElement("a"); 1996 link.download = download.filename || "chart.png"; 1997 link.style.position = "absolute"; 1998 link.style.top = "20px"; 1999 link.style.right = "20px"; 2000 link.style.zIndex = 1000; 2001 link.style.lineHeight = "20px"; 2002 link.target = "_blank"; // for safari 2003 2004 var image = document.createElement("img"); 2005 // icon from Font Awesome, modified to set fill color 2006 var svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 512 512\"><!--! Font Awesome Free 6.2.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path fill=\"#CCCCCC\" d=\"M344 240h-56L287.1 152c0-13.25-10.75-24-24-24h-16C234.7 128 223.1 138.8 223.1 152L224 240h-56c-9.531 0-18.16 5.656-22 14.38C142.2 263.1 143.9 273.3 150.4 280.3l88.75 96C243.7 381.2 250.1 384 256.8 384c7.781-.3125 13.25-2.875 17.75-7.844l87.25-96c6.406-7.031 8.031-17.19 4.188-25.88S353.5 240 344 240zM256 0C114.6 0 0 114.6 0 256s114.6 256 256 256s256-114.6 256-256S397.4 0 256 0zM256 464c-114.7 0-208-93.31-208-208S141.3 48 256 48s208 93.31 208 208S370.7 464 256 464z\"/></svg>"; 2007 image.src = "data:image/svg+xml;utf8," + (encodeURIComponent(svg)); 2008 image.alt = "Download"; 2009 image.style.width = "20px"; 2010 image.style.height = "20px"; 2011 image.style.border = "none"; 2012 link.appendChild(image); 2013 2014 var element = chart.element; 2015 element.style.position = "relative"; 2016 2017 chart.__downloadAttached = true; 2018 2019 // mouseenter 2020 chart.__enterEvent = element.addEventListener("mouseover", function (e) { 2021 var related = e.relatedTarget; 2022 // check download option again to ensure it wasn't changed 2023 if ((!related || (related !== this && !this.contains(related))) && chart.options.download) { 2024 link.href = chart.toImage(download); 2025 element.appendChild(link); 2026 } 2027 }); 2028 2029 // mouseleave 2030 chart.__leaveEvent = element.addEventListener("mouseout", function (e) { 2031 var related = e.relatedTarget; 2032 if (!related || (related !== this && !this.contains(related))) { 2033 if (link.parentNode) { 2034 link.parentNode.removeChild(link); 2035 } 2036 } 2037 }); 2038 } 2039 2040 var pendingRequests = []; 2041 var runningRequests = 0; 2042 var maxRequests = 4; 2043 2044 function pushRequest(url, success, error) { 2045 pendingRequests.push([url, success, error]); 2046 runNext(); 2047 } 2048 2049 function runNext() { 2050 if (runningRequests < maxRequests) { 2051 var request = pendingRequests.shift(); 2052 if (request) { 2053 runningRequests++; 2054 getJSON(request[0], request[1], request[2]); 2055 runNext(); 2056 } 2057 } 2058 } 2059 2060 function requestComplete() { 2061 runningRequests--; 2062 runNext(); 2063 } 2064 2065 function getJSON(url, success, error) { 2066 var xhr = new XMLHttpRequest(); 2067 xhr.open("GET", url, true); 2068 xhr.setRequestHeader("Content-Type", "application/json"); 2069 xhr.onload = function () { 2070 requestComplete(); 2071 if (xhr.status === 200) { 2072 success(JSON.parse(xhr.responseText)); 2073 } else { 2074 error(xhr.statusText); 2075 } 2076 }; 2077 xhr.send(); 2078 } 2079 2080 // helpers 2081 2082 function setText(element, text) { 2083 element.textContent = text; 2084 } 2085 2086 // TODO remove prefix for all messages 2087 function chartError(element, message, noPrefix) { 2088 if (!noPrefix) { 2089 message = "Error Loading Chart: " + message; 2090 } 2091 setText(element, message); 2092 element.style.color = "#ff0000"; 2093 } 2094 2095 function errorCatcher(chart) { 2096 try { 2097 chart.__render(); 2098 } catch (err) { 2099 chartError(chart.element, err.message); 2100 throw err; 2101 } 2102 } 2103 2104 function fetchDataSource(chart, dataSource, showLoading) { 2105 // only show loading message for urls and callbacks 2106 if (showLoading && chart.options.loading && (typeof dataSource === "string" || typeof dataSource === "function")) { 2107 setText(chart.element, chart.options.loading); 2108 } 2109 2110 if (typeof dataSource === "string") { 2111 pushRequest(dataSource, function (data) { 2112 chart.rawData = data; 2113 errorCatcher(chart); 2114 }, function (message) { 2115 chartError(chart.element, message); 2116 }); 2117 } else if (typeof dataSource === "function") { 2118 try { 2119 dataSource(function (data) { 2120 chart.rawData = data; 2121 errorCatcher(chart); 2122 }, function (message) { 2123 chartError(chart.element, message, true); 2124 }); 2125 } catch (err) { 2126 chartError(chart.element, err, true); 2127 } 2128 } else { 2129 chart.rawData = dataSource; 2130 errorCatcher(chart); 2131 } 2132 } 2133 2134 function renderChart(chartType, chart) { 2135 if (dataEmpty(chart.data, chartType)) { 2136 var message = chart.options.empty || (chart.options.messages && chart.options.messages.empty) || "No data"; 2137 setText(chart.element, message); 2138 } else { 2139 callAdapter(chartType, chart); 2140 // TODO add downloadSupported method to adapter 2141 if (chart.options.download && !chart.__downloadAttached && chart.adapter === "chartjs") { 2142 addDownloadButton(chart); 2143 } 2144 } 2145 } 2146 2147 function getElement(element) { 2148 if (typeof element === "string") { 2149 var elementId = element; 2150 element = document.getElementById(element); 2151 if (!element) { 2152 throw new Error("No element with id " + elementId); 2153 } 2154 } 2155 return element; 2156 } 2157 2158 // define classes 2159 2160 var Chart = function Chart(element, dataSource, options) { 2161 this.element = getElement(element); 2162 this.options = merge(Chartkick.options, options || {}); 2163 this.dataSource = dataSource; 2164 2165 // TODO handle charts without an id for eachChart and destroyAll 2166 if (this.element.id) { 2167 Chartkick.charts[this.element.id] = this; 2168 } 2169 2170 fetchDataSource(this, dataSource, true); 2171 2172 if (this.options.refresh) { 2173 this.startRefresh(); 2174 } 2175 }; 2176 2177 Chart.prototype.getElement = function getElement () { 2178 return this.element; 2179 }; 2180 2181 Chart.prototype.getDataSource = function getDataSource () { 2182 return this.dataSource; 2183 }; 2184 2185 Chart.prototype.getData = function getData () { 2186 return this.data; 2187 }; 2188 2189 Chart.prototype.getOptions = function getOptions () { 2190 return this.options; 2191 }; 2192 2193 Chart.prototype.getChartObject = function getChartObject () { 2194 return this.chart; 2195 }; 2196 2197 Chart.prototype.getAdapter = function getAdapter () { 2198 return this.adapter; 2199 }; 2200 2201 Chart.prototype.updateData = function updateData (dataSource, options) { 2202 this.dataSource = dataSource; 2203 if (options) { 2204 this.__updateOptions(options); 2205 } 2206 fetchDataSource(this, dataSource, true); 2207 }; 2208 2209 Chart.prototype.setOptions = function setOptions (options) { 2210 this.__updateOptions(options); 2211 this.redraw(); 2212 }; 2213 2214 Chart.prototype.redraw = function redraw () { 2215 fetchDataSource(this, this.rawData); 2216 }; 2217 2218 Chart.prototype.refreshData = function refreshData () { 2219 if (typeof this.dataSource === "string") { 2220 // prevent browser from caching 2221 var sep = this.dataSource.indexOf("?") === -1 ? "?" : "&"; 2222 var url = this.dataSource + sep + "_=" + (new Date()).getTime(); 2223 fetchDataSource(this, url); 2224 } else if (typeof this.dataSource === "function") { 2225 fetchDataSource(this, this.dataSource); 2226 } 2227 }; 2228 2229 Chart.prototype.startRefresh = function startRefresh () { 2230 var this$1$1 = this; 2231 2232 var refresh = this.options.refresh; 2233 2234 if (refresh && typeof this.dataSource !== "string" && typeof this.dataSource !== "function") { 2235 throw new Error("Data source must be a URL or callback for refresh"); 2236 } 2237 2238 if (!this.intervalId) { 2239 if (refresh) { 2240 this.intervalId = setInterval(function () { 2241 this$1$1.refreshData(); 2242 }, refresh * 1000); 2243 } else { 2244 throw new Error("No refresh interval"); 2245 } 2246 } 2247 }; 2248 2249 Chart.prototype.stopRefresh = function stopRefresh () { 2250 if (this.intervalId) { 2251 clearInterval(this.intervalId); 2252 this.intervalId = null; 2253 } 2254 }; 2255 2256 Chart.prototype.toImage = function toImage (download) { 2257 // TODO move logic to adapter 2258 if (this.adapter === "chartjs") { 2259 if (download && download.background && download.background !== "transparent") { 2260 // https://stackoverflow.com/questions/30464750/chartjs-line-chart-set-background-color 2261 var canvas = this.chart.canvas; 2262 var ctx = this.chart.ctx; 2263 var tmpCanvas = document.createElement("canvas"); 2264 var tmpCtx = tmpCanvas.getContext("2d"); 2265 tmpCanvas.width = ctx.canvas.width; 2266 tmpCanvas.height = ctx.canvas.height; 2267 tmpCtx.fillStyle = download.background; 2268 tmpCtx.fillRect(0, 0, tmpCanvas.width, tmpCanvas.height); 2269 tmpCtx.drawImage(canvas, 0, 0); 2270 return tmpCanvas.toDataURL("image/png"); 2271 } else { 2272 return this.chart.toBase64Image(); 2273 } 2274 } else { 2275 throw new Error("Feature only available for Chart.js"); 2276 } 2277 }; 2278 2279 Chart.prototype.destroy = function destroy () { 2280 this.destroyed = true; 2281 this.stopRefresh(); 2282 2283 if (this.__adapterObject) { 2284 this.__adapterObject.destroy(this); 2285 } 2286 2287 if (this.__enterEvent) { 2288 this.element.removeEventListener("mouseover", this.__enterEvent); 2289 } 2290 2291 if (this.__leaveEvent) { 2292 this.element.removeEventListener("mouseout", this.__leaveEvent); 2293 } 2294 }; 2295 2296 Chart.prototype.__updateOptions = function __updateOptions (options) { 2297 var updateRefresh = options.refresh && options.refresh !== this.options.refresh; 2298 this.options = merge(Chartkick.options, options); 2299 if (updateRefresh) { 2300 this.stopRefresh(); 2301 this.startRefresh(); 2302 } 2303 }; 2304 2305 Chart.prototype.__render = function __render () { 2306 this.data = this.__processData(); 2307 renderChart(this.__chartName(), this); 2308 }; 2309 2310 Chart.prototype.__config = function __config () { 2311 return Chartkick.config; 2312 }; 2313 2314 var LineChart = /*@__PURE__*/(function (Chart) { 2315 function LineChart () { 2316 Chart.apply(this, arguments); 2317 } 2318 2319 if ( Chart ) LineChart.__proto__ = Chart; 2320 LineChart.prototype = Object.create( Chart && Chart.prototype ); 2321 LineChart.prototype.constructor = LineChart; 2322 2323 LineChart.prototype.__processData = function __processData () { 2324 return processSeries(this); 2325 }; 2326 2327 LineChart.prototype.__chartName = function __chartName () { 2328 return "LineChart"; 2329 }; 2330 2331 return LineChart; 2332 }(Chart)); 2333 2334 var PieChart = /*@__PURE__*/(function (Chart) { 2335 function PieChart () { 2336 Chart.apply(this, arguments); 2337 } 2338 2339 if ( Chart ) PieChart.__proto__ = Chart; 2340 PieChart.prototype = Object.create( Chart && Chart.prototype ); 2341 PieChart.prototype.constructor = PieChart; 2342 2343 PieChart.prototype.__processData = function __processData () { 2344 return processSimple(this); 2345 }; 2346 2347 PieChart.prototype.__chartName = function __chartName () { 2348 return "PieChart"; 2349 }; 2350 2351 return PieChart; 2352 }(Chart)); 2353 2354 var ColumnChart = /*@__PURE__*/(function (Chart) { 2355 function ColumnChart () { 2356 Chart.apply(this, arguments); 2357 } 2358 2359 if ( Chart ) ColumnChart.__proto__ = Chart; 2360 ColumnChart.prototype = Object.create( Chart && Chart.prototype ); 2361 ColumnChart.prototype.constructor = ColumnChart; 2362 2363 ColumnChart.prototype.__processData = function __processData () { 2364 return processSeries(this, null, true); 2365 }; 2366 2367 ColumnChart.prototype.__chartName = function __chartName () { 2368 return "ColumnChart"; 2369 }; 2370 2371 return ColumnChart; 2372 }(Chart)); 2373 2374 var BarChart = /*@__PURE__*/(function (Chart) { 2375 function BarChart () { 2376 Chart.apply(this, arguments); 2377 } 2378 2379 if ( Chart ) BarChart.__proto__ = Chart; 2380 BarChart.prototype = Object.create( Chart && Chart.prototype ); 2381 BarChart.prototype.constructor = BarChart; 2382 2383 BarChart.prototype.__processData = function __processData () { 2384 return processSeries(this, null, true); 2385 }; 2386 2387 BarChart.prototype.__chartName = function __chartName () { 2388 return "BarChart"; 2389 }; 2390 2391 return BarChart; 2392 }(Chart)); 2393 2394 var AreaChart = /*@__PURE__*/(function (Chart) { 2395 function AreaChart () { 2396 Chart.apply(this, arguments); 2397 } 2398 2399 if ( Chart ) AreaChart.__proto__ = Chart; 2400 AreaChart.prototype = Object.create( Chart && Chart.prototype ); 2401 AreaChart.prototype.constructor = AreaChart; 2402 2403 AreaChart.prototype.__processData = function __processData () { 2404 return processSeries(this); 2405 }; 2406 2407 AreaChart.prototype.__chartName = function __chartName () { 2408 return "AreaChart"; 2409 }; 2410 2411 return AreaChart; 2412 }(Chart)); 2413 2414 var GeoChart = /*@__PURE__*/(function (Chart) { 2415 function GeoChart () { 2416 Chart.apply(this, arguments); 2417 } 2418 2419 if ( Chart ) GeoChart.__proto__ = Chart; 2420 GeoChart.prototype = Object.create( Chart && Chart.prototype ); 2421 GeoChart.prototype.constructor = GeoChart; 2422 2423 GeoChart.prototype.__processData = function __processData () { 2424 return processSimple(this); 2425 }; 2426 2427 GeoChart.prototype.__chartName = function __chartName () { 2428 return "GeoChart"; 2429 }; 2430 2431 return GeoChart; 2432 }(Chart)); 2433 2434 var ScatterChart = /*@__PURE__*/(function (Chart) { 2435 function ScatterChart () { 2436 Chart.apply(this, arguments); 2437 } 2438 2439 if ( Chart ) ScatterChart.__proto__ = Chart; 2440 ScatterChart.prototype = Object.create( Chart && Chart.prototype ); 2441 ScatterChart.prototype.constructor = ScatterChart; 2442 2443 ScatterChart.prototype.__processData = function __processData () { 2444 return processSeries(this, "number"); 2445 }; 2446 2447 ScatterChart.prototype.__chartName = function __chartName () { 2448 return "ScatterChart"; 2449 }; 2450 2451 return ScatterChart; 2452 }(Chart)); 2453 2454 var BubbleChart = /*@__PURE__*/(function (Chart) { 2455 function BubbleChart () { 2456 Chart.apply(this, arguments); 2457 } 2458 2459 if ( Chart ) BubbleChart.__proto__ = Chart; 2460 BubbleChart.prototype = Object.create( Chart && Chart.prototype ); 2461 BubbleChart.prototype.constructor = BubbleChart; 2462 2463 BubbleChart.prototype.__processData = function __processData () { 2464 return processSeries(this, "bubble"); 2465 }; 2466 2467 BubbleChart.prototype.__chartName = function __chartName () { 2468 return "BubbleChart"; 2469 }; 2470 2471 return BubbleChart; 2472 }(Chart)); 2473 2474 var Timeline = /*@__PURE__*/(function (Chart) { 2475 function Timeline () { 2476 Chart.apply(this, arguments); 2477 } 2478 2479 if ( Chart ) Timeline.__proto__ = Chart; 2480 Timeline.prototype = Object.create( Chart && Chart.prototype ); 2481 Timeline.prototype.constructor = Timeline; 2482 2483 Timeline.prototype.__processData = function __processData () { 2484 var data = this.rawData; 2485 for (var i = 0; i < data.length; i++) { 2486 data[i][1] = toDate(data[i][1]); 2487 data[i][2] = toDate(data[i][2]); 2488 } 2489 return data; 2490 }; 2491 2492 Timeline.prototype.__chartName = function __chartName () { 2493 return "Timeline"; 2494 }; 2495 2496 return Timeline; 2497 }(Chart)); 2498 2499 Chartkick.LineChart = LineChart; 2500 Chartkick.PieChart = PieChart; 2501 Chartkick.ColumnChart = ColumnChart; 2502 Chartkick.BarChart = BarChart; 2503 Chartkick.AreaChart = AreaChart; 2504 Chartkick.GeoChart = GeoChart; 2505 Chartkick.ScatterChart = ScatterChart; 2506 Chartkick.BubbleChart = BubbleChart; 2507 Chartkick.Timeline = Timeline; 2508 2509 // not ideal, but allows for simpler integration 2510 if (typeof window !== "undefined" && !window.Chartkick) { 2511 window.Chartkick = Chartkick; 2512 2513 // clean up previous charts before Turbolinks loads new page 2514 document.addEventListener("turbolinks:before-render", function () { 2515 if (Chartkick.config.autoDestroy !== false) { 2516 Chartkick.destroyAll(); 2517 } 2518 }); 2519 2520 // clean up previous charts before Turbo loads new page 2521 document.addEventListener("turbo:before-render", function () { 2522 if (Chartkick.config.autoDestroy !== false) { 2523 Chartkick.destroyAll(); 2524 } 2525 }); 2526 2527 // use setTimeout so charting library can come later in same JS file 2528 setTimeout(function () { 2529 window.dispatchEvent(new Event("chartkick:load")); 2530 }, 0); 2531 } 2532 2533 // backwards compatibility for esm require 2534 Chartkick.default = Chartkick; 2535 2536 return Chartkick; 2537 2538}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.