emilk / emilk/egui

Using BoxElem to draw candlestick charts, rendering anomalies occur at the corners of individual bars, appearing as extra pigment points.

Open
#7,733 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Rust
Stars
30.6k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
72

Description

Describe the bug
Using BoxElem to draw candlestick charts, rendering anomalies occur at the corners of individual bars, appearing as extra pigment points.

To Reproduce
Steps to reproduce the behavior:
code like

use egui::{Color32, Stroke};
use egui_plot::{BoxElem, BoxPlot, BoxSpread, Plot};
/// https://github.com/mikael-nilsson-github/egui-candlestick-chart/tree/main 
pub struct App {
    value: f64,
}

impl App {
    pub fn new(_cc: &eframe::CreationContext<'_>) -> Self {
        Self {
            value: 42.0,
        }
    }
}

fn candlestick_chart(ui: &mut egui::Ui) {
    let red = Color32::from_rgb(255,0,0);
    let green = Color32::from_rgb(0,255,0);
    let data = BoxPlot::new("",vec![
        BoxElem::new(0.3, BoxSpread::new(1.5, 2.2, 2.2, 2.6, 3.1)).whisker_width(0.0).fill(green).stroke(Stroke::new(2.0, green)),
        BoxElem::new(0.6, BoxSpread::new(1.5, 2.4, 2.4, 2.8, 3.5)).whisker_width(0.0).fill(green).stroke(Stroke::new(2.0, green)),
        BoxElem::new(0.9, BoxSpread::new(1.8, 2.0, 2.4, 2.5, 2.7)).whisker_width(0.0).fill(red).stroke(Stroke::new(2.0, red)),
        BoxElem::new(1.2, BoxSpread::new(1.5, 1.8, 1.8, 2.1, 2.2)).whisker_width(0.0).fill(red).stroke(Stroke::new(2.0, red)),
        BoxElem::new(1.5, BoxSpread::new(1.4, 1.6, 1.6, 1.8, 2.1)).whisker_width(0.0).fill(red).stroke(Stroke::new(2.0, red)),
        BoxElem::new(1.8, BoxSpread::new(0.5, 1.5, 1.5, 1.6, 1.7)).whisker_width(0.0).fill(red).stroke(Stroke::new(2.0, red)),
        BoxElem::new(2.1, BoxSpread::new(1.2, 1.4, 1.4, 2.9, 3.2)).whisker_width(0.0).fill(green).stroke(Stroke::new(2.0, green)),
        BoxElem::new(2.4, BoxSpread::new(2.1, 2.3, 2.3, 2.6, 2.7)).whisker_width(0.0).fill(green).stroke(Stroke::new(2.0, green)),
        BoxElem::new(2.7, BoxSpread::new(1.9, 2.1, 2.1, 2.7, 3.5)).whisker_width(0.0).fill(red).stroke(Stroke::new(2.0, red)),
        BoxElem::new(3.0, BoxSpread::new(2.0, 2.1, 2.1, 2.9, 3.3)).whisker_width(0.0).fill(green).stroke(Stroke::new(2.0, green)),
        BoxElem::new(3.3, BoxSpread::new(2.3, 2.9, 2.9, 3.7, 4.1)).whisker_width(0.0).fill(green).stroke(Stroke::new(2.0, green)),
        BoxElem::new(3.6, BoxSpread::new(3.1, 3.4, 3.4, 4.0, 4.2)).whisker_width(0.0).fill(red).stroke(Stroke::new(2.0, red)),
    ]);

    let plot = Plot::new("candlestick chart")
        .view_aspect(2.0);

    plot.show(ui, |plot_ui| {
            plot_ui.box_plot(data);
    });
}

impl eframe::App for App {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(ctx, |ui| {
            ui.label(format!("value = {}", self.value));
        });
        egui::Window::new("My Window").show(ctx, |ui| {
            candlestick_chart(ui);
        });
    }
}

fn main() {
    let native_options = eframe::NativeOptions::default();
    eframe::run_native(
        "candlestic chart",
        native_options,
        Box::new(|cc| Ok(Box::new(App::new(cc)))),
    );
}

Expected behavior

Screenshots

Image Image

Desktop (please complete the following information):

  • OS: windows 10

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the provided Rust example using BoxElem and BoxPlot on Windows 10, then inspect the BoxElem/BoxPlot rendering path for how bar corners and strokes are drawn. Compare the output with the screenshots; done means the candlestick bars render without extra pigment points at their corners.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.