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: add rotate labels feature for bar chart #389

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions frontend/src2/charts/components/BarChartConfigForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ const hasAxisSplit = computed(() => {
<Checkbox label="Normalize" v-model="(y_axis as YAxisBar).normalize" />
</template>
</YAxisConfig>
<FormControl
v-model="config.label_rotation"
label="Rotate Labels (degrees)"
type="number"
placeholder="0"
/>

<SplitByConfig v-model="config.split_by" :dimensions="props.dimensions" />
</template>
18 changes: 16 additions & 2 deletions frontend/src2/charts/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -266,6 +276,10 @@ function getXAxis(options: XAxisCustomizeOptions = {}) {
splitLine: { show: false },
axisLine: { show: true },
axisTick: { show: false },
axisLabel: {
show: true,
rotate: 0,
},
}
}

Expand Down
13 changes: 10 additions & 3 deletions frontend/src2/types/chart.types.ts
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -51,6 +51,7 @@ export type SeriesBar = Series & {

export type BarChartConfig = AxisChartConfig & {
y_axis: YAxisBar
label_rotation?: number
UmakanthKaspa marked this conversation as resolved.
Show resolved Hide resolved
}
export type LineChartConfig = AxisChartConfig & {
y_axis: YAxisLine
Expand Down Expand Up @@ -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
Expand All @@ -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