From 6f0612565062d50e16ff7de02ce793a0297e8475 Mon Sep 17 00:00:00 2001 From: UmakanthKaspa Date: Tue, 10 Dec 2024 11:38:18 +0000 Subject: [PATCH 1/2] feat: add rotate labels feature for bar chart --- .../charts/components/BarChartConfigForm.vue | 6 ++++++ frontend/src2/charts/helpers.ts | 18 ++++++++++++++++-- frontend/src2/types/chart.types.ts | 13 ++++++++++--- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/frontend/src2/charts/components/BarChartConfigForm.vue b/frontend/src2/charts/components/BarChartConfigForm.vue index a171afb1..4a8abc8f 100644 --- a/frontend/src2/charts/components/BarChartConfigForm.vue +++ b/frontend/src2/charts/components/BarChartConfigForm.vue @@ -52,6 +52,12 @@ const hasAxisSplit = computed(() => { + diff --git a/frontend/src2/charts/helpers.ts b/frontend/src2/charts/helpers.ts index 7cfaec86..97a68304 100644 --- a/frontend/src2/charts/helpers.ts +++ b/frontend/src2/charts/helpers.ts @@ -148,6 +148,16 @@ export function getBarChartOptions(config: BarChartConfig, result: QueryResult, const hasRightAxis = config.y_axis.series.some((s) => s.align === 'Right') const yAxis = !hasRightAxis ? [leftYAxis] : [leftYAxis, rightYAxis] + const labelRotation = Math.max(0, Math.min(config.label_rotation || 0, 90)) + + const updatedXAxis = { + ...xAxis, + axisLabel: { + ...(xAxis.axisLabel || {}), + rotate: labelRotation, + }, + } + const sortedRows = xAxisIsDate ? _rows.sort((a, b) => { const a_date = new Date(a[config.x_axis.dimension_name]) @@ -186,8 +196,8 @@ export function getBarChartOptions(config: BarChartConfig, result: QueryResult, animationDuration: 700, color: colors, grid: getGrid({ show_legend }), - xAxis: swapAxes ? yAxis : xAxis, - yAxis: swapAxes ? xAxis : yAxis, + xAxis: swapAxes ? yAxis : updatedXAxis, + yAxis: swapAxes ? updatedXAxis : yAxis, series: number_columns.map((c, idx) => { const serie = getSerie(config, c.name) const is_right_axis = serie.align === 'Right' @@ -266,6 +276,10 @@ function getXAxis(options: XAxisCustomizeOptions = {}) { splitLine: { show: false }, axisLine: { show: true }, axisTick: { show: false }, + axisLabel: { + show: true, + rotate: 0, + }, } } diff --git a/frontend/src2/types/chart.types.ts b/frontend/src2/types/chart.types.ts index ec661a96..a11fd205 100644 --- a/frontend/src2/types/chart.types.ts +++ b/frontend/src2/types/chart.types.ts @@ -1,4 +1,4 @@ -import { Dimension, Measure } from "./query.types" +import { Dimension, Measure } from './query.types' export const AXIS_CHARTS = ['Bar', 'Line', 'Row'] export type AxisChartType = (typeof AXIS_CHARTS)[number] @@ -51,6 +51,7 @@ export type SeriesBar = Series & { export type BarChartConfig = AxisChartConfig & { y_axis: YAxisBar + label_rotation?: number } export type LineChartConfig = AxisChartConfig & { y_axis: YAxisLine @@ -83,7 +84,7 @@ export type DountChartConfig = { label_column: Dimension value_column: Measure legend_position?: 'top' | 'bottom' | 'left' | 'right' - show_inline_labels?: boolean; + show_inline_labels?: boolean } export type FunnelChartConfig = { label_column: Dimension @@ -100,4 +101,10 @@ export type TableChartConfig = { conditional_formatting?: boolean } -export type ChartConfig = LineChartConfig | BarChartConfig | NumberChartConfig | DountChartConfig | TableChartConfig | FunnelChartConfig +export type ChartConfig = + | LineChartConfig + | BarChartConfig + | NumberChartConfig + | DountChartConfig + | TableChartConfig + | FunnelChartConfig From c5ae3d5d34be692ccce350c5922c4cf19bf4780e Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Mon, 20 Jan 2025 16:58:33 +0530 Subject: [PATCH 2/2] refactor: move label rotation to x axis config --- .../charts/components/BarChartConfigForm.vue | 8 +---- .../src2/charts/components/XAxisConfig.vue | 19 +++++++++-- frontend/src2/charts/helpers.ts | 34 +++++++------------ frontend/src2/types/chart.types.ts | 4 +-- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/frontend/src2/charts/components/BarChartConfigForm.vue b/frontend/src2/charts/components/BarChartConfigForm.vue index 6c3686a1..3a30b0a3 100644 --- a/frontend/src2/charts/components/BarChartConfigForm.vue +++ b/frontend/src2/charts/components/BarChartConfigForm.vue @@ -1,7 +1,7 @@