Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix WithKeyPoints for f32 / f64 ranges#653

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
AaronErhardt merged 1 commit intoplotters-rs:masterfromoldgalileo:master
Nov 8, 2024

Conversation

oldgalileo
Copy link
Contributor

Allow usingf32 key point ranges when constructing a Cartesian2d chart:

fnmain() ->Result<_>{// Chart setup ...letmut chart =ChartBuilder::on(&top).x_label_area_size(20).y_label_area_size(40).build_cartesian_2d((0f32..10f32).with_key_points((0f32..10f32).step(0.5).values().map(|x| x*PI).collect()),0f32..2.5f32).unwrap();        chart.configure_mesh().x_labels(5).y_labels(2).draw()?;// Draw stuff ...}

This code fails to compile, and will complain with the following:

error[E0599]: the method `configure_mesh` exists for struct `ChartContext<'_, BitMapBackend<'_>, Cartesian2d<WithKeyPoints<RangedCoordf32>, RangedCoordf32>>`, but its trait bounds were not satisfied  --> src/bin/plotting.rs:30:11   |30 |     chart.configure_mesh()   |           ^^^^^^^^^^^^^^ method cannot be called due to unsatisfied trait bounds   |  ::: $HOME/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.7/src/coord/ranged1d/combinators/ckps.rs:16:1   |16 | pub struct WithKeyPoints<Inner: Ranged> {   | --------------------------------------- doesn't satisfy `<_ as Ranged>::FormatOption = DefaultFormatting` or `WithKeyPoints<RangedCoordf32>: ValueFormatter<f32>`   |   = note: the following trait bounds were not satisfied:           `<WithKeyPoints<RangedCoordf32> as plotters::prelude::Ranged>::FormatOption = DefaultFormatting`           which is required by `WithKeyPoints<RangedCoordf32>: ValueFormatter<f32>`

My change addresses the immediate issue, although I suspect there's a more elegant fix here. Couldn't find a quick fix for the issue of a default implementation not existing whenT::FormatOption != DefaultFormatting, but it occurred to me that maybe a macro at least would be better? Although conversely it's only for f32 and f64 at the moment so I'm not sure.

Copy link
Contributor

@10ne110ne1 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@AaronErhardtAaronErhardt left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@AaronErhardtAaronErhardt merged commit48ed63f intoplotters-rs:masterNov 8, 2024
18 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@10ne110ne110ne1 approved these changes

@AaronErhardtAaronErhardtAaronErhardt approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@oldgalileo@10ne1@AaronErhardt

[8]ページ先頭

©2009-2025 Movatter.jp