chart-heatmap.html 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. {% removeemptylines %}
  2. {% assign id = include.chart-id %}
  3. {% assign class = include.class %}
  4. {% assign height = include.height | default: data.height | default: 25 %}
  5. {% assign class = include.class %}
  6. <div id="chart-{{ id }}"{% if class %} class="{{ class }}"{% endif %}></div>
  7. {% capture script -%}
  8. {% assign colors = include.colors | default: 1 %}
  9. {% removeemptylines %}
  10. <script>
  11. document.addEventListener("DOMContentLoaded", function () {
  12. {% if environment == 'development' %}
  13. window.tabler_chart = window.tabler_chart || {};
  14. {% endif %}
  15. window.ApexCharts && ({% if environment == 'development' %}window.tabler_chart["chart-{{ include.chart-id }}"] = {% endif %}new ApexCharts(document.getElementById('chart-{{ id }}'), {
  16. chart: {
  17. height: {{ height | times: 16 }},
  18. type: "heatmap",
  19. toolbar: {
  20. show: false,
  21. },
  22. },
  23. dataLabels: {
  24. enabled: {% if include.labels %}true{% else %}false{% endif %}
  25. },
  26. {% if include.scale %}
  27. plotOptions: {
  28. heatmap: {
  29. enableShades: {% unless include.no-shades %}true{% else %}false{% endunless %},
  30. colorScale: {
  31. ranges: [{
  32. from: 0,
  33. to: 20,
  34. name: "Low",
  35. color: "var(--tblr-green)"
  36. }, {
  37. from: 21,
  38. to: 50,
  39. name: "Medium",
  40. color: "var(--tblr-blue)"
  41. }, {
  42. from: 51,
  43. to: 75,
  44. name: "High",
  45. color: "var(--tblr-yellow)"
  46. }, {
  47. from: 76,
  48. to: 100,
  49. name: "Extreme",
  50. color: "var(--tblr-red)"
  51. }]
  52. }
  53. }
  54. },
  55. {% else %}
  56. colors: [{% if include.color %}'{{ include.color }}'{% else %}{% for color in site.colors limit: colors %}"{{ color[1].prop }}", {% endfor %}{% endif %}],
  57. {% endif %}
  58. series: [
  59. {% for i in site.months-short limit: 12 %}
  60. {% assign month-i = forloop.index %}
  61. { name: "{{ i }}", data: [{% for j in (1..16) %}{x: '{{ j }}', y: {{ j | random_number: 0, 100 | plus: month-i | random_number: 0, 100 }}},{% endfor %}] },
  62. {% endfor %}
  63. ],
  64. xaxis: {
  65. type: "category"
  66. },
  67. legend: {
  68. {% if include.legend %}
  69. show: true,
  70. position: 'bottom',
  71. offsetY: 8,
  72. markers: {
  73. width: 10,
  74. height: 10,
  75. radius: 100,
  76. },
  77. itemMargin: {
  78. horizontal: 8,
  79. },
  80. {% else %}
  81. show: false,
  82. {% endif %}
  83. },
  84. })).render();
  85. });
  86. </script>
  87. {% endremoveemptylines %}
  88. {%- endcapture %}
  89. {% capture_script %}
  90. {{ script }}
  91. {% endcapture_script %}
  92. {% endremoveemptylines %}