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 experiments #316

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft

Chart experiments #316

wants to merge 17 commits into from

Conversation

dantownsend
Copy link
Member

Based on #311

The only real change is the data is calculated dynamically each time the endpoint is called.

@sinisaos
Copy link
Member

sinisaos commented Jul 1, 2023

@dantownsend This is great. You can use the changes from the last commit from the Charts support branch because only Chart.js is used there and there are changes in chart size, typo fixes, etc.

@dantownsend
Copy link
Member Author

@sinisaos Good catch - I've updated it with your latest changes.

@dantownsend
Copy link
Member Author

@sinisaos I like the way chart.js looks.

Screenshot 2023-07-01 at 08 27 50

The only problem is dark mode where the labels are harder to see.

Screenshot 2023-07-01 at 08 27 56

Do you know if Chart.js supports dark mode, or we can configure the label colours somehow?

@sinisaos
Copy link
Member

sinisaos commented Jul 1, 2023

@dantownsend I don't know, but there's probably some way to change it through css or something.

Copy link
Member

Choose a reason for hiding this comment

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

Now I noticed that the image in the docs is wrong (use Highcharts and not Chart.js), so if you can change that too.

Copy link
Member Author

Choose a reason for hiding this comment

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

@sinisaos OK will change that

@codecov-commenter
Copy link

codecov-commenter commented Jul 1, 2023

Codecov Report

Merging #316 (96fde3d) into master (8731cad) will decrease coverage by 1.01%.
The diff coverage is 85.10%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##           master     #316      +/-   ##
==========================================
- Coverage   93.31%   92.30%   -1.01%     
==========================================
  Files           5        5              
  Lines         359      403      +44     
==========================================
+ Hits          335      372      +37     
- Misses         24       31       +7     
Impacted Files Coverage Δ
piccolo_admin/translations/data.py 100.00% <ø> (ø)
piccolo_admin/endpoints.py 91.59% <85.10%> (-1.02%) ⬇️

@dantownsend
Copy link
Member Author

dantownsend commented Jul 1, 2023

@sinisaos I had an idea ... will play around with it to see how easy it is. We can let the user specify a Pydantic model which is used to configure the chart.

For example:

class ChartModel(BaseModel):
    genre: str | None = None

async def get_director_movie_count(model: ChartModel):
    query = (
        await Movie.select(
            Movie.director.name.as_alias("director"), Count(Movie.id)
        )
        .group_by(Movie.director)
        .order_by(Movie.director.name)
    )
    if model.genre:
        query = query.where(Movie.genre == model.genre)
    movies = await query()
    return [(i["director"], i["count"]) for i in movies]

APP = create_admin(
    charts=[
        ChartConfig(
            title="Movies per director",
            chart_type="Pie",
            data_source=get_director_movie_count,
        ),
    ]
)

On the chart page we then have a button which opens a modal containing a form based on the Pydantic model. In this case there's a text input where the user can specify a genre, and then the chart just shows the number of movies per director in that genre.

@sinisaos
Copy link
Member

sinisaos commented Jul 2, 2023

@dantownsend That would be interesting. I don't know how complicated it is to implement because you also need to check if the user types a good term and maybe you should use a list of predefined terms (and then use the select dropdown) to prevent bad terms.

@@ -45,6 +47,7 @@ Vue.filter("readable", function (value) {
/*****************************************************************************/

Vue.config.productionTip = false
Vue.use(Chartkick.use(Chart))

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// charts font color and gridlines in dark mode
if (localStorage.getItem('darkMode')) {
Chart.defaults.global.defaultFontColor = "#ffffff"
Chart.defaults.scale.gridLines.color = "#ffffff"
}

Copy link
Member

Choose a reason for hiding this comment

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

This is a way to change Chart.js colors in dark mode, but unfortunately it doesn't work without refreshing the page. I'm sorry I didn't check before posting the suggested change.

Copy link
Member Author

Choose a reason for hiding this comment

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

No worries, it's still useful - there might be a way to reload the chart without reloading the entire page.

@dantownsend
Copy link
Member Author

@sinisaos I got the chart filtering working:

chart_demo.mov

@sinisaos sinisaos mentioned this pull request Jul 3, 2023
@sinisaos
Copy link
Member

sinisaos commented Jul 3, 2023

@dantownsend Wow, that looks and works great and I think it's really useful.

@dantownsend
Copy link
Member Author

@sinisaos Thanks, I think it's pretty cool.

@github-actions
Copy link

github-actions bot commented Aug 4, 2023

This PR has been marked as stale because it has been open for 30 days with no activity. Are there any blockers, or should this be closed?

@github-actions github-actions bot added the Stale label Aug 4, 2023
@dantownsend
Copy link
Member Author

I have a bunch of changes for this - just need to push them up.

@github-actions github-actions bot removed the Stale label Aug 7, 2023
@github-actions
Copy link

github-actions bot commented Sep 7, 2023

This PR has been marked as stale because it has been open for 30 days with no activity. Are there any blockers, or should this be closed?

@github-actions github-actions bot added the Stale label Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants