<commit_before>// -*- coding: utf-8; -*-
//
// $Id$
//
// Demonstrate most pllegend capability including unicode symbols.
//
// Copyright (C) 2010 <NAME>
//
// This file is part of PLplot.
//
// PLplot is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as published
// by the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// PLplot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with PLplot; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//

// This example designed just for devices (e.g., the cairo-related and
// qt-related devices) where the best choice of glyph is automatically
// selected by the related libraries (pango/cairo or Qt4) for each
// unicode character depending on what system fonts are installed.  Of
// course, you must have the appropriate TrueType fonts installed to
// have access to all the required glyphs.

#include "plcdemos.h"

static PLINT position_options[16] = {
    PL_POSITION_LEFT | PL_POSITION_TOP | PL_POSITION_OUTSIDE,
    PL_POSITION_TOP | PL_POSITION_OUTSIDE,
    PL_POSITION_RIGHT | PL_POSITION_TOP | PL_POSITION_OUTSIDE,
    PL_POSITION_RIGHT | PL_POSITION_OUTSIDE,
    PL_POSITION_RIGHT | PL_POSITION_BOTTOM | PL_POSITION_OUTSIDE,
    PL_POSITION_BOTTOM | PL_POSITION_OUTSIDE,
    PL_POSITION_LEFT | PL_POSITION_BOTTOM | PL_POSITION_OUTSIDE,
    PL_POSITION_LEFT | PL_POSITION_OUTSIDE,
    PL_POSITION_LEFT | PL_POSITION_TOP | PL_POSITION_INSIDE,
    PL_POSITION_TOP | PL_POSITION_INSIDE,
    PL_POSITION_RIGHT | PL_POSITION_TOP | PL_POSITION_INSIDE,
    PL_POSITION_RIGHT | PL_POSITION_INSIDE,
    PL_POSITION_RIGHT | PL_POSITION_BOTTOM | PL_POSITION_INSIDE,
    PL_POSITION_BOTTOM | PL_POSITION_INSIDE,
    PL_POSITION_LEFT | PL_POSITION_BOTTOM | PL_POSITION_INSIDE,
    PL_POSITION_LEFT | PL_POSITION_INSIDE
};

// Pick 5 arbitrary UTF-8 symbols useful for plotting points (✠✚✱✪✽✺✰✴✦).
static char *special_symbols[5] = {
    "✰",
    "✴",
    "✱",
    "✽",
    "✦"
};

// plcolorbar options

// Colorbar type options
#define COLORBAR_KINDS    4
static PLINT      colorbar_option_kinds[COLORBAR_KINDS] = {
    PL_COLORBAR_SHADE,
    PL_COLORBAR_SHADE | PL_COLORBAR_SHADE_LABEL,
    PL_COLORBAR_IMAGE,
    PL_COLORBAR_GRADIENT
};
static const char *colorbar_option_kind_labels[COLORBAR_KINDS] = {
    "Shade colorbars",
    "Shade colorbars with custom labels",
    "Image colorbars",
    "Gradient colorbars"
};

// Which side of the page are we positioned relative to?
#define COLORBAR_POSITIONS    4
static PLINT      colorbar_position_options[COLORBAR_POSITIONS] = {
    PL_POSITION_LEFT,
    PL_POSITION_RIGHT,
    PL_POSITION_TOP,
    PL_POSITION_BOTTOM
};
static const char *colorbar_position_option_labels[COLORBAR_POSITIONS] = {
    "Left",
    "Right",
    "Top",
    "Bottom"
};

// Colorbar label positioning options
#define COLORBAR_LABELS    4
static PLINT      colorbar_label_options[COLORBAR_LABELS] = {
    PL_COLORBAR_LABEL_LEFT,
    PL_COLORBAR_LABEL_RIGHT,
    PL_COLORBAR_LABEL_TOP,
    PL_COLORBAR_LABEL_BOTTOM
};
static const char *colorbar_label_option_labels[COLORBAR_LABELS] = {
    "Label left",
    "Label right",
    "Label top",
    "Label bottom"
};

// Colorbar cap options
#define COLORBAR_CAPS    4
static PLINT         colorbar_cap_options[COLORBAR_CAPS] = {
    PL_COLORBAR_CAP_NONE,
    PL_COLORBAR_CAP_LOW,
    PL_COLORBAR_CAP_HIGH,
    PL_COLORBAR_CAP_LOW | PL_COLORBAR_CAP_HIGH
};
static const char    *colorbar_cap_option_labels[COLORBAR_CAPS] = {
    "No caps",
    "Low cap",
    "High cap",
    "Low and high caps"
};

