Skip to content

Commit 6e85273

Browse files
feat: configure number of column values in pivot table
1 parent b8dd626 commit 6e85273

6 files changed

Lines changed: 40 additions & 19 deletions

File tree

frontend/src2/charts/chart.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ function makeChart(workbookChart: WorkbookChart) {
220220
let rows = config.rows.filter((r) => r.column_name)
221221
let columns = config.columns.filter((c) => c.column_name)
222222
let values = config.values.filter((v) => v.measure_name)
223+
values = values.length ? values : [count()]
223224

224225
if (!rows.length) {
225226
console.warn('Rows are required')
@@ -237,7 +238,8 @@ function makeChart(workbookChart: WorkbookChart) {
237238
chart.dataQuery.addPivotWider({
238239
rows: rows,
239240
columns: columns,
240-
values: values || [count()],
241+
values: values,
242+
max_column_values: config.max_column_values || 10,
241243
})
242244
}
243245

frontend/src2/charts/components/DimensionPicker.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ function selectDimension(option?: DimensionOption) {
9898
/>
9999
</InlineFormControlLabel>
100100

101+
<slot name="config-fields" />
102+
101103
<div class="flex gap-1">
102104
<Button class="w-full" @click="emit('remove')" theme="red">
103105
<template #prefix>

frontend/src2/charts/components/TableChartConfigForm.vue

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import { watchEffect } from 'vue'
33
import DraggableList from '../../components/DraggableList.vue'
4+
import InlineFormControlLabel from '../../components/InlineFormControlLabel.vue'
45
import { TableChartConfig } from '../../types/chart.types'
56
import { ColumnOption, DimensionOption } from '../../types/query.types'
67
import CollapsibleSection from './CollapsibleSection.vue'
@@ -56,23 +57,34 @@ watchEffect(() => {
5657
</CollapsibleSection>
5758

5859
<CollapsibleSection title="Columns">
59-
<div>
60-
<DraggableList v-model:items="config.columns" group="columns">
61-
<template #item="{ item, index }">
62-
<DimensionPicker
63-
:options="props.dimensions"
64-
:model-value="item"
65-
@update:model-value="Object.assign(item, $event || {})"
66-
@remove="config.columns.splice(index, 1)"
67-
/>
68-
</template>
69-
</DraggableList>
70-
<button
71-
class="mt-1.5 text-left text-xs text-gray-600 hover:underline"
72-
@click="config.columns.push({} as any)"
73-
>
74-
+ Add column
75-
</button>
60+
<div class="flex flex-col gap-3">
61+
<div>
62+
<DraggableList v-model:items="config.columns" group="columns">
63+
<template #item="{ item, index }">
64+
<DimensionPicker
65+
:options="props.dimensions"
66+
:model-value="item"
67+
@update:model-value="Object.assign(item, $event || {})"
68+
@remove="config.columns.splice(index, 1)"
69+
/>
70+
</template>
71+
</DraggableList>
72+
<button
73+
class="mt-1.5 text-left text-xs text-gray-600 hover:underline"
74+
@click="config.columns.push({} as any)"
75+
>
76+
+ Add column
77+
</button>
78+
</div>
79+
80+
<InlineFormControlLabel class="!w-1/2" label="Max Column Values">
81+
<FormControl
82+
type="number"
83+
autocomplete="off"
84+
:modelValue="config.max_column_values || 10"
85+
@update:modelValue="config.max_column_values = $event"
86+
/>
87+
</InlineFormControlLabel>
7688
</div>
7789
</CollapsibleSection>
7890

frontend/src2/types/chart.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export type TableChartConfig = {
100100
rows: Dimension[]
101101
columns: Dimension[]
102102
values: Measure[]
103+
max_column_values?: number
103104
show_filter_row?: boolean
104105
show_row_totals?: boolean
105106
show_column_totals?: boolean

frontend/src2/types/query.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export type PivotWiderArgs = {
137137
rows: Dimension[]
138138
columns: Dimension[]
139139
values: Measure[]
140+
max_column_values?: number
140141
}
141142
export type PivotWider = { type: 'pivot_wider' } & PivotWiderArgs
142143

insights/insights/doctype/insights_data_source_v3/ibis_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,14 @@ def apply_pivot(self, pivot_args, pivot_type):
402402
)
403403

404404
names_from = [col.get_name() for col in columns]
405+
max_names = pivot_args.get("max_column_values", 10)
406+
max_names = int(max_names)
407+
max_names = max(1, min(max_names, 100))
405408
names = (
406409
self.query.select(names_from)
407410
.order_by(names_from)
408411
.distinct()
409-
.limit(10)
412+
.limit(max_names)
410413
.execute()
411414
)
412415
names = names.fillna("null").values

0 commit comments

Comments
 (0)