Skip to content

Commit 5d857fa

Browse files
authored
Main graph fixes (#6169)
* fix graph crashing * do not attempt to link to __blank__ period
1 parent d34b683 commit 5d857fa

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed

assets/js/dashboard/stats/graph/graph-tooltip.js

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,18 @@ const buildTooltipData = function (
8686
true
8787
)
8888

89-
const value = graphData.plot[data.dataIndex]
89+
const value = data && graphData.plot?.[data.dataIndex]
9090

9191
const formatter = MetricFormatterShort[metric]
92-
const comparisonValue = graphData.comparison_plot?.[comparisonData.dataIndex]
92+
const comparisonValue =
93+
comparisonData && graphData.comparison_plot?.[comparisonData.dataIndex]
9394
const comparisonDifference =
9495
label &&
9596
comparisonData &&
97+
value &&
9698
calculatePercentageDifference(comparisonValue, value)
9799

98-
const formattedValue = formatter(value)
100+
const formattedValue = value && formatter(value)
99101
const formattedComparisonValue = comparisonData && formatter(comparisonValue)
100102

101103
return {
@@ -151,6 +153,11 @@ export default function GraphTooltip(graphData, metric, dashboardState, theme) {
151153
tooltipModel
152154
)
153155

156+
if (!tooltipData.label) {
157+
tooltipEl.style.display = 'none'
158+
return
159+
}
160+
154161
tooltipRoot.render(
155162
<aside className="text-gray-100 flex flex-col gap-1.5">
156163
<div className="flex justify-between items-center">
@@ -167,32 +174,30 @@ export default function GraphTooltip(graphData, metric, dashboardState, theme) {
167174
) : null}
168175
</div>
169176

170-
{tooltipData.label ? (
171-
<div className="flex flex-col">
177+
<div className="flex flex-col">
178+
<div className="flex flex-row justify-between items-center text-sm">
179+
<span className="flex items-center mr-4">
180+
<div
181+
className="size-2 mr-2 rounded-full"
182+
style={{ backgroundColor: 'rgba(101,116,205)' }}
183+
></div>
184+
<span>{tooltipData.label}</span>
185+
</span>
186+
<span className="font-bold">{tooltipData.formattedValue}</span>
187+
</div>
188+
189+
{tooltipData.comparisonLabel ? (
172190
<div className="flex flex-row justify-between items-center text-sm">
173191
<span className="flex items-center mr-4">
174-
<div
175-
className="size-2 mr-2 rounded-full"
176-
style={{ backgroundColor: 'rgba(101,116,205)' }}
177-
></div>
178-
<span>{tooltipData.label}</span>
192+
<div className="size-2 mr-2 rounded-full bg-gray-500"></div>
193+
<span>{tooltipData.comparisonLabel}</span>
194+
</span>
195+
<span className="font-bold">
196+
{tooltipData.formattedComparisonValue}
179197
</span>
180-
<span className="font-bold">{tooltipData.formattedValue}</span>
181198
</div>
182-
183-
{tooltipData.comparisonLabel ? (
184-
<div className="flex flex-row justify-between items-center text-sm">
185-
<span className="flex items-center mr-4">
186-
<div className="size-2 mr-2 rounded-full bg-gray-500"></div>
187-
<span>{tooltipData.comparisonLabel}</span>
188-
</span>
189-
<span className="font-bold">
190-
{tooltipData.formattedComparisonValue}
191-
</span>
192-
</div>
193-
) : null}
194-
</div>
195-
) : null}
199+
) : null}
200+
</div>
196201

197202
{['month', 'day'].includes(graphData.interval) && (
198203
<>

assets/js/dashboard/stats/graph/line-graph.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,11 @@ class LineGraph extends React.Component {
243243
const element = this.chart.getElementsAtEventForMode(e, 'index', {
244244
intersect: false
245245
})[0]
246-
const date =
247-
this.props.graphData.labels[element.index] ||
248-
this.props.graphData.comparison_labels[element.index]
246+
const date = this.props.graphData.labels[element.index]
247+
248+
if (date === '__blank__') {
249+
return
250+
}
249251

250252
if (this.props.graphData.interval === 'month') {
251253
this.props.navigate({

0 commit comments

Comments
 (0)