static int           colorbar = 0; // By default do not plot plcolorbar pages
                                   // for now while we are working out the API.
static PLOptionTable options[] = {
    {
        "colorbar",              // Turns on pages showing colorbars
        NULL,
        NULL,
        &colorbar,
        PL_OPT_BOOL,
        "-colorbar",
        "Plot the \"color bar\" pages."
    },
    {
        NULL,                   // option
        NULL,                   // handler
        NULL,                   // client data
        NULL,                   // address of variable to set
        0,                      // mode flag
        NULL,                   // short syntax
        NULL
    }                           // long syntax
};

const char           *notes[] = { "Make sure you get it right!", NULL };

void
plcolorbar_example_page( int kind_i, int label_i, int cap_i, PLINT cont_color, PLINT cont_width, PLINT n_values, PLFLT *values )
{
    // Parameters for the colorbars on this page
    PLINT      position_i, position, opt;
    PLFLT      x, y, x_length, y_length;
    PLFLT      ticks;
    PLINT      sub_ticks;
    PLFLT      low_cap_color, high_cap_color;
    PLINT      vertical, ifn;
    const char *axis_opts;
    char       label[200];
    char       title[200];
    PLFLT      colorbar_width, colorbar_height;

    ticks     = 0.0;
    sub_ticks = 0;

    low_cap_color  = 0.0;
    high_cap_color = 1.0;

    // Start a new page
    pladv( 0 );

    // Draw one colorbar relative to each side of the page
    for ( position_i = 0; position_i < COLORBAR_POSITIONS; position_i++ )
    {
        position = colorbar_position_options[position_i];
        opt      =
            colorbar_option_kinds[kind_i] |
            colorbar_label_options[label_i] |
            colorbar_cap_options[cap_i];

        vertical = position & PL_POSITION_LEFT || position & PL_POSITION_RIGHT;
        ifn      = position & PL_POSITION_LEFT || position & PL_POSITION_BOTTOM;

        // Set the offset position on the page
        if ( vertical )
        {
            x        = 0.0;
            y        = 0.0;
            x_length = 0.05;
            y_length = 0.5;
        }
        else
        {
            x        = 0.0;
            y        = 0.0;
            x_length = 0.5;
            y_length = 0.05;
        }

        // Set appropriate labelling options.
        if ( ifn )
        {
            if ( cont_color == 0 || cont_width == 0 )
            {
                axis_opts = "uwtvn";
            }
            else
            {
                axis_opts = "uwxvn";
            }
        }
        else
        {
            if ( cont_color == 0 || cont_width == 0 )
            {
                axis_opts = "uwtvm";
            }
            else
            {
                axis_opts = "uwxvm";
            }
        }

        sprintf( label, "%s, %s",
            colorbar_position_option_labels[position_i],
            colorbar_label_option_labels[label_i] );

        // Smaller text
        plschr( 0.0, 0.75 );
        // Small ticks on the vertical axis
        plsmaj( 0.0, 0.5 );
        plsmin( 0.0, 0.5 );

        plvpor( 0.1, 0.9, 0.1, 0.9 );
        plwind( 0.0, 1.0, 0.0, 1.0 );
        // Set interesting background colour.
        plscol0a( 15, 0, 0, 0, 0.20 );
        plcolorbar( &colorbar_width, &colorbar_height,
            opt|PL_COLORBAR_BOUNDING_BOX|PL_COLORBAR_BACKGROUND, position,
            x, y, x_length, y_length,
            15, 1, 1,
            low_cap_color, high_cap_color,
            cont_color, cont_width,
            ticks, sub_ticks,
            axis_opts, label,
            n_values, values );

        // Reset text and tick sizes
        plschr( 0.0, 1.0 );
        plsmaj( 0.0, 1.0 );
        plsmin( 0.0, 1.0 );
    }

    // Draw a page title
    sprintf( title, "%s - %s",
        colorbar_option_kind_labels[kind_i],
        colorbar_cap_option_labels[cap_i] );
    plvpor( 0.0, 1.0, 0.0, 1.0 );
    plwind( 0.0, 1.0, 0.0, 1.0 );
    plptex( 0.5, 0.5, 0.0, 0.0, 0.5, title );
}

