slint icon indicating copy to clipboard operation
slint copied to clipboard

random svg path preview

Open moolight-seashell opened this issue 8 months ago • 2 comments

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 avatar Jun 22 '24 15:06 moolight-seashell