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

random svg path preview #5459

Open
moolight-seashell opened this issue Jun 22, 2024 · 3 comments
Open

random svg path preview #5459

moolight-seashell opened this issue Jun 22, 2024 · 3 comments
Labels
needs info Further information from the reporter is requested

Comments

@moolight-seashell
Copy link

moolight-seashell commented Jun 22, 2024

hi,

i have this code :

export component Graph {
    in property <[{values: [float],background: color, name: string}]> graphes: 
        [{values: [0.5,0.75,0.25,0.1,0.4,0.5,0.9,0.25,0.1],background: #2bc2ae71, name: "temperature"}];

    for graphe in graphes.length : Rectangle {
        for value in graphes[graphe].values.length - 1:
        Path {
            width: parent.width;
            height: parent.height;
            fill: graphes[graphe].background;
            viewbox-width: parent.width/1px;
            viewbox-height: parent.height/1px;

            MoveTo {
                x : value * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                y : parent.viewbox-height;
            }
            LineTo{
                x : value * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                y : graphes[graphe].values[value] * parent.viewbox-height;
            }
            CubicTo{
                control-1-x : (value+0.5) * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                control-1-y : graphes[graphe].values[value] * parent.viewbox-height;
                control-2-x : (value+0.5) * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                control-2-y : graphes[graphe].values[value + 1] * parent.viewbox-height;
                x : (value+1) * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                y : graphes[graphe].values[value + 1] * parent.viewbox-height;
            }
            LineTo{
                x : (value+1) * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                y : parent.viewbox-height;
            }
            Close {
            }
        }

        for value in graphes[graphe].values.length - 1:
        Path {
            width: parent.width;
            height: parent.height;
            stroke: blue;
            stroke-width: 5px;
            viewbox-width: (parent.width - self.stroke-width)/1px;
            viewbox-height: (parent.height - self.stroke-width)/1px;

            
            MoveTo{
                x : value * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                y : graphes[graphe].values[value] * parent.viewbox-height;
            }
            CubicTo{
                control-1-x : (value+0.5) * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                control-1-y : graphes[graphe].values[value] * parent.viewbox-height;
                control-2-x : (value+0.5) * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                control-2-y : graphes[graphe].values[value + 1] * parent.viewbox-height;
                x : (value+1) * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                y : graphes[graphe].values[value + 1] * parent.viewbox-height;
            }
        }
    }

somtime i have a good preview like this :
Capture d’écran du 2024-06-22 17-46-35

but very often i have these preview :

Capture d’écran du 2024-06-22 17-46-54

@moolight-seashell
Copy link
Author

moolight-seashell commented Jun 22, 2024

and well it's quite annoying to not be able to chain if and for without using an object in between

the preview looks a little bit more stable with if in between like that :

export component Graph {
    in property <[{values: [float],underline_color: color, line_color : color, draw_line : bool , draw_underline: bool, name: string}]> graphes: 
        [{values: [0.5,0.75,0.25,0.1,0.4,0.5,0.9,0.25,0.1],underline_color: #2bc2ae71, line_color : #45968b, draw_line : true, draw_underline : false,name: "temperature"},
        {values: [0.7,0.2,0.8,0.4,0.5,0.4,0.8,0.7,0.2],underline_color: #30c22b70,line_color: #3c9139, draw_line : true, draw_underline : true, name: "huminidtée"}];

    for graphe in graphes.length : Rectangle {
        Text {
            horizontal-alignment: left;
            text: graphes[graphe].name;
            y : graphe*1px * 20;
            x : 10px;
            color: graphes[graphe].line_color;
            font-size: 15px;
            
        }

        if(graphes[graphe].draw_underline):  Rectangle {
            for value in graphes[graphe].values.length - 1:
            Path {
                width: parent.width;
                height: parent.height;
                fill: graphes[graphe].underline_color;
                viewbox-width: parent.width/1px;
                viewbox-height: parent.height/1px;

                MoveTo {
                    x : value * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                    y : parent.viewbox-height;
                }
                LineTo{
                    x : value * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                    y : graphes[graphe].values[value] * parent.viewbox-height;
                }
                CubicTo{
                    control-1-x : (value+0.5) * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                    control-1-y : graphes[graphe].values[value] * parent.viewbox-height;
                    control-2-x : (value+0.5) * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                    control-2-y : graphes[graphe].values[value + 1] * parent.viewbox-height;
                    x : (value+1) * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                    y : graphes[graphe].values[value + 1] * parent.viewbox-height;
                }
                LineTo{
                    x : (value+1) * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                    y : parent.viewbox-height;
                }
                Close {
                }
            }
        }

        if(graphes[graphe].draw_line): Rectangle {
            for value in graphes[graphe].values.length - 1:
            Path {
                width: parent.width;
                height: parent.height;
                stroke: graphes[graphe].line_color;
                stroke-width: 3px;
                viewbox-width: (parent.width - self.stroke-width)/1px;
                viewbox-height: (parent.height - self.stroke-width)/1px;
    
                
                MoveTo{
                    x : value * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                    y : graphes[graphe].values[value] * parent.viewbox-height;
                }
                CubicTo{
                    control-1-x : (value+0.5) * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                    control-1-y : graphes[graphe].values[value] * parent.viewbox-height;
                    control-2-x : (value+0.5) * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                    control-2-y : graphes[graphe].values[value + 1] * parent.viewbox-height;
                    x : (value+1) * (parent.viewbox-width / (graphes[graphe].values.length - 1));
                    y : graphes[graphe].values[value + 1] * parent.viewbox-height;
                }
            }
        }
    }

@tronical
Copy link
Member

I've tried to reproduce this, but I haven't had any luck yet. Is this on Linux with wayland by chance?

@ogoffart ogoffart added the needs info Further information from the reporter is requested label Jun 28, 2024
@moolight-seashell
Copy link
Author

i am on manjaro with xserver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs info Further information from the reporter is requested
Projects
None yet
Development

No branches or pull requests

3 participants