Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

integration.js 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. $(document).ready(function() {
  2. function getData() {
  3. return [
  4. ["", "Kia", "Nissan", "Toyota", "Honda", "Mazda", "Ford"],
  5. ["2012", 10, 11, 12, 13, 15, 16],
  6. ["2013", 10, 11, 12, 13, 15, 16],
  7. ["2014", 10, 11, 12, 13, 15, 16],
  8. ["2015", 10, 11, 12, 13, 15, 16],
  9. ["2016", 10, 11, 12, 13, 15, 16]
  10. ]
  11. }
  12. function updateHeatmap(change, source) {
  13. if (source) heatmap[change[0][1]] = generateHeatmapData.call(this, change[0][1]);
  14. else {
  15. heatmap = [];
  16. for (var i = 1, colCount = this.countCols(); i < colCount; i++) heatmap[i] = generateHeatmapData.call(this, i)
  17. }
  18. }
  19. function point(min, max, value) {
  20. return (value - min) / (max - min)
  21. }
  22. function generateHeatmapData(colId) {
  23. var values = this.getDataAtCol(colId);
  24. return {
  25. min: Math.min.apply(null, values),
  26. max: Math.max.apply(null, values)
  27. }
  28. }
  29. function heatmapRenderer(instance, td, row, col, prop, value, cellProperties) {
  30. Handsontable.renderers.TextRenderer.apply(this, arguments), heatmap[col] && (td.style.backgroundColor = heatmapScale(point(heatmap[col].min, heatmap[col].max, parseInt(value, 10))).hex(), td.style.textAlign = "right")
  31. }
  32. var $container = $("#jQuery");
  33. $container.handsontable({
  34. data: getData(),
  35. rowHeaders: !0,
  36. colHeaders: !0,
  37. contextMenu: !0
  38. });
  39. var heatmap, heatmapScale, hot, data = ($("#jQuery").handsontable("getInstance"), [
  40. [2012, 190251, 5090, 195341],
  41. [2013, 224495, 6486, 230981],
  42. [2014, 254044, 6765, 260809],
  43. [2015, 254099, 7521, 261620],
  44. [2016, 271108, 9449, 280557],
  45. [2017, 280565, 11714, 292279],
  46. [2018, 284120, 11292, 295412],
  47. [2019, 279742, 11468, 291210],
  48. [2020, 290411, 11806, 302217],
  49. [2021, 290652, 10891, 301543],
  50. [2022, 283863, 10402, 294265],
  51. [2023, 267646, 10104, 255850]
  52. ]),
  53. container = document.getElementById("chromaJS");
  54. heatmapScale = chroma.scale(["#FFFFFF", "#8BC34A"]), hot = new Handsontable(container, {
  55. data: data,
  56. colHeaders: ["Year", "Domestic Flights", "International Flights", "Total Flights"],
  57. columns: [{
  58. type: "numeric"
  59. }, {
  60. type: "numeric",
  61. format: "0,0",
  62. renderer: heatmapRenderer
  63. }, {
  64. type: "numeric",
  65. format: "0,0",
  66. renderer: heatmapRenderer
  67. }, {
  68. type: "numeric",
  69. format: "0,0",
  70. renderer: heatmapRenderer
  71. }],
  72. afterLoadData: updateHeatmap,
  73. beforeChangeRender: updateHeatmap
  74. })
  75. });