Alien-libhisto

 view release on metacpan or  search on metacpan

bundled/tools/src/cmd_plot.c  view on Meta::CPAN

    fprintf(out, "         ");
    fprintf(out, "%-7.2f", ax.min);
    int mid_pad = (int)(nx * 2) - 14;
    if (mid_pad > 0) {
        for (int p = 0; p < mid_pad / 2; ++p) fputc(' ', out);
        fprintf(out, "%-7.2f", 0.5 * (ax.min + ax.max));
        for (int p = 0; p < (mid_pad - mid_pad / 2); ++p) fputc(' ', out);
    }
    fprintf(out, "%7.2f\n", ax.max);

    /* Color bar legend */
    if (use_color) {
        fprintf(out, "\n  Intensity: 0.00 ");
        for (int step = 0; step <= 20; ++step) {
            double frac = (double)step / 20.0;
            char bg[32];
            histo_palette_sample_ansi_bg(palette, frac, bg, sizeof(bg));
            fprintf(out, "%s \033[0m", bg);
        }
        fprintf(out, " %.2e [%s]\n\n", max_content, histo_palette_name(palette));
    } else {

bundled/tools/src/cmd_top.c  view on Meta::CPAN

} tui_modal_type_t;

typedef struct {
    tui_view_mode_t view_mode;
    tui_scale_mode_t scale_mode;
    tui_modal_type_t modal;
    histo_palette_t palette;
    bool show_kde;
    bool show_fit;
    bool show_errors;
    bool show_legend;  /* 2D: color range reference bar */
    bool show_y_axis;  /* 1D: count axis ruler tick line */
    bool monochrome;
    bool paused;
    bool cmd_active;
    bool log_z;  /* 2D: logarithmic intensity scaling */
    bool compact_header;
    bool auto_bins;
    int inspect_row;

    char cmd_buf[256];

bundled/tools/src/cmd_top.c  view on Meta::CPAN

    /* Y-axis label width: "  yval │ " = ~10 chars */
    int label_cols = 10;
    /* Available width for heatmap cells: 2 chars per X bin */
    int avail_cols = width - label_cols - 4;
    uint32_t x_step = 1;
    if ((int)(nx * 2) > avail_cols && avail_cols > 0) {
        x_step = (nx * 2 + (uint32_t)avail_cols - 1) / (uint32_t)avail_cols;
    }

    /* Y rows: map ny bins to max_rows, stepping if needed */
    /* Reserve 2 rows for X-axis line and labels, plus 1 if legend active */
    int leg_rows = st->show_legend ? 1 : 0;
    int heatmap_rows = max_rows - 2 - leg_rows;
    if (heatmap_rows < 1) heatmap_rows = 1;
    uint32_t y_step = (ny > (uint32_t)heatmap_rows) ? (ny + (uint32_t)heatmap_rows - 1) / (uint32_t)heatmap_rows : 1;

    int rows_drawn = 0;

    /* Render Y rows from top (ny-1) to bottom (0) */
    for (int iy = (int)ny - 1; iy >= 0 && rows_drawn < heatmap_rows; iy -= (int)y_step) {
        char row_buf[4096];
        double ymin_b, ymax_b, dummy;

bundled/tools/src/cmd_top.c  view on Meta::CPAN

        int max_st = bar_w - (int)strlen(max_str);
        if (max_st > (int)strlen(min_str)) {
            memcpy(l_bar + max_st, max_str, strlen(max_str));
        }
        snprintf(label_buf, sizeof(label_buf), "         %s", l_bar);
        tui_render_row(f, label_buf, width, true);
        rows_drawn++;
    }

    /* Optional Color Range Legend reference bar */
    if (st->show_legend && rows_drawn < max_rows) {
        char leg_buf[4096];
        if (st->monochrome) {
            snprintf(leg_buf, sizeof(leg_buf), "  Scale: [ .:-=+*#%%@ ] (0.00 -> %.2e) [%s]", max_content, st->log_z ? "LOG-Z" : "LIN");
        } else {
            int pos = snprintf(leg_buf, sizeof(leg_buf), "  Color Scale: 0.00 ");
            for (int step = 0; step <= 16 && pos + 32 < (int)sizeof(leg_buf); ++step) {
                double frac = (double)step / 16.0;
                char bg[32];
                histo_palette_sample_ansi_bg(st->palette, frac, bg, sizeof(bg));
                pos += snprintf(leg_buf + pos, sizeof(leg_buf) - pos, "%s \033[0m", bg);

bundled/tools/src/cmd_top.c  view on Meta::CPAN

                                    if (st.scale_mode == SCALE_LOG_X || st.scale_mode == SCALE_LOG_LOG) {
                                        tui_engine_rebuild_1d_log(&eng, 50, &st.frozen_snapshot);
                                    } else {
                                        tui_engine_rebuild_1d(&eng, 50, 0, 0, &st.frozen_snapshot);
                                    }
                                }
                            }
                            break;
                        case 'g':
                        case 'G':
                            st.show_legend = !st.show_legend;
                            break;
                        case 'y':
                        case 'Y':
                            st.show_y_axis = !st.show_y_axis;
                            break;
                        case 'k':
                            if (!eng.is_2d) st.show_kde = !st.show_kde;
                            break;
                        case 'f':
                            if (!eng.is_2d) st.show_fit = !st.show_fit;

bundled/tools/src/cmd_top.c  view on Meta::CPAN

            if (eng.is_2d) {
                if (snap_2d) {
                    histo2d_axis_t ax, ay;
                    histo2d_axis_x(snap_2d, &ax);
                    histo2d_axis_y(snap_2d, &ay);
                    snprintf(subhdr, sizeof(subhdr), "2D Heatmap │ X: %u bins [%.1f, %.1f] │ Y: %u bins [%.1f, %.1f] │ Pal: %s │ %s %s",
                             histo2d_nbins_x(snap_2d), ax.min, ax.max,
                             histo2d_nbins_y(snap_2d), ay.min, ay.max,
                             histo_palette_name(st.palette),
                             st.log_z ? "LOG-Z" : "LIN",
                             st.show_legend ? "│ Legend: ON" : "");
                } else {
                    snprintf(subhdr, sizeof(subhdr), "Initializing 2D...");
                }
            } else if (snap) {
                double r_min = 0, r_max = 0;
                histo_range(snap, &r_min, &r_max);
                uint32_t nb = histo_nbins(snap);
                const char *sc = (st.scale_mode == SCALE_LOG_Y) ? "LOG-Y" :
                                 (st.scale_mode == SCALE_LOG_X) ? "LOG-X" :
                                 (st.scale_mode == SCALE_LOG_LOG) ? "LOG-LOG" : "LIN";



( run in 0.677 second using v1.01-cache-2.11-cpan-364913b4093 )