Skip to content

Commit

Permalink
feat: color picker for line & bar charts
Browse files Browse the repository at this point in the history
  • Loading branch information
nextchamp-saqib committed Oct 10, 2022
1 parent b91deae commit 87820a5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
10 changes: 7 additions & 3 deletions frontend/src/components/Controls/Color.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<div class="mb-1 text-sm text-gray-600" v-if="label">
<div class="mb-1 text-sm text-gray-500" v-if="label">
{{ label }}
</div>
<Popover placement="bottom-start" class="w-full">
Expand All @@ -23,7 +23,7 @@
? value
: [value]"
:key="idx"
class="h-5 w-5 rounded-full"
class="h-4 w-4 rounded-full"
:style="{ backgroundColor: color }"
></div>
</div>
Expand Down Expand Up @@ -179,7 +179,11 @@ export default {
return this.options || Object.values(COLOR_MAP)
},
selectedColorLabel() {
return this.multiple ? this.modelValue.length + ' colors selected' : this.modelValue
return this.multiple
? this.modelValue.length > 1
? `${this.modelValue.length} colors`
: this.value[0]
: this.value
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Query/Visualize/BarChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const props = defineProps({
</script>

<template>
<Chart :title="props.title" :subtitle="props.subtitle">
<Chart :title="props.title" :subtitle="props.subtitle" :color="props.options.colors">
<ChartGrid>
<ChartLegend type="scroll" bottom="bottom" />
<ChartAxis
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/components/Query/Visualize/BarChartOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { inject } from 'vue'
import Autocomplete from '@/components/Controls/Autocomplete.vue'
import ListPicker from '@/components/Controls/ListPicker.vue'
import Color from '@/components/Controls/Color.vue'
const query = inject('query')
const chart = inject('chart')
Expand All @@ -21,4 +22,11 @@ const chart = inject('chart')
@change="(options) => (chart.data.valueColumn = options)"
/>
</div>

<Color
label="Colors"
v-model="chart.options.colors"
:max="chart.data?.valueColumn?.length || 1"
multiple
/>
</template>
2 changes: 1 addition & 1 deletion frontend/src/components/Query/Visualize/LineChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const props = defineProps({
</script>

<template>
<Chart :title="props.title" :subtitle="props.subtitle">
<Chart :title="props.title" :subtitle="props.subtitle" :color="props.options.colors">
<ChartGrid>
<ChartLegend type="scroll" bottom="bottom" />
<ChartAxis
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/components/Query/Visualize/LineChartOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { inject } from 'vue'
import Checkbox from '@/components/Controls/Checkbox.vue'
import Autocomplete from '@/components/Controls/Autocomplete.vue'
import ListPicker from '@/components/Controls/ListPicker.vue'
import Color from '@/components/Controls/Color.vue'
const query = inject('query')
const chart = inject('chart')
Expand All @@ -23,6 +24,13 @@ const chart = inject('chart')
/>
</div>

<Color
label="Colors"
v-model="chart.options.colors"
:max="chart.data?.valueColumn?.length || 1"
multiple
/>
<div class="space-y-2 text-gray-600">
<Checkbox v-model="chart.options.smoothLines" label="Enable Curved Lines" />
</div>
Expand Down

0 comments on commit 87820a5

Please sign in to comment.