giu icon indicating copy to clipboard operation
giu copied to clipboard

Question: how to add a text label on plot canvas

Open gucio321 opened this issue 3 years ago • 11 comments

Hi! I'd like to add a label on the plot canvas, is it possible?

gucio321 avatar Nov 20 '22 18:11 gucio321

ok, I'm looking on how does ImPlot do it for PieChart, here is the code

        for (int i = 0; i < count; ++i) {
            ImPlotItem* item = GetItem(label_ids[i]);
            double percent = normalize ? (double)values[i] / sum : (double)values[i];
            a1 = a0 + 2 * IM_PI * percent;
            if (item->Show) {
                sprintf(buffer, fmt, (double)values[i]);
                ImVec2 size = ImGui::CalcTextSize(buffer);
                double angle = a0 + (a1 - a0) * 0.5;
                ImVec2 pos = PlotToPixels(center.x + 0.5 * radius * cos(angle), center.y + 0.5 * radius * sin(an
                ImU32 col  = CalcTextColor(ImGui::ColorConvertU32ToFloat4(item->Color));
                DrawList.AddText(pos - size * 0.5f, col, buffer);
            }
            a0 = a1;
        }

so it just uses low-level ImGui's API to add this text

is DrawList.AddText the same as giu.Canvas().AddText(...)?

gucio321 avatar Nov 20 '22 18:11 gucio321

Yes, DrawList.AddText is the same as Canvas().AddText

AllenDang avatar Nov 21 '22 03:11 AllenDang

ok, I've opened a PR on imgui-go to export ImPlot:GetPlotDrawList()

Off-Topic btw, looking forward to see cimgui-go working, since work with imgui-go is becoming harder after seeing how cimgui-go is simple :smile:

let me know if I can help with implementing something on docking branch

gucio321 avatar Nov 21 '22 07:11 gucio321

@gucio321 Maybe migrate giu.Styler() stuff? There are lot's of migration is pending because the lack of time of mine...

AllenDang avatar Nov 21 '22 08:11 AllenDang

sure, I can try with it @AllenDang could I migrate CSS stuff as well? It is only related to StyleSetter IMO :smile:

gucio321 avatar Nov 21 '22 15:11 gucio321

@gucio321 Yes, go ahead.

AllenDang avatar Nov 22 '22 02:11 AllenDang

Ok so done

gucio321 avatar Nov 22 '22 06:11 gucio321

@AllenDang could you please merge imgui-go https://github.com/AllenDang/imgui-go/pull/15

gucio321 avatar Nov 23 '22 17:11 gucio321

meh, its really complex :smile:

@AllenDang could you help me :pray:

gucio321 avatar Nov 26 '22 13:11 gucio321

@gucio321 How can I help? What's the issue now?

AllenDang avatar Nov 28 '22 02:11 AllenDang

well, so first of all, plots in cimgui-go are broken (https://github.com/AllenDang/cimgui-go/issues/36) and imgui-go (in my opinion) lacks some methods...

However, I can be wrong, and just cannot find appropiate way to get position of last plot and add a label.

gucio321 avatar Nov 28 '22 08:11 gucio321

I don't need it anymore but it should be possible now, with cigui-go

gucio321 avatar Jul 10 '24 12:07 gucio321