-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from opendatateam/chart
chart
- Loading branch information
Showing
16 changed files
with
1,637 additions
and
128 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<script> | ||
import { | ||
Chart, | ||
BarController, | ||
BarElement, | ||
CategoryScale, | ||
LinearScale, | ||
Title, | ||
Tooltip, | ||
Legend, | ||
} from "chart.js"; | ||
Chart.register( | ||
BarController, | ||
BarElement, | ||
CategoryScale, | ||
LinearScale, | ||
Title, | ||
Tooltip, | ||
Legend | ||
); | ||
export default { | ||
name: "HistogramChart", | ||
props: { | ||
chartData: { | ||
type: Array, | ||
required: true, | ||
}, | ||
}, | ||
mounted() { | ||
this.$nextTick(() => { | ||
this.createChart(); | ||
}); | ||
}, | ||
methods: { | ||
createChart() { | ||
if (!this.$refs.histogramChart) { | ||
console.error("Canvas reference is not available."); | ||
return; | ||
} | ||
const ctx = this.$refs.histogramChart.getContext("2d"); | ||
const labels = this.chartData.map((item) => item.x); | ||
const values = this.chartData.map((item) => item.y); | ||
new Chart(ctx, { | ||
type: "bar", | ||
data: { | ||
labels: labels, | ||
datasets: [ | ||
{ | ||
label: "Transactions", | ||
data: values, | ||
backgroundColor: "rgba(75, 192, 192, 0.2)", | ||
borderColor: "rgba(75, 192, 192, 1)", | ||
borderWidth: 1, | ||
}, | ||
], | ||
}, | ||
options: { | ||
responsive: true, | ||
plugins: { | ||
legend: { | ||
display: false, | ||
}, | ||
tooltip: { | ||
enabled: true, | ||
}, | ||
}, | ||
scales: { | ||
x: { | ||
type: "category", | ||
}, | ||
y: { | ||
beginAtZero: true, | ||
}, | ||
}, | ||
...this.chartOptions, | ||
}, | ||
}); | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<canvas ref="histogramChart"></canvas> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,71 @@ | ||
<template> | ||
<div class="tile"> | ||
<h2 class="font-bold mb-2">{{ natureCultureFullName }}</h2> | ||
<p><b>Transactions - {{ level }}</b></p> | ||
<span v-if="data.length > 0"><HistogramChart :chartData="data" :key="chartKey" /></span> | ||
<span v-else>Il n'y a pas de transactions pour ce département.</span> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, computed, ref, watch } from "vue"; | ||
import { NatureCulture } from "@/types/NatureCulture"; | ||
import { defineComponent } from "vue"; | ||
import HistogramChart from '@/components/HistogramChart.vue'; | ||
import monthDepData from "@/assets/json/dvf_month_agri.json"; | ||
import monthNatData from "@/assets/json/dvf_month_agri_nat.json"; | ||
import { useAppStore } from '@/store/appStore.ts'; | ||
export default defineComponent({ | ||
name: "TileTwo", | ||
props: { | ||
selectedNatureCulture: { | ||
type: String, | ||
default: "", | ||
}, | ||
}, | ||
computed: { | ||
natureCultureFullName(): string { | ||
return this.selectedNatureCulture | ||
? NatureCulture[ | ||
this.selectedNatureCulture as keyof typeof NatureCulture | ||
] | ||
: ""; | ||
}, | ||
}, | ||
name: "TileTwo", | ||
components: { | ||
HistogramChart, | ||
}, | ||
props: { | ||
selectedNatureCulture: { | ||
type: String, | ||
default: "", | ||
}, | ||
}, | ||
setup(props) { | ||
const appStore = useAppStore(); | ||
const data = ref(monthNatData["P"]); | ||
const chartKey = ref(0); | ||
const options = { | ||
plugins: { | ||
legend: { | ||
display: true, | ||
position: "top", | ||
}, | ||
}, | ||
}; | ||
const level = ref("National") | ||
const natureCultureFullName = computed((): string => { | ||
return props.selectedNatureCulture | ||
? NatureCulture[props.selectedNatureCulture as keyof typeof NatureCulture] | ||
: ""; | ||
}); | ||
watch(() => appStore.option, (newValue: string) => { | ||
data.value = monthNatData[newValue]; | ||
chartKey.value++; | ||
}); | ||
watch(() => appStore.mouseDep, (newValue: string) => { | ||
data.value = monthDepData[appStore.option][newValue]; | ||
level.value = appStore.mouseDepName; | ||
chartKey.value++; | ||
}); | ||
return { | ||
natureCultureFullName, | ||
data, | ||
options, | ||
chartKey, | ||
level, | ||
}; | ||
}, | ||
}); | ||
</script> | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<script setup lang="ts"> | ||
import type { HTMLAttributes } from 'vue' | ||
import { cn } from '@/utils' | ||
const props = defineProps<{ | ||
class?: HTMLAttributes['class'] | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<div | ||
:class=" | ||
cn( | ||
'rounded-lg border bg-card text-card-foreground shadow-sm', | ||
props.class, | ||
) | ||
" | ||
> | ||
<slot /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script setup lang="ts"> | ||
import type { HTMLAttributes } from 'vue' | ||
import { cn } from '@/utils' | ||
const props = defineProps<{ | ||
class?: HTMLAttributes['class'] | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<div :class="cn('p-6 pt-0', props.class)"> | ||
<slot /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script setup lang="ts"> | ||
import type { HTMLAttributes } from 'vue' | ||
import { cn } from '@/utils' | ||
const props = defineProps<{ | ||
class?: HTMLAttributes['class'] | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<p :class="cn('text-sm text-muted-foreground', props.class)"> | ||
<slot /> | ||
</p> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script setup lang="ts"> | ||
import type { HTMLAttributes } from 'vue' | ||
import { cn } from '@/utils' | ||
const props = defineProps<{ | ||
class?: HTMLAttributes['class'] | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<div :class="cn('flex items-center p-6 pt-0', props.class)"> | ||
<slot /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script setup lang="ts"> | ||
import type { HTMLAttributes } from 'vue' | ||
import { cn } from '@/utils' | ||
const props = defineProps<{ | ||
class?: HTMLAttributes['class'] | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<div :class="cn('flex flex-col gap-y-1.5 p-6', props.class)"> | ||
<slot /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<script setup lang="ts"> | ||
import type { HTMLAttributes } from 'vue' | ||
import { cn } from '@/utils' | ||
const props = defineProps<{ | ||
class?: HTMLAttributes['class'] | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<h3 | ||
:class=" | ||
cn('text-2xl font-semibold leading-none tracking-tight', props.class) | ||
" | ||
> | ||
<slot /> | ||
</h3> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export { default as Card } from './Card.vue' | ||
export { default as CardContent } from './CardContent.vue' | ||
export { default as CardDescription } from './CardDescription.vue' | ||
export { default as CardFooter } from './CardFooter.vue' | ||
export { default as CardHeader } from './CardHeader.vue' | ||
export { default as CardTitle } from './CardTitle.vue' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
import { defineStore } from "pinia"; | ||
|
||
export const useAppStore = defineStore("appStore", { | ||
state: () => ({ | ||
option: "P", | ||
mapZoom: 5.2, | ||
address: [1, 1], | ||
}), | ||
actions: { | ||
updateOption(newOption: string) { | ||
this.option = newOption; | ||
}, | ||
updateMapZoom(zoom: number) { | ||
this.mapZoom = zoom; | ||
}, | ||
updateAddress(address: any) { | ||
this.address = address; | ||
}, | ||
}, | ||
}); | ||
export const useAppStore = defineStore('appStore', { | ||
state: () => ({ | ||
option: 'P', | ||
mapZoom: 5.2, | ||
address: [1,1], | ||
mouseDep: "", | ||
mouseDepName: "", | ||
}), | ||
actions: { | ||
updateOption(newOption: string) { | ||
this.option = newOption; | ||
}, | ||
updateMapZoom(zoom: number){ | ||
this.mapZoom = zoom; | ||
}, | ||
updateAddress(address: any){ | ||
this.address = address | ||
}, | ||
updateMouseDep(dep: string){ | ||
this.mouseDep = dep; | ||
}, | ||
updateMouseDepName(depName: string){ | ||
this.mouseDepName = depName; | ||
}, | ||
}, | ||
}); |