Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix: yAxis config for barchart

DarkPhoenix270481b4240d7f97
diff --git a/packages/nc-gui/components/nc/List/ColumnSelector.vue b/packages/nc-gui/components/nc/List/ColumnSelector.vue
index 9b14e6e70c..4bf248f432 100644
--- a/packages/nc-gui/components/nc/List/ColumnSelector.vue
+++ b/packages/nc-gui/components/nc/List/ColumnSelector.vue
@@ -11,6 +11,7 @@ interface Props {
disableLabel?: boolean
autoSelect?: boolean
disabled?: boolean
+ allowClear?: boolean
}
const props = withDefaults(defineProps<Props>(), {
@@ -18,6 +19,7 @@ const props = withDefaults(defineProps<Props>(), {
disableLabel: false,
autoSelect: false,
disabled: false,
+ allowClear: false,
})
const emit = defineEmits<{
@@ -35,8 +37,7 @@ const modelValue = useVModel(props, 'value', emit)
const isOpenColumnSelectDropdown = ref(false)
const handleValueUpdate = (value: any) => {
- const stringValue = String(value)
- modelValue.value = stringValue
+ modelValue.value = value
}
const columnList = computedAsync(async () => {
@@ -149,7 +150,7 @@ defineExpose({
"
:has-error="!!selectedColumn?.ncItemDisabled"
>
- <div class="flex-1 flex items-center gap-2 min-w-0">
+ <div class="flex-1 flex group items-center gap-2 min-w-0">
<div v-if="selectedColumn" class="min-w-5 flex items-center justify-center">
<NcIconField :field="selectedColumn" class="text-gray-500" />
</div>
@@ -164,6 +165,13 @@ defineExpose({
</template>
</NcTooltip>
+ <GeneralIcon
+ v-if="selectedColumn && allowClear"
+ class="!hidden text-nc-content-gray-muted transition group-hover:!block h-4 w-4 cursor-pointer"
+ icon="ncXCircle"
+ @click.stop="handleValueUpdate(null)"
+ />
+
<GeneralIcon
icon="ncChevronDown"
class="flex-none h-4 w-4 transition-transform opacity-70"
diff --git a/packages/nocodb-sdk/src/lib/dashboard/widgetUtils.ts b/packages/nocodb-sdk/src/lib/dashboard/widgetUtils.ts
index dbe9bf6ec6..e80547c1a1 100644
--- a/packages/nocodb-sdk/src/lib/dashboard/widgetUtils.ts
+++ b/packages/nocodb-sdk/src/lib/dashboard/widgetUtils.ts
@@ -5,7 +5,16 @@ import {
WidgetType,
WidgetTypes,
} from '.';
-import { ColumnType, UITypes } from '~/lib';
+import {
+ AllAggregations,
+ ColumnType,
+ isBarcode,
+ isButton,
+ isLookup,
+ isQrCode,
+ isSystemColumn,
+ UITypes,
+} from '~/lib';
export const calculateNextPosition = (
existingWidgets: WidgetType[],
@@ -153,6 +162,34 @@ const getDefaultChartConfig = (
return columns[0]?.id || '';
};
+ const getDefaultYAxisColumn = (columns?: Array<ColumnType>): string => {
+ if (!columns || columns?.length === 0) return '';
+
+ // Priority 1: SingleSelect
+ const singleSelectColumn = columns.find(
+ (col) => col.uidt === UITypes.SingleSelect
+ );
+ if (singleSelectColumn) return singleSelectColumn.id;
+
+ // Priority 2: SingleLineText
+ const singleLineTextColumn = columns.find(
+ (col) => col.uidt === UITypes.SingleLineText
+ );
+ if (singleLineTextColumn) return singleLineTextColumn.id;
+
+ // Fallback: first column
+ return (
+ columns.filter(
+ (col) =>
+ isSystemColumn(col) &&
+ isButton(col) &&
+ isLookup(col) &&
+ isQrCode(col) &&
+ isBarcode(col)
+ )[0]?.id || ''
+ );
+ };
+
switch (chartType) {
case ChartTypes.PIE:
return {
@@ -210,6 +247,42 @@ const getDefaultChartConfig = (
},
};
+ case ChartTypes.BAR:
+ return {
+ ...baseConfig,
+ chartType: ChartTypes.BAR,
+ data: {
+ xAxis: {
+ column_id: getDefaultCategoryColumn(columns),
+ sortBy: 'xAxis' as const,
+ orderBy: 'default' as const,
+ includeEmptyRecords: false,
+ },
+ yAxis: {
+ startAtZero: false,
+ fields: [
+ {
+ column_id: getDefaultYAxisColumn(columns),
+ aggregation: AllAggregations.CountUnique,
+ },
+ ],
+ groupBy: null,
+ },
+ },
+ appearance: {
+ orientation: 'vertical' as const,
+ showDataLabels: false,
+ showLegend: true,
+ legendPosition: 'top' as const,
+ colorSchema: 'default' as const,
+ customColorSchema: [],
+ },
+ permissions: {
+ allowUserToPrint: false,
+ allowUsersToViewRecords: false,
+ },
+ };
+
default:
return {
...baseConfig,