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

Chart support #146

Open
dantownsend opened this issue Jan 27, 2022 · 12 comments
Open

Chart support #146

dantownsend opened this issue Jan 27, 2022 · 12 comments
Labels
enhancement New feature or request

Comments

@dantownsend
Copy link
Member

I'm putting this here as a placeholder to collect thoughts. I don't think it's an immediate priority, but would be cool.

We support form creation using FormConfig. We might be able to add something similar called ChartConfig. It would initially just be for very simple chart types, like bar, line, and pie.

Here's an example:

async def get_data():
    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]

director_chart = ChartConfig(title='Movie count', type=Bar(source=get_data))

create_admin(charts=[director_chart])

There would be a new section in the sidebar:

Screenshot 2022-01-27 at 14 24 09

@dantownsend dantownsend added the enhancement New feature or request label Jan 27, 2022
@dantownsend dantownsend added this to To do in Enhancements via automation Jan 27, 2022
@sinisaos
Copy link
Member

@dantownsend @Fidel-C I've been playing around a bit with adding charts to Picolo Admin. In addition to custom links(#307), we can also have a separate Charts section. The result is this.

charts.mp4

The data format must be a list of lists (eg. data=[["Male", 7], ["Female", 3]]) to satisfy the frontend library (I used the Chartkick library). I used hardcoded data, but any function or coroutine which return list of lists, will satisfy the data format.

@Fidel-C
Copy link

Fidel-C commented May 11, 2023

@sinisaos wow this is really nice

@dantownsend
Copy link
Member Author

@sinisaos Yeah, that's really cool 👍

How large is the chartkick library? We just need to make sure we pick something which doesn't make the bundle size too large.

@dantownsend
Copy link
Member Author

I'm already thinking how I could use this in my own projects ... I think it'll be very useful.

@sinisaos
Copy link
Member

Thank you both for your kind words.
@dantownsend Bundle size

@Fidel-C
Copy link

Fidel-C commented May 19, 2023

@sinisaos is the chart feature now in the official version?

@sinisaos
Copy link
Member

@Fidel-C No it's not. It's just an experiment. I didn't even make a PR because @dantownsend didn't say that the package size of the new Vue library is fine. You can patch a local installation from this branch so you can try it out. First you need to download, then cd into admin_ui directory and npm run build. After that you can add piccolo_admin to your virtualenv site packages (if you are using virtualenv).

@dantownsend
Copy link
Member Author

Sorry, I haven't looked into it yet. Just need to try running the bundle locally, to see how big the compiled JS file is. From the look of the link you shared it doesn't seem too bad though.

@Fidel-C
Copy link

Fidel-C commented May 19, 2023

@sinisaos thanks a lot for your help. But then, charts display has become a major requirement for modern admin panels. Maybe @dantownsend will consider that.

@Fidel-C
Copy link

Fidel-C commented Jun 2, 2023

@dantownsend and @sinisaos Seems this feature has been replaced by the "links" feature?
Cos I'm still looking forward to it.

@dantownsend
Copy link
Member Author

@Fidel-C The chart PR is definitely still valid. I like the links feature because it's generally useful, but I've wanted native chart support for a while. I'm trying to get another PR finished off in the main Piccolo repo, then can turn my attention to these other PRs.

@Fidel-C
Copy link

Fidel-C commented Jun 3, 2023

Alright cool. Will be waiting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

No branches or pull requests

3 participants