void<commit_msg>Adjust positions of colorbars so that text doesn't get clipped.<commit_after>// -*- coding: utf-8; -*-
//
// $Id$
//
// Demonstrate most pllegend capability including unicode symbols.
//
// Copyright (C) 2010 <NAME>
//
// This file is part of PLplot.
//
// PLplot is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as published
// by the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// PLplot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with PLplot; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//

// This example designed just for devices (e.g., the cairo-related and
// qt-related devices) where the best choice of glyph is automatically
// selected by the related libraries (pango/cairo or Qt4) for each
// unicode character depending on what system fonts are installed.  Of
// course, you must have the appropriate TrueType fonts installed to
// have access to all the required glyphs.

#include "plcdemos.h"

static PLINT position_options[16] = {
    PL_POSITION_LEFT | PL_POSITION_TOP | PL_POSITION_OUTSIDE,
    PL_POSITION_TOP | PL_POSITION_OUTSIDE,
    PL_POSITION_RIGHT | PL_POSITION_TOP | PL_POSITION_OUTSIDE,
    PL_POSITION_RIGHT | PL_POSITION_OUTSIDE,
    PL_POSITION_RIGHT | PL_POSITION_BOTTOM | PL_POSITION_OUTSIDE,
    PL_POSITION_BOTTOM | PL_POSITION_OUTSIDE,
    PL_POSITION_LEFT | PL_POSITION_BOTTOM | PL_POSITION_OUTSIDE,
    PL_POSITION_LEFT | PL_POSITION_OUTSIDE,
    PL_POSITION_LEFT | PL_POSITION_TOP | PL_POSITION_INSIDE,
    PL_POSITION_TOP | PL_POSITION_INSIDE,
    PL_POSITION_RIGHT | PL_POSITION_TOP | PL_POSITION_INSIDE,
    PL_POSITION_RIGHT | PL_POSITION_INSIDE,
    PL_POSITION_RIGHT | PL_POSITION_BOTTOM | PL_POSITION_INSIDE,
    PL_POSITION_BOTTOM | PL_POSITION_INSIDE,
    PL_POSITION_LEFT | PL_POSITION_BOTTOM | PL_POSITION_INSIDE,
    PL_POSITION_LEFT | PL_POSITION_INSIDE
};

// Pick 5 arbitrary UTF-8 symbols useful for plotting points (✠✚✱✪✽✺✰✴✦).
static char *special_symbols[5] = {
    "✰",
    "✴",
    "✱",
    "✽",
    "✦"
};

// plcolorbar options

// Colorbar type options
#define COLORBAR_KINDS    4
static PLINT      colorbar_option_kinds[COLORBAR_KINDS] = {
    PL_COLORBAR_SHADE,
    PL_COLORBAR_SHADE | PL_COLORBAR_SHADE_LABEL,
    PL_COLORBAR_IMAGE,
    PL_COLORBAR_GRADIENT
};
static const char *colorbar_option_kind_labels[COLORBAR_KINDS] = {
    "Shade colorbars",
    "Shade colorbars with custom labels",
    "Image colorbars",
    "Gradient colorbars"
};

// Which side of the page are we positioned relative to?
#define COLORBAR_POSITIONS    4
static PLINT      colorbar_position_options[COLORBAR_POSITIONS] = {
    PL_POSITION_LEFT,
    PL_POSITION_RIGHT,
    PL_POSITION_TOP,
    PL_POSITION_BOTTOM
};
static const char *colorbar_position_option_labels[COLORBAR_POSITIONS] = {
    "Left",
    "Right",
    "Top",
    "Bottom"
};

// Colorbar label positioning options
#define COLORBAR_LABELS    4
static PLINT      colorbar_label_options[COLORBAR_LABELS] = {
    PL_COLORBAR_LABEL_LEFT,
    PL_COLORBAR_LABEL_RIGHT,
    PL_COLORBAR_LABEL_TOP,
    PL_COLORBAR_LABEL_BOTTOM
};
static const char *colorbar_label_option_labels[COLORBAR_LABELS] = {
    "Label left",
    "Label right",
    "Label top",
    "Label bottom"
};

// Colorbar cap options
#define COLORBAR_CAPS    4
static PLINT         colorbar_cap_options[COLORBAR_CAPS] = {
    PL_COLORBAR_CAP_NONE,
    PL_COLORBAR_CAP_LOW,
    PL_COLORBAR_CAP_HIGH,
    PL_COLORBAR_CAP_LOW | PL_COLORBAR_CAP_HIGH
};
static const char    *colorbar_cap_option_labels[COLORBAR_CAPS] = {
    "No caps",
    "Low cap",
    "High cap",
    "Low and high caps"
};

