-
Notifications
You must be signed in to change notification settings - Fork 45
Charts support #311
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
Closed
Closed
Charts support #311
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c3c19a2
add charts support
sinisaos 9ec5ccc
Resolved merge conflict
sinisaos cafb5c4
fix Playwright tests
sinisaos 9ff7282
fix charts in dark mode
sinisaos bc19e7c
Merge branch 'piccolo-orm:master' into charts_support
sinisaos 6d8909a
Merge branch 'piccolo-orm:master' into charts_support
sinisaos da9fe50
add suggested changes
sinisaos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,31 @@ | ||
| <template> | ||
| <ul> | ||
| <li v-bind:key="chartConfig.title" v-for="chartConfig in chartConfigs"> | ||
| <router-link | ||
| :to="{ | ||
| name: 'chart', | ||
| 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> |
This file contains hidden or 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,59 @@ | ||
| <template> | ||
| <div> | ||
| <h3>{{ chartConfigs.title }}</h3> | ||
| <pie-chart | ||
| width="650px" | ||
| height="450px" | ||
| :download="{ background: '#ffffff' }" | ||
| v-if="chartConfigs.chart_type == 'Pie'" | ||
| :data="chartConfigs.data" | ||
| ></pie-chart> | ||
| <line-chart | ||
| width="650px" | ||
| height="450px" | ||
| :download="{ background: '#ffffff' }" | ||
| v-else-if="chartConfigs.chart_type == 'Line'" | ||
| :data="chartConfigs.data" | ||
| ></line-chart> | ||
| <column-chart | ||
| width="650px" | ||
| height="450px" | ||
| :download="{ background: '#ffffff' }" | ||
| v-else-if="chartConfigs.chart_type == 'Column'" | ||
| :data="chartConfigs.data" | ||
| ></column-chart> | ||
| <bar-chart | ||
| width="650px" | ||
| height="450px" | ||
| :download="{ background: '#ffffff' }" | ||
| v-else-if="chartConfigs.chart_type == 'Bar'" | ||
| :data="chartConfigs.data" | ||
| ></bar-chart> | ||
| <area-chart | ||
| width="650px" | ||
| height="450px" | ||
| :download="{ background: '#ffffff' }" | ||
| 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> |
This file contains hidden or 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 hidden or 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,5 +1,5 @@ | ||
| <template> | ||
| <div> | ||
| <div class="sidebar_wrapper"> | ||
| <ul class="table_list"> | ||
| <TableNavItem | ||
| v-bind:key="tableName" | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,29 @@ | ||
| <template> | ||
| <DetailViewBase> | ||
| <ChartsPage :chartSlug="chartSlug" /> | ||
| </DetailViewBase> | ||
| </template> | ||
|
|
||
|
|
||
| <script lang="ts"> | ||
| import Vue from "vue" | ||
| import ChartsPage from "../components/ChartsPage.vue" | ||
| import DetailViewBase from "../components/DetailViewBase.vue" | ||
|
|
||
| export default Vue.extend({ | ||
| props: { | ||
| chartSlug: String | ||
| }, | ||
| components: { | ||
| ChartsPage, | ||
| DetailViewBase | ||
| }, | ||
| async mounted() { | ||
| await this.$store.dispatch("fetchChartConfig", this.chartSlug) | ||
| } | ||
| }) | ||
| </script> | ||
|
|
||
|
|
||
| <style scoped lang="less"> | ||
| </style> |
This file contains hidden or 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,43 @@ | ||
| import asyncio | ||
|
|
||
| from fastapi import FastAPI | ||
| from fastapi.routing import Mount | ||
| from home.tables import Director, Movie | ||
|
|
||
| from piccolo_admin.endpoints import ChartConfig, create_admin | ||
|
|
||
|
|
||
| # count directors movies | ||
| async def director_movie_count(): | ||
| movies = await Movie.select( | ||
| Movie.director.name.as_alias("director"), | ||
| Count(Movie.id), | ||
| ).group_by(Movie.director) | ||
| # Flatten the response so it's a list of lists | ||
| # like [['George Lucas', 3], ...] | ||
| return [[i["director"], i["count"]] for i in movies] | ||
|
|
||
|
|
||
| chart_data = asyncio.run(director_movie_count()) | ||
|
|
||
|
|
||
| director_chart = ChartConfig( | ||
| title="Movie count", | ||
| chart_type="Pie", | ||
| data=chart_data, | ||
| ) | ||
|
|
||
|
|
||
| app = FastAPI( | ||
| routes=[ | ||
| Mount( | ||
| "/admin/", | ||
| create_admin( | ||
| tables=[Director, Movie], | ||
| charts=[director_chart], | ||
| ), | ||
| ), | ||
| ], | ||
| ) | ||
|
|
||
| # For Starlette it is identical, just `app = Starlette(...)` |
This file contains hidden or 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,9 @@ | ||
| from piccolo.columns.column_types import Varchar, ForeignKey | ||
| from piccolo.table import Table | ||
|
|
||
| class Director(Table): | ||
| name = Varchar() | ||
|
|
||
| class Movie(Table): | ||
| title = Varchar() | ||
| director = ForeignKey(references=Director) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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,32 @@ | ||
| .. _Charts: | ||
|
|
||
| Charts | ||
| ====== | ||
|
|
||
| Piccolo Admin can display different types of charts based on your | ||
| data. Five chart types are supported: ``Pie``, ``Line``, ``Column``, | ||
| ``Bar`` and ``Area``. | ||
|
|
||
| Here's an example of charts usage, using FastAPI: | ||
|
|
||
| .. literalinclude:: ./examples/app.py | ||
|
|
||
| Piccolo Admin will then show a chart in the UI. | ||
|
|
||
| .. image:: ./images/charts_sidebar.png | ||
|
|
||
| .. image:: ./images/chart.png | ||
|
|
||
| .. hint:: | ||
|
|
||
| The data format must be a list of lists | ||
| (e.g. ``[["Male", 7], ["Female", 3]]``). | ||
|
|
||
| ------------------------------------------------------------------------------- | ||
|
|
||
| Source | ||
| ------ | ||
|
|
||
| .. currentmodule:: piccolo_admin.endpoints | ||
|
|
||
| .. autoclass:: ChartConfig |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this for?
There was a problem hiding this comment.
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
Homepage and other pages. Now this is not the case because the sidebar menu on theHomepage is wider than on other pages. I can remove it if you want?