| 2844 | } |
| 2845 | |
| 2846 | IMPLOT_INLINE void RenderPieSlice(ImDrawList& draw_list, const ImPlotPoint& center, double radius, double a0, double a1, ImU32 col, ImPlotPieChartFlags flags, bool detached = false) { |
| 2847 | const float resolution = 50 / (2 * IM_PI); |
| 2848 | ImVec2 buffer[52]; |
| 2849 | |
| 2850 | int n = ImMax(3, (int)((a1 - a0) * resolution)); |
| 2851 | double da = (a1 - a0) / (n - 1); |
| 2852 | int i = 0; |
| 2853 | |
| 2854 | if (detached) { |
| 2855 | const double offset = 0.08; // Offset of the detached slice |
| 2856 | const double width_scale = 0.95; // Scale factor for the width of the detached slice |
| 2857 | |
| 2858 | double a_mid = (a0 + a1) / 2; |
| 2859 | double new_a0 = a_mid - (a1 - a0) * width_scale / 2; |
| 2860 | double new_a1 = a_mid + (a1 - a0) * width_scale / 2; |
| 2861 | double new_da = (new_a1 - new_a0) / (n - 1); |
| 2862 | |
| 2863 | ImPlotPoint offsetCenter(center.x + offset * cos(a_mid), center.y + offset * sin(a_mid)); |
| 2864 | |
| 2865 | // Start point (center of the offset) |
| 2866 | buffer[0] = PlotToPixels(offsetCenter, IMPLOT_AUTO, IMPLOT_AUTO); |
| 2867 | |
| 2868 | for (; i < n; ++i) { |
| 2869 | double a = new_a0 + i * new_da; |
| 2870 | buffer[i + 1] = PlotToPixels( |
| 2871 | offsetCenter.x + (radius + offset/2) * cos(a), |
| 2872 | offsetCenter.y + (radius + offset/2) * sin(a), |
| 2873 | IMPLOT_AUTO, IMPLOT_AUTO |
| 2874 | ); |
| 2875 | } |
| 2876 | |
| 2877 | } else { |
| 2878 | buffer[0] = PlotToPixels(center, IMPLOT_AUTO, IMPLOT_AUTO); |
| 2879 | for (; i < n; ++i) { |
| 2880 | double a = a0 + i * da; |
| 2881 | buffer[i + 1] = PlotToPixels( |
| 2882 | center.x + radius * cos(a), |
| 2883 | center.y + radius * sin(a), |
| 2884 | IMPLOT_AUTO, IMPLOT_AUTO); |
| 2885 | } |
| 2886 | } |
| 2887 | // Close the shape |
| 2888 | buffer[i + 1] = buffer[0]; |
| 2889 | |
| 2890 | // fill |
| 2891 | RenderPieSliceFill(draw_list, buffer, n + 2, col); |
| 2892 | |
| 2893 | // border (for AA) |
| 2894 | if (!ImHasFlag(flags, ImPlotPieChartFlags_NoSliceBorder)) |
| 2895 | RenderPieSliceLine(draw_list, buffer, n + 2, col); |
| 2896 | } |
| 2897 | |
| 2898 | template <typename T> |
| 2899 | double PieChartSum(IndexerIdx<T> indexer, bool ignore_hidden) { |
no test coverage detected