static int           colorbar = 0; // By default do not plot plcolorbar pages
                                   // for now while we are working out the API.
static PLOptionTable options[] = {
    {
        "colorbar",              // Turns on pages showing colorbars
        NULL,
        NULL,
        &colorbar,
        PL_OPT_BOOL,
        "-colorbar",
        "Plot the \"color bar\" pages."
    },
    {
        NULL,                   // option
        NULL,                   // handler
        NULL,                   // client data
        NULL,                   // address of variable to set
        0,                      // mode flag
        NULL,                   // short syntax
        NULL
    }                           // long syntax
};

const char           *notes[] = { "Make sure you get it right!", NULL };

void
plcolorbar_example_page( int kind_i, int label_i, int cap_i, PLINT cont_color, PLINT cont_width, PLINT n_values, PLFLT *values )
{
    // Parameters for the colorbars on this page
    PLINT      position_i, position, opt;
    PLFLT      x, y, x_length, y_length;
    PLFLT      ticks;
    PLINT      sub_ticks;
    PLFLT      low_cap_color, high_cap_color;
    PLINT      vertical, ifn;
    const char *axis_opts;
    char       label[200];
    char       title[200];
    PLFLT      colorbar_width, colorbar_height;

    ticks     = 0.0;
    sub_ticks = 0;

    low_cap_color  = 0.0;
    high_cap_color = 1.0;

    // Start a new page
    pladv( 0 );

    // Draw one colorbar relative to each side of the page
    for ( position_i = 0; position_i < COLORBAR_POSITIONS; position_i++ )
    {
        position = colorbar_position_options[position_i];
        opt      =
            colorbar_option_kinds[kind_i] |
            colorbar_label_options[label_i] |
            colorbar_cap_options[cap_i];

        vertical = position & PL_POSITION_LEFT || position & PL_POSITION_RIGHT;
        ifn      = position & PL_POSITION_LEFT || position & PL_POSITION_BOTTOM;

        // Set the offset position on the page
        if ( vertical )
        {
            x        = 0.0;
            y        = 0.0;
            x_length = 0.05;
            y_length = 0.5;
        }
        else
        {
            x        = 0.0;
            y        = 0.0;
            x_length = 0.5;
            y_length = 0.05;
        }

        // Set appropriate labelling options.
        if ( ifn )
        {
            if ( cont_color == 0 || cont_width == 0 )
            {
                axis_opts = "uwtvn";
            }
            else
            {
                axis_opts = "uwxvn";
            }
        }
        else
        {
            if ( cont_color == 0 || cont_width == 0 )
            {
                axis_opts = "uwtvm";
            }
            else
            {
                axis_opts = "uwxvm";
            }
        }

        sprintf( label, "%s, %s",
            colorbar_position_option_labels[position_i],
            colorbar_label_option_labels[label_i] );

        // Smaller text
        plschr( 0.0, 0.75 );
        // Small ticks on the vertical axis
        plsmaj( 0.0, 0.5 );
        plsmin( 0.0, 0.5 );

        plvpor( 0.15, 0.85, 0.15, 0.85 );
        plwind( 0.0, 1.0, 0.0, 1.0 );
        // Set interesting background colour.
        plscol0a( 15, 0, 0, 0, 0.20 );
        plcolorbar( &colorbar_width, &colorbar_height,
            opt|PL_COLORBAR_BOUNDING_BOX|PL_COLORBAR_BACKGROUND, position,
            x, y, x_length, y_length,
            15, 1, 1,
            low_cap_color, high_cap_color,
            cont_color, cont_width,
            ticks, sub_ticks,
            axis_opts, label,
            n_values, values );

        // Reset text and tick sizes
        plschr( 0.0, 1.0 );
        plsmaj( 0.0, 1.0 );
        plsmin( 0.0, 1.0 );
    }

    // Draw a page title
    sprintf( title, "%s - %s",
        colorbar_option_kind_labels[kind_i],
        colorbar_cap_option_labels[cap_i] );
    plvpor( 0.0, 1.0, 0.0, 1.0 );
    plwind( 0.0, 1.0, 0.0, 1.0 );
    plptex( 0.5, 0.5, 0.0, 0.0, 0.5, title );
}

void
{'fraction_non_alphanumeric': 0.09057301293900184, 'fraction_numerical': 0.018237831176833027, 'mean_word_length': 2.073470933535315, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6048739', 'n_tokens_mistral': 5618, 'n_tokens_neox': 5340, 'n_words': 1400}