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

Charts support #311

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
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
79 changes: 76 additions & 3 deletions admin_ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions admin_ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
"@fortawesome/vue-fontawesome": "^0.1.10",
"@types/js-cookie": "^2.2.6",
"axios": "^0.21.2",
"chart.js": "^4.3.0",
"core-js": "^3.6.5",
"flatpickr": "^4.6.9",
"highcharts": "^11.0.1",
"is-svg": "^4.3.1",
"js-cookie": "^2.2.1",
"json-bigint": "^1.0.0",
"ssri": "^8.0.1",
"vue": "^2.7.14",
"vue-chartkick": "^0.6.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the interaction between chart.js, highcharts and vue-chartkick?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is chart.js redundant? It looks like we're just using highcharts?

Copy link
Member

@dantownsend dantownsend Jun 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried chart.js? It's slightly smaller than highcharts, and it supports tree shaking, so we might get a smaller bundle size:

https://bundlephobia.com/package/[email protected]
https://bundlephobia.com/package/[email protected]

Also, the licensing on highcharts looks complicated, so I'd rather stay away from it. chart.js is MIT like Piccolo Admin.

https://github.com/chartjs/Chart.js/blob/master/LICENSE.md

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake. I tried both libraries, so it accidentally stayed in package.json. This PR uses highcharts, but I will switch to Chart.js in the next commit.

"vue-class-component": "^7.2.6",
"vue-flatpickr-component": "^8.1.7",
"vue-i18n": "^8.27.2",
Expand Down
31 changes: 31 additions & 0 deletions admin_ui/src/components/ChartsNav.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<template>
<ul>
<li v-bind:key="chartConfig.title" v-for="chartConfig in chartConfigs">
<router-link
:to="{
name: 'getCharts',
params: { chartSlug: chartConfig.chart_slug }
}"
class="subtle"
>
<font-awesome-icon icon="level-up-alt" class="rotated90" />
<span>{{ chartConfig.title }}</span>
</router-link>
</li>
</ul>
</template>

<script lang="ts">
import Vue from "vue"

export default Vue.extend({
computed: {
chartConfigs() {
return this.$store.state.chartConfigs
}
},
async mounted() {
await this.$store.dispatch("fetchChartConfigs")
}
})
</script>
44 changes: 44 additions & 0 deletions admin_ui/src/components/ChartsPage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<template>
<div>
<h3>{{ chartConfigs.title }}</h3>
<pie-chart
v-if="chartConfigs.chart_type == 'Pie'"
:data="chartConfigs.data"
></pie-chart>
<line-chart
v-else-if="chartConfigs.chart_type == 'Line'"
:data="chartConfigs.data"
></line-chart>
<column-chart
v-else-if="chartConfigs.chart_type == 'Column'"
:data="chartConfigs.data"
></column-chart>
<bar-chart
v-else-if="chartConfigs.chart_type == 'Bar'"
:data="chartConfigs.data"
></bar-chart>
<area-chart
v-else-if="chartConfigs.chart_type == 'Area'"
:data="chartConfigs.data"
></area-chart>
</div>
</template>

<script lang="ts">
import Vue from "vue"

export default Vue.extend({
computed: {
chartConfigs() {
return this.$store.state.chartConfigs
}
}
})
</script>

<style scoped lang="less">
h3 {
text-transform: capitalize;
text-align: center;
}
</style>
22 changes: 22 additions & 0 deletions admin_ui/src/components/SidebarNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@
</span>
</p>
<FormNav v-show="!isHiddenForms" />
<p
class="opaque"
v-if="chartConfigs.length > 0"
v-on:click="isHiddenCharts = !isHiddenCharts"
>
<font-awesome-icon icon="chart-bar" />{{ $t("Charts") }}
<span style="float: right">
<font-awesome-icon
icon="angle-down"
title="Show charts"
v-if="isHiddenCharts"
/>
<font-awesome-icon icon="angle-up" title="Hide charts" v-else />
</span>
</p>
<ChartsNav v-show="!isHiddenCharts" />
<p
class="opaque"
v-if="Object.keys(customLinks).length > 0"
Expand All @@ -56,25 +72,31 @@
import Vue from "vue"
import TableNav from "./TableNav.vue"
import FormNav from "./FormNav.vue"
import ChartsNav from "./ChartsNav.vue"
import LinksNav from "./LinksNav.vue"

export default Vue.extend({
data() {
return {
isHiddenTables: false,
isHiddenForms: false,
isHiddenCharts: false,
isHiddenLinks: false
}
},
components: {
TableNav,
FormNav,
ChartsNav,
LinksNav
},
computed: {
formConfigs() {
return this.$store.state.formConfigs
},
chartConfigs() {
return this.$store.state.chartConfigs
},
customLinks() {
return this.$store.state.customLinks
}
Expand Down
2 changes: 1 addition & 1 deletion admin_ui/src/components/TableNav.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div>
<div class="sidebar_wrapper">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for a menu sidebar of equal width between the Home page and other pages. Now this is not the case because the sidebar menu on the Home page is wider than on other pages. I can remove it if you want?

<ul class="table_list">
<TableNavItem
v-bind:key="tableName"
Expand Down
2 changes: 2 additions & 0 deletions admin_ui/src/fontawesome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
faBars,
faCaretUp,
faCaretDown,
faChartBar,
faCheck,
faCircleNotch,
faCogs,
Expand Down Expand Up @@ -54,6 +55,7 @@ library.add(
faBars,
faCaretUp,
faCaretDown,
faChartBar,
faCheck,
faCircleNotch,
faCogs,
Expand Down
7 changes: 7 additions & 0 deletions admin_ui/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,10 @@ export interface FormConfig {
slug: string
description: string
}

export interface ChartConfig {
title: string
chart_slug: string
chart_type: string
data: any
}
23 changes: 23 additions & 0 deletions admin_ui/src/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,29 @@ button {
.ql-picker-label {
color: white
}

.highcharts-background {
fill: @dark_grey;

}

.highcharts-axis-labels.highcharts-xaxis-labels {
text[style] {
fill: white !important;
}
}

.highcharts-axis-labels.highcharts-yaxis-labels {
text[style] {
fill: white !important;
}
}

.highcharts-axis.highcharts-xaxis {
.highcharts-axis-line {
stroke: white !important;
}
}
}

#app {
Expand Down
Loading