Skip to content

Commit e71682a

Browse files
authored
Merge pull request #4838 from dschweinbenz/fix/4809-heatmap-gaps
Fix heatmap gaps and ticket alignment
2 parents 4356a6b + ae9b24c commit e71682a

File tree

2 files changed

+128
-2
lines changed

2 files changed

+128
-2
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
7+
<title>HeatMap with inconsistent timeseries</title>
8+
9+
<link href="../../assets/styles.css" rel="stylesheet" />
10+
11+
<style>
12+
#chart {
13+
max-width: 650px;
14+
margin: 35px auto;
15+
}
16+
</style>
17+
18+
<script>
19+
window.Promise ||
20+
document.write(
21+
'<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"><\/script>'
22+
)
23+
window.Promise ||
24+
document.write(
25+
'<script src="https://cdn.jsdelivr.net/npm/eligrey-classlist-js-polyfill@1.2.20171210/classList.min.js"><\/script>'
26+
)
27+
window.Promise ||
28+
document.write(
29+
'<script src="https://cdn.jsdelivr.net/npm/findindex_polyfill_mdn"><\/script>'
30+
)
31+
</script>
32+
33+
<script src="../../../dist/apexcharts.js"></script>
34+
</head>
35+
36+
<body>
37+
<div id="chart"></div>
38+
39+
<script>
40+
const end = new Date("2024-11-29T10:00:00.000Z").getTime();
41+
const start = end - 12 * 60 * 60 * 1000;
42+
43+
const timeSeries = () => {
44+
let series = [];
45+
for (let i = start; i < end; i += 30 * 60 * 1000) {
46+
series.push({
47+
x: (new Date(i).getTime()),
48+
y: Math.floor(Math.random() * 100).toFixed(0),
49+
});
50+
}
51+
return series;
52+
};
53+
let data1 = timeSeries()
54+
data1.splice(0,10)
55+
data1.splice(3,2)
56+
const data2 = timeSeries()
57+
data2.splice(data2.length - 10,10);
58+
const data3 = timeSeries()
59+
let data = [
60+
{
61+
name: "Series 1",
62+
data: data1,
63+
},
64+
{
65+
name: "Series 2",
66+
data: data2,
67+
},
68+
{
69+
name: "Series 3",
70+
data: data3,
71+
},
72+
];
73+
74+
var options = {
75+
chart: {
76+
height: 200,
77+
width: 630,
78+
type: "heatmap"
79+
},
80+
tooltip: {
81+
x: { show: true, format: 'MMM dd HH:mm' },
82+
},
83+
xaxis: {
84+
labels: {
85+
datetimeFormatter: {
86+
year: 'yyyy',
87+
month: 'yyyy MMM',
88+
day: 'MMM dd',
89+
hour: 'HH:mm',
90+
},
91+
},
92+
type: 'datetime'
93+
},
94+
plotOptions: {
95+
heatmap: {
96+
colorScale: {
97+
ranges: [
98+
{
99+
from: 0,
100+
to: 100,
101+
name: 'orange',
102+
color: '#FFB200'
103+
}]
104+
}
105+
}
106+
},
107+
series: data,
108+
};
109+
110+
var chart = new ApexCharts(document.querySelector("#chart"), options);
111+
112+
chart.render();
113+
</script>
114+
</body>
115+
</html>

src/charts/HeatMap.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,18 @@ export default class HeatMap {
7676
let x1 = 0
7777
let shadeIntensity = w.config.plotOptions.heatmap.shadeIntensity
7878

79-
for (let j = 0; j < heatSeries[i].length; j++) {
79+
let j = 0;
80+
for (let dIndex = 0; dIndex < w.globals.dataPoints; dIndex++) {
81+
82+
// Recognize gaps and align values based on x axis
83+
if ((w.globals.minX + (w.globals.minXDiff * dIndex)) < w.globals.seriesX[i][j]) {
84+
x1 = x1 + xDivision;
85+
continue;
86+
}
87+
88+
// Stop loop if index is out of array length
89+
if (j >= heatSeries[i].length) break;
90+
8091
let heatColor = this.helpers.getShadeColor(
8192
w.config.chart.type,
8293
i,
@@ -114,7 +125,6 @@ export default class HeatMap {
114125
cx: x1,
115126
cy: y1,
116127
})
117-
118128
rect.node.classList.add('apexcharts-heatmap-rect')
119129
elSeries.add(rect)
120130

@@ -186,6 +196,7 @@ export default class HeatMap {
186196
}
187197

188198
x1 = x1 + xDivision
199+
j++;
189200
}
190201

191202
y1 = y1 + yDivision

0 commit comments

Comments
 (0)