Skip to content

Commit

Permalink
fix(insights): Fix bar chart height (#21707)
Browse files Browse the repository at this point in the history
  • Loading branch information
webjunkie authored Apr 23, 2024
1 parent e332571 commit cf2a4ee
Show file tree
Hide file tree
Showing 28 changed files with 29 additions and 21 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 21 additions & 20 deletions frontend/src/scenes/insights/views/LineGraph/LineGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@ export function LineGraph_({
},
}

const truncateRows = !inSurveyView && !!insightProps.dashboardId

if (type === GraphType.Bar) {
if (hideXAxis || hideYAxis) {
options.layout = { padding: 20 }
Expand Down Expand Up @@ -674,29 +676,31 @@ export function LineGraph_({
y: {
display: true,
beforeFit: (scale) => {
if (inSurveyView) {
scale.ticks = scale.ticks.map((tick) => {
if (typeof tick.label === 'string') {
return { ...tick, label: truncateString(tick.label, 50) }
}
return tick
})

const ROW_HEIGHT = 60
const dynamicHeight = scale.ticks.length * ROW_HEIGHT
const height = dynamicHeight
const parentNode: any = scale.chart?.canvas?.parentNode
parentNode.style.height = `${height}px`
} else {
// display only as many bars, as we can fit labels
scale.ticks = scale.ticks.map((tick) => {
if (typeof tick.label === 'string') {
return { ...tick, label: truncateString(tick.label, 50) }
}
return tick
})

const ROW_HEIGHT = 20
const height = scale.ticks.length * ROW_HEIGHT
const parentNode: any = scale.chart?.canvas?.parentNode
parentNode.style.height = `${height}px`

if (truncateRows) {
// Display only as many bars, as we can fit labels
// Important: Make sure the query result does not deliver more data than we can display
// See apply_dashboard_filters function in query runners
scale.max = scale.ticks.length
}
},
beginAtZero: true,
ticks: {
...tickOptions,
precision,
autoSkip: true,
stepSize: !truncateRows ? 1 : undefined,
autoSkip: !truncateRows ? false : undefined,
callback: function _renderYLabel(_, i) {
const d = datasets?.[0]
if (!d) {
Expand Down Expand Up @@ -738,10 +742,7 @@ export function LineGraph_({
}, [datasets, hiddenLegendKeys, isDarkModeOn, trendsFilter, formula, showValueOnSeries, showPercentStackView])

return (
<div
className={clsx('LineGraph w-full h-full overflow-hidden', { absolute: !inSurveyView })}
data-attr={dataAttr}
>
<div className={clsx('LineGraph w-full grow relative overflow-hidden')} data-attr={dataAttr}>
<canvas ref={canvasRef} />
{showAnnotations && myLineChart && chartWidth && chartHeight ? (
<AnnotationsOverlay
Expand Down
9 changes: 8 additions & 1 deletion posthog/hogql_queries/insights/trends/trends_query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from posthog.hogql_queries.insights.trends.display import TrendsDisplay
from posthog.hogql_queries.insights.trends.trends_query_builder import TrendsQueryBuilder
from posthog.hogql_queries.insights.trends.series_with_extras import SeriesWithExtras
from posthog.hogql_queries.query_runner import QueryRunner
from posthog.hogql_queries.query_runner import QueryRunner, RunnableQueryNode
from posthog.hogql_queries.utils.formula_ast import FormulaAST
from posthog.hogql_queries.utils.query_date_range import QueryDateRange
from posthog.hogql_queries.utils.query_previous_period_date_range import (
Expand Down Expand Up @@ -812,3 +812,10 @@ def _trends_display(self) -> TrendsDisplay:
display = self.query.trendsFilter.display

return TrendsDisplay(display)

def apply_dashboard_filters(self, *args, **kwargs) -> RunnableQueryNode:
# Remove any set breakdown limit for display on the dashboard
if self.query.breakdownFilter:
self.query.breakdownFilter.breakdown_limit = None

return self.query

0 comments on commit cf2a4ee

Please sign in to comment.