Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bi): Added stacked bar charts #23991

Merged
merged 4 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions frontend/src/lib/components/Cards/InsightCard/InsightCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ const displayMap: Record<
className: 'bar',
element: ActionsHorizontalBar,
},
ActionsStackedBar: {
className: 'bar',
element: ActionsLineGraph,
},
ActionsTable: {
className: 'table',
element: DashboardInsightsTable,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ChartDisplayCategory, ChartDisplayType, Region, SSOProvider } from '../
export const DISPLAY_TYPES_TO_CATEGORIES: Record<ChartDisplayType, ChartDisplayCategory> = {
[ChartDisplayType.ActionsLineGraph]: ChartDisplayCategory.TimeSeries,
[ChartDisplayType.ActionsBar]: ChartDisplayCategory.TimeSeries,
[ChartDisplayType.ActionsStackedBar]: ChartDisplayCategory.TimeSeries,
[ChartDisplayType.ActionsAreaGraph]: ChartDisplayCategory.TimeSeries,
[ChartDisplayType.ActionsLineGraphCumulative]: ChartDisplayCategory.CumulativeTimeSeries,
[ChartDisplayType.BoldNumber]: ChartDisplayCategory.TotalValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export const LineGraph = (): JSX.Element => {
// TODO: Extract this logic out of this component and inject values in
// via props. Make this a purely presentational component
const { xData, yData, presetChartHeight, visualizationType, showEditingUI } = useValues(dataVisualizationLogic)
const isBarChart = visualizationType === ChartDisplayType.ActionsBar
const isBarChart =
visualizationType === ChartDisplayType.ActionsBar || visualizationType === ChartDisplayType.ActionsStackedBar
const isStackedBarChart = visualizationType === ChartDisplayType.ActionsStackedBar
const isAreaChart = visualizationType === ChartDisplayType.ActionsAreaGraph

const { goalLines } = useValues(displayLogic)
Expand Down Expand Up @@ -243,6 +245,7 @@ export const LineGraph = (): JSX.Element => {
x: {
display: true,
beginAtZero: true,
stacked: isStackedBarChart,
ticks: tickOptions,
grid: {
...gridOptions,
Expand All @@ -253,7 +256,7 @@ export const LineGraph = (): JSX.Element => {
y: {
display: true,
beginAtZero: true,
stacked: isAreaChart,
stacked: isAreaChart || isStackedBarChart,
ticks: {
display: true,
...tickOptions,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IconGraph, IconTrends } from '@posthog/icons'
import { IconGraph, IconLifecycle, IconTrends } from '@posthog/icons'
import { LemonSelect, LemonSelectOptions } from '@posthog/lemon-ui'
import { useActions, useValues } from 'kea'
import { Icon123, IconAreaChart, IconTableChart } from 'lib/lemon-ui/icons'
Expand Down Expand Up @@ -40,6 +40,11 @@ export const TableDisplay = (): JSX.Element => {
icon: <IconGraph />,
label: 'Bar chart',
},
{
value: ChartDisplayType.ActionsStackedBar,
icon: <IconLifecycle />,
label: 'Stacked bar chart',
},
{
value: ChartDisplayType.ActionsAreaGraph,
icon: <IconAreaChart />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ function InternalDataTableVisualization(props: DataTableVisualizationProps): JSX
} else if (
visualizationType === ChartDisplayType.ActionsLineGraph ||
visualizationType === ChartDisplayType.ActionsBar ||
visualizationType === ChartDisplayType.ActionsAreaGraph
visualizationType === ChartDisplayType.ActionsAreaGraph ||
visualizationType === ChartDisplayType.ActionsStackedBar
) {
component = <Chart />
} else if (visualizationType === ChartDisplayType.BoldNumber) {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2002,6 +2002,7 @@
"enum": [
"ActionsLineGraph",
"ActionsBar",
"ActionsStackedBar",
"ActionsAreaGraph",
"ActionsLineGraphCumulative",
"BoldNumber",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/scenes/insights/utils/compareInsightQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const groupedChartDisplayTypes: Record<ChartDisplayType, ChartDisplayType> = {
[ChartDisplayType.ActionsLineGraph]: ChartDisplayType.ActionsLineGraph,
[ChartDisplayType.ActionsBar]: ChartDisplayType.ActionsLineGraph,
[ChartDisplayType.ActionsAreaGraph]: ChartDisplayType.ActionsLineGraph,
[ChartDisplayType.ActionsStackedBar]: ChartDisplayType.ActionsLineGraph,

// cumulative time series
[ChartDisplayType.ActionsLineGraphCumulative]: ChartDisplayType.ActionsLineGraphCumulative,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2013,6 +2013,7 @@ export interface DatedAnnotationType extends Omit<AnnotationType, 'date_marker'>
export enum ChartDisplayType {
ActionsLineGraph = 'ActionsLineGraph',
ActionsBar = 'ActionsBar',
ActionsStackedBar = 'ActionsStackedBar',
ActionsAreaGraph = 'ActionsAreaGraph',
ActionsLineGraphCumulative = 'ActionsLineGraphCumulative',
BoldNumber = 'BoldNumber',
Expand Down
1 change: 1 addition & 0 deletions posthog/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class ChartAxis(BaseModel):
class ChartDisplayType(StrEnum):
ACTIONS_LINE_GRAPH = "ActionsLineGraph"
ACTIONS_BAR = "ActionsBar"
ACTIONS_STACKED_BAR = "ActionsStackedBar"
ACTIONS_AREA_GRAPH = "ActionsAreaGraph"
ACTIONS_LINE_GRAPH_CUMULATIVE = "ActionsLineGraphCumulative"
BOLD_NUMBER = "BoldNumber"
Expand Down
Loading