diff --git a/frontend/src2/charts/components/DonutChartConfigForm.vue b/frontend/src2/charts/components/DonutChartConfigForm.vue index 7b0b39680..3f7fcdc59 100644 --- a/frontend/src2/charts/components/DonutChartConfigForm.vue +++ b/frontend/src2/charts/components/DonutChartConfigForm.vue @@ -1,5 +1,5 @@ @@ -43,6 +277,133 @@ const discrete_dimensions = computed(() => v-model="config.label_column" :options="discrete_dimensions" /> + + + {{ __('Color Palette') }} + + + + + + + + + + + + + + + + + + + + + + + + + {{ __('Pick a color for slot') }} {{ (editingIdx ?? 0) + 1 }} + + + ✕ + + + + + + + + + {{ __('Custom hex') }} + + + { + if (editingIdx !== null) + handleNativeColorInput(e, editingIdx) + } + " + /> + + + + + + d[1]) const total = values.reduce((a, b) => a + b, 0) - const colors = getColors() + const baseColors = config.label_colors?.length ? config.label_colors : getColors() + const colors = labels.map((_, i) => baseColors[i % baseColors.length]) let center, radius, top, left, right, bottom, padding, orient const legend_position = config.legend_position || 'bottom' @@ -443,18 +445,20 @@ export function getDonutChartOptions(config: DonutChartConfig, result: QueryResu animation: true, animationDuration: 700, color: colors, - dataset: { source: data }, series: [ { type: 'pie', name: valueColumn?.name, center, radius, + data: labels.map((label, i) => ({ + name: label, + value: values[i], + itemStyle: { color: colors[i] }, + })), labelLine: { show: show_inline_labels, - lineStyle: { - width: 2, - }, + lineStyle: { width: 2 }, length: 10, length2: 20, smooth: true, @@ -462,7 +466,7 @@ export function getDonutChartOptions(config: DonutChartConfig, result: QueryResu label: { show: show_inline_labels, formatter: ({ value, name }: any) => { - const percentage = total > 0 ? (value[1] / total) * 100 : 0 + const percentage = total > 0 ? (value / total) * 100 : 0 return `${ellipsis(name, 20)} (${percentage.toFixed(0)}%)` }, }, @@ -484,9 +488,7 @@ export function getDonutChartOptions(config: DonutChartConfig, result: QueryResu return `${ellipsis(name, 20)} (${percentage.toFixed(0)}%)` }, } - : { - show: false, - }, + : { show: false }, tooltip: { trigger: 'item', confine: true, @@ -564,10 +566,6 @@ export function getFunnelChartOptions(config: FunnelChartConfig, result: QueryRe sort: 'descending', label: { show: true, - // position doesn't have any effect - // it is mapped here to re-render when the label position changes - // because the label layout function is not changing when the label position changes - // and so the chart doesn't re-render position: labelPosition, color: '#565656', lineHeight: 16, @@ -813,6 +811,7 @@ export function getMapChartOptions(config: MapChartConfig, result: QueryResult) pieces: mapPieces(values), itemSymbol: 'circle', inRange: { + color: ['#dbeeff', '#b7ddff', '#92cdff', '#6ebcff', '#4aabff'], }, }, diff --git a/frontend/src2/types/chart.types.ts b/frontend/src2/types/chart.types.ts index 2a6d59b7a..25ae986a2 100644 --- a/frontend/src2/types/chart.types.ts +++ b/frontend/src2/types/chart.types.ts @@ -18,6 +18,7 @@ export type XAxis = { label_rotation?: number } + export type SplitBy = { dimension: Dimension max_split_values?: number @@ -101,6 +102,7 @@ export type DonutChartConfig = { legend_position?: 'top' | 'bottom' | 'left' | 'right' max_slices?: number show_inline_labels?: boolean + label_colors?: string[] } export type FunnelChartConfig = { label_column: Dimension