| 1 | # ABSTRACT: Plots from Perl data structures, drawn by matplotlib, gnuplot or ggplot2, with one interface for every plot type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 24 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 24 | ▶ | use feature 'say'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 24 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | package Matplotlib::Simple; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # The front end: plt and its wrappers take the caller's arguments, fold "p" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # and "df" into plots, and check every one of them, and then hand the figure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # to the engine that draws it -- Matplotlib::Simple::Matplotlib unless "engine" names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # another (%engine_module). Until 0.33 Matplotlib::Simple drew with matplotlib | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # alone, so the keywords are matplotlib's names throughout, and an engine that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # has no counterpart for one refuses it by name rather than leaving it out (check_engine). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 24 | require 5.010; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 24 | our $VERSION = 0.3345; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 24 | ▶ | use Scalar::Util 'looks_like_number'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 24 | ▶ | use List::Util qw(max sum min); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 24 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 24 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 24 | ▶ | use File::Temp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 24 | ▶ | use DDP { output => 'STDOUT', array_max => 10, show_memsize => 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 24 | ▶ | use Devel::Confess 'color'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 24 | ▶ | use FindBin qw($RealBin $RealScript); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 24 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 24 | ▶ | use Capture::Tiny 'capture'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 24 | our @EXPORT = qw(plt bar barh boxplot colored_table hexbin hist hist2d imshow pie plot scatter venn_proportional_area violinplot violin wide); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 24 | ▶ | use Encode (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 24 | our @EXPORT_OK = @EXPORT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 24 | our @ax_methods = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 'ArtistList', 'add_child_axes', 'add_collection', 'add_container', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 'add_image', 'add_line', 'add_patch', 'add_table', 'apply_aspect', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 'autoscale_view', 'axison', 'bxp', 'callbacks', 'can_pan', 'can_zoom', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 'child_axes', 'collections', 'containers', 'contains_point', 'dataLim', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 'drag_pan', 'end_pan', 'fmt_xdata', 'fmt_ydata', 'format_coord', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 'format_xdata', 'format_ydata','hexbin', 'hist', 'hist2d', 'hlines', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 'ignore_existing_data_limits', 'in_axes', 'indicate_inset', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 'indicate_inset_zoom', 'inset_axes', 'invert_xaxis', 'invert_yaxis', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 'label_outer', 'legend_', 'name', 'pcolorfast', 'redraw_in_frame', 'relim', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 'reset_position', 'scatter', 'secondary_xaxis', 'secondary_yaxis', 'set_adjustable', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 'set_anchor', 'set_aspect', 'set_autoscale_on', 'set_autoscalex_on', 'set_autoscaley_on', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 'set_axes_locator', 'set_axis_off', 'set_axis_on', 'set_axisbelow', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 'set_box_aspect', 'set_fc', 'set_forward_navigation_events', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 'set_frame_on', 'set_navigate', 'set_navigate_mode', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 'set_position', 'set_prop_cycle', 'set_rasterization_zorder', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 'set_subplotspec', 'set_title', 'set_xbound', 'set_xlabel', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 'set_xlim', # ax.set_xlim(left, right), or ax.set_xlim(right = 180) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 'set_xmargin', 'set_xscale', 'set_xticklabels', 'set_xticks', 'set_ybound', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 'set_ylabel', 'set_ylim', 'set_ymargin', 'set_yscale', 'set_yticklabels', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 'set_yticks', 'sharex', 'sharey', 'spines', 'start_pan', 'tables', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 'text', 'tick_params', 'ticklabel_format', 'titleOffsetTrans', 'transAxes', 'transData', 'transLimits', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 'transScale', 'update_datalim', 'use_sticky_edges', 'viewLim', 'vlines', 'violin', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 'xaxis', 'xaxis_date', 'xaxis_inverted', 'yaxis', 'yaxis_date', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 'yaxis_inverted' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 24 | our @fig_methods = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 'add_artist', 'add_axes', 'add_axobserver', 'add_callback', 'add_gridspec', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 'add_subfigure', 'add_subplot', 'align_labels', 'align_titles', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 'align_xlabels', 'align_ylabels', 'artists', 'autofmt_xdate', #'axes', # same as plt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 'bbox', 'bbox_inches', 'canvas', 'clear', 'clf', 'clipbox', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 'colorbar', # same name as in plt, have to use on case-by-case | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 'contains', 'convert_xunits', 'convert_yunits', 'delaxes', 'dpi', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 'dpi_scale_trans', 'draw', 'draw_artist', 'draw_without_rendering', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 'figbbox', 'figimage', # 'figure', 'findobj', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 'format_cursor_data', 'frameon', 'have_units', 'images', 'is_transform_set', # 'legend', legends', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 'lines', 'mouseover', 'number', 'patch', 'patches', 'pchanged', 'pick', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 'pickable', 'properties', 'remove', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 'remove_callback', #'savefig', keeping plt instead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 'sca', 'set', 'set_agg_filter', 'set_alpha', 'set_animated', 'set_canvas', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 'set_clip_box', 'set_clip_on', 'set_clip_path', 'set_constrained_layout', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 'set_constrained_layout_pads', 'set_dpi', 'set_edgecolor', 'set_facecolor', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 'set_figheight' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | , # default 4.8 # 'set_figure', # deprecated as of matplotlib 3.10.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 'set_figwidth', # default 6.4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 'set_frameon', 'set_gid', 'set_in_layout', 'set_label', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 'set_layout_engine', 'set_linewidth', 'set_mouseover', 'set_path_effects', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 'set_picker', 'set_rasterized', 'set_size_inches', 'set_sketch_params', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 'set_snap', 'set_tight_layout', 'set_transform', 'set_url', 'set_visible', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 'set_zorder', # 'show', # keeping plt instead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 'stale', 'stale_callback', 'sticky_edges', 'subfigs', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 'subfigures', # subplot_mosaic', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 'subplotpars', # subplots','subplots_adjust', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 'suppressComposite', # 'suptitle', # keeping plt instead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 'supxlabel', 'supylabel', #'text', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 'texts', #'tight_layout', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 'transFigure', 'transSubfigure', 'update', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 'update_from', #'waitforbuttonpress', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 'zorder' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 24 | our @plt_methods = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 'AbstractContextManager', 'Annotation', 'Arrow', 'Artist', 'AutoLocator', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 'AxLine', 'Axes', 'BackendFilter', 'Button', 'Circle', 'Colorizer', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 'ColorizingArtist', 'Colormap', 'Enum', 'ExitStack', 'Figure', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 'FigureBase', 'FigureCanvasBase', 'FigureManagerBase', 'FixedFormatter', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 'FixedLocator', 'FormatStrFormatter', 'Formatter', 'FuncFormatter', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 'GridSpec', 'IndexLocator', 'Line2D', 'LinearLocator', 'Locator', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 'LogFormatter', 'LogFormatterExponent', 'LogFormatterMathtext', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 'LogLocator', 'MaxNLocator', 'MouseButton', 'MultipleLocator', 'Normalize', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 'NullFormatter', 'NullLocator', 'PolarAxes', 'Polygon', 'Rectangle', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 'ScalarFormatter', 'Slider', 'Subplot', 'SubplotSpec', 'TYPE_CHECKING', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 'Text', 'TickHelper', 'Widget', 'acorr', 'angle_spectrum', 'annotate', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 'annotations', 'arrow', 'autoscale', 'autumn', 'axes', 'axhline', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 'axhspan', 'axis', 'axline', 'axvline', 'axvspan', 'backend_registry', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 'bar_label', 'barbs', 'bone', 'box', 'boxplot', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 'broken_barh', 'cast', 'cbook', 'cla', 'clabel' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | , #'clf', # I don't think you'd ever do that, also redundant with fig | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 'clim', 'close', 'cm', 'cohere', 'color_sequences', 'colorbar', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 'colormaps', 'connect', 'contour', 'contourf', 'cool', 'copper', 'csd', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 'cycler', 'delaxes', 'disconnect', 'draw', 'draw_all', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 'draw_if_interactive', 'ecdf', 'errorbar', 'eventplot', 'figaspect', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 'figimage', 'figlegend', 'fignum_exists', 'figtext', 'figure', 'fill', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 'fill_between', 'fill_betweenx', 'findobj', 'flag', 'functools', 'gca', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 'gcf', 'gci', 'get', 'get_backend', 'get_cmap', 'get_current_fig_manager', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 'get_figlabels', 'get_fignums', 'get_plot_commands', 'get_scale_names', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 'getp', 'ginput', 'gray', 'grid', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 'hot', 'hsv', 'importlib', 'imread', 'imsave', 'inferno', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 'inspect', 'install_repl_displayhook', 'interactive', 'ioff', 'ion', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 'isinteractive', 'jet', 'legend', 'locator_params', 'logging', 'loglog', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 'magma', 'magnitude_spectrum', 'margins', 'matplotlib', 'matshow', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 'minorticks_off', 'minorticks_on', 'mlab', 'new_figure_manager', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 'nipy_spectral', 'np', 'overload', 'pause', 'pcolor', 'pcolormesh', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 'phase_spectrum', 'pie', 'pink', 'plasma', 'plot', 'plot_date', 'polar', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 'prism', 'psd', 'quiver', 'quiverkey', 'rc', 'rcParams', 'rcParamsDefault', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 'rcParamsOrig', 'rc_context', 'rcdefaults', 'rcsetup', 'rgrids', 'savefig', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 'sca', #'scatter', # taken by "ax" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 'sci', 'semilogx', 'semilogy', 'set_cmap', 'set_loglevel', 'setp', 'show', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 'specgram', 'spring', 'spy', 'stackplot', 'stairs', 'stem', 'step', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 'streamplot', # 'style' is plt's own keyword since 0.33; as a pyplot method it wrote plt.style(...), and plt.style is a module, so it never ran | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 'subplot', # nrows, ncols : int, default: 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 'subplot2grid', 'subplot_mosaic', 'subplot_tool', 'subplots', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 'subplots_adjust', 'summer', 'suptitle', 'switch_backend', 'sys', 'table', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # 'text' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | , # text(x: 'float', y: 'float', s: 'str', fontdict: 'dict[str, Any] | None' = None, **kwargs) -> 'Text' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 'thetagrids', 'threading',# 'tick_params', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 'tight_layout', 'time', 'title', 'tricontour', 'tricontourf', 'tripcolor', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 'triplot', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | #'twinx', 'twiny', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 'uninstall_repl_displayhook', 'violinplot', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 'viridis', 'waitforbuttonpress', 'winter', 'xcorr', 'xkcd',# 'vlines' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 'xlabel','xscale','ylabel', 'ylim', 'yscale', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # 'xlim','xticks','yticks' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # The names in the three lists above that are not something to call. The lists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # were read off dir() of an Axes, a Figure and pyplot, which holds attributes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # modules and constants beside the methods, and every keyword in them is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # written into the script as a call: "dpi => 300" passed the keyword check and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # became fig.dpi(300), which python refused as "TypeError: 'float' object is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # not callable", and "rcParams => ..." as "'RcParams' object is not callable". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # Not one of them could ever have run, so each is now refused as any other | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # unknown keyword is, with the keywords it resembles. Checked against | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # matplotlib 3.11.2 with callable(getattr(obj, name)). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 24 | my %not_callable = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | ax => [ qw(axison callbacks child_axes collections containers dataLim | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | fmt_xdata fmt_ydata ignore_existing_data_limits legend_ name spines tables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | titleOffsetTrans transAxes transData transLimits transScale | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | use_sticky_edges viewLim xaxis yaxis) ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | fig => [ qw(artists bbox bbox_inches canvas clipbox dpi dpi_scale_trans | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | figbbox frameon images lines mouseover number patch patches stale | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | sticky_edges subfigs subplotpars suppressComposite texts transFigure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | transSubfigure zorder) ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | plt => [ qw(TYPE_CHECKING annotations backend_registry cbook cm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | color_sequences functools importlib inspect logging matplotlib mlab np | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | rcParams rcParamsDefault rcParamsOrig rcsetup sys threading time) ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 24 | foreach my $list ( [ ax => \@ax_methods ], [ fig => \@fig_methods ], [ plt => \@plt_methods ] ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 72 | my ( $object, $methods ) = @{$list}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 72 | my %drop = map { $_ => 1 } @{ $not_callable{$object} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 72 | @{$methods} = grep { not $drop{$_} } @{$methods}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 24 | our @arg = ('add', 'cmap', 'data', 'execute', 'fh', 'ncol', 'ncols', 'nrow', 'nrows', 'p', 'plot_type', 'plots', 'plot', 'output_file', 'scale', 'scalex', 'scaley', 'show', 'twinx'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # Options of plt itself, which no helper takes. "shared_colorbar" was in @arg, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # so every plot type accepted it inside a subplot and did nothing with it; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # plt hands it only to the subplot that draws the shared colorbar, whose type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # lists it among its own options. "engine" names what draws the whole figure, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # and "style" how it looks; both are refused in a subplot by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # refuse_subplot_choices. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # "dpi" is the resolution the figure is saved at, which the matplotlib engine | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # hands to savefig. Until 0.3343 it was among the Figure "methods", and wrote | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # fig.dpi(300), a TypeError; and "set_dpi", the method beside it, is no way to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # say it, since savefig takes the figure's resolution as it was when the figure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # was made (matplotlib 3.11.2), so fig.set_dpi(300) left the file as it was. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 24 | my @plt_arg = ( 'dpi', 'engine', 'shared_colorbar', 'style' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # Every keyword this module spelled with a dot up to 0.318, and what it is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # called now. The old spellings are refused, not accepted: see | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # refuse_dotted_keywords. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 24 | my %undotted_keyword = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 'col.labels' => 'col_labels', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 'colorbar.on' => 'colorbar_on', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 'key.order' => 'key_order', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 'output.file' => 'output_file', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 'plot.type' => 'plot_type', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 'row.labels' => 'row_labels', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 'set.options' => 'set_options', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 'shared.colorbar' => 'shared_colorbar', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 'show.colorbar' => 'show_colorbar', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 'show.legend' => 'show_legend', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 'show.numbers' => 'show_numbers', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 'twinx.args' => 'twinx_args', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 'undef.color' => 'undef_color', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 'xscale.hexbin' => 'xscale_hexbin', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 'yscale.hexbin' => 'yscale_hexbin', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 24 | our @cb_arg = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 'cbdrawedges', # for colarbar: Whether to draw lines at color boundaries | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 'cblabel', # The label on the colorbar's long axis | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 'cblocation', # of the colorbar None or {'left', 'right', 'top', 'bottom'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 'cb_min', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 'cb_max', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 'cborientation', # None or {'vertical', 'horizontal'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 'cbpad', # pad : float, default: 0.05 if vertical, 0.15 if horizontal; Fraction of original Axes between colorbar and new image Axes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 'cb_logscale'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 24 | our %opt = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | barplot_helper => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 'color' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | , # :mpltype:`color` or list of :mpltype:`color`, optional; The colors of the bar faces. This is an alias for *facecolor*. If both are given, *facecolor* takes precedence # if entering multiple colors, quoting isn't needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 'edgecolor' , # optional; The colors of the bar edges. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 'key_order', # define the keys in an order (an array reference) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 'label', # an array of labels for grouped bar plots | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 'linewidth', # float or array, optional; Width of the bar edge(s). If 0, don't draw edges | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 'log' , # bool, default: False; If *True*, set the y-axis to be log scale. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 'logscale', # equivalent to "log" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 'stacked', # stack the groups on top of one another; default 0 = off | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 'width', # float or array, default: 0.8; The width(s) of the bars. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 'xerr', # float or array-like of shape(N,) or shape(2, N), optional. If not *None*, add horizontal / vertical errorbars to the bar tips. The values are +/- sizes relative to the data: - scalar: symmetric +/- values for all bars # - shape(N,): symmetric +/- values for each bar # - shape(2, N): Separate - and + values for each bar. First row # contains the lower errors, the second row contains the upper # errors. # - *None*: No errorbar. (Default) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 'yerr', # same as xerr, but better with bar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | boxplot_helper => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 'color', # one color for every box; "colors" is the hash of one per key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 'colors', 'key_order', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 'logscale', # array of "x" and/or "y" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 'notch', # Whether to draw a notched boxplot (`True`), or a rectangular boxplot (`False`) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 'orientation',# {'vertical', 'horizontal'}, default: 'vertical' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 'showcaps', # bool: Show the caps on the ends of whiskers; default "True" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 'showfliers', #bool, default: :rc:`boxplot.showfliers`; Show the outliers beyond the caps. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 'showmeans' #bool, default: :rc:`boxplot.showmeans` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | colored_table_helper => [@cb_arg, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 'col_labels', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 'cmap', # the cmap used for coloring | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 'colorbar_on', # only draw if colorbar is on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 'default_undefined', # what value should undefined values be assigned to? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 'mirror', # $data{A}{B} = $data{B}{A} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 'row_labels', # row labels | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 'shared_colorbar', # array of 0-based indices for sharing a colorbar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 'show_numbers',# show the numbers or not, by default off. 0 = "off"; "show_numbers" > 0 => "on" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 'undef_color', # what color will undefined points be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | hexbin_helper => [ @cb_arg, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 'cb_logscale', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 'cmap', # "gist_rainbow" by default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 'colorbar_on', # only draw colorbar if colorbar is on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 'key_order', # define the keys in an order (an array reference) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 'marginals', # If marginals is *True*, plot the marginal density as colormapped rectangles along the bottom of the x-axis and left of the y-axis. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 'mincnt' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | , # int >= 0, default: 0 If > 0, only display cells with at least *mincnt* number of points in the cell. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 'shared_colorbar', # array of 0-based indices for sharing a colorbar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 'vmax' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | , # When using scalar data and no explicit *norm*, *vmin* and *vmax* define the data range that the colormap cover | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 'vmin' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | , # When using scalar data and no explicit *norm*, *vmin* and *vmax* define the data range that the colormap cover | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 'xbins', # default 15 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 'xscale_hexbin', # 'linear', 'log'}, default: 'linear': Use a linear or log10 scale on the horizontal axis. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 'ybins', # default 15 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 'yscale_hexbin', # 'linear', 'log'}, default: 'linear': Use a linear or log10 scale on the vertical axis. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | hist_helper => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 'alpha', # default 0.5; same for all sets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 'key_order', # the order the sets are drawn in, and so of the legend; default sorted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 'bins' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | , # int or sequence or str, default: :rc:`hist.bins`If *bins* is an integer, it defines the number of equal-width bins in the range. If *bins* is a sequence, it defines the bin edges, including the left edge of the first bin and the right edge of the last bin; in this case, bins may be unequally spaced. All but the last (righthand-most) bin is half-open | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 'color', # a hash, where keys are the keys in data, and values are colors, e.g. X => 'blue' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 'logscale', # array of "x" and/or "y"; a scalar is refused | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 'orientation', # {'vertical', 'horizontal'}, default: 'vertical' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 'show_legend' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | hist2d_helper => [@cb_arg, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 'cb_logscale', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 'cmap', # "gist_rainbow" by default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 'cmax', # All bins that has count < *cmin* or > *cmax* will not be displayed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 'cmin', # color min | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 'colorbar_on', # only draw colorbar if colorbar is on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 'density', # density : bool, default: False | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 'key_order', # define the keys in an order (an array reference) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 'logscale', # logscale, an array of axes that will get log scale | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 'shared_colorbar', # array of 0-based indices for sharing a colorbar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 'show_colorbar', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 'vmax' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | , # When using scalar data and no explicit *norm*, *vmin* and *vmax* define the data range that the colormap cover | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 'vmin' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | , # When using scalar data and no explicit *norm*, *vmin* and *vmax* define the data range that the colormap cover | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 'xbins', # default 15 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 'xmin', 'xmax', 'ymin', 'ymax', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 'ybins', # default 15 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | imshow_helper => [@cb_arg, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 'cblabel', # colorbar label | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 'cbdrawedges', # for colorbar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 'cblocation', # of the colorbar None or {'left', 'right', 'top', 'bottom'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 'cborientation', # None or {'vertical', 'horizontal'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 'cmap', # The Colormap instance or registered colormap name used to map scalar data to colors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 'colorbar_on', # only draw if colorbar is on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 'shared_colorbar', # array of 0-based indices for sharing a colorbar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 'stringmap', # 'H' => 'Alpha helix' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 'vmax', # float | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 'vmin', # flat | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | pie_helper => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 'autopct', # percent wise | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 'key_order', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | #labeldistance and pctdistance are ratios of the radius; therefore they vary between 0 for the center of the pie and 1 for the edge of the pie, and can be set to greater than 1 to place text outside the pie https://matplotlib.org/stable/gallery/pie_and_polar_charts/pie_features.html | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 'labeldistance', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 'pctdistance', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | plot_helper => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 'key_order', # an array of key strings (which are defined in data) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 'logscale', # an array of "x" and/or "y" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 'show_legend', # be default on; should be 0 if off | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 'set_options', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 'twinx_args' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | venn_proportional_area_helper => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 'alpha', # float, opacity of the set circles (matplotlib_venn default 0.4) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 'key_order', # array ref: the order (and hence the set labels) of the sets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 'set_colors', # array ref of colors, one per set, e.g. ['red','green'] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | scatter_helper => [@cb_arg, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 'color_key', # which of data keys is the color key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 'cmap', # for 3-set scatterplots; default "gist_rainbow" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 'colorbar_on', # only draw colorbar if colorbar is on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 'keys', # specify the order, otherwise alphabetical #'log', # if set to > 1, the y-axis will be logarithmic # 's', # float or array-like, shape (n, ), optional. The marker size in points**2 (typographic points are 1/72 in.). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 'logscale', # "x" and/or "y" as an aray | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 'key_order', # the order of the sets of a hash of sets; default sorted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 'shared_colorbar', # array of 0-based indices for sharing a colorbar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 'show_legend', # label each of several sets for the legend; default on, 0 or 'False' for off | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 'set_options', # color = 'red', marker = 'v', etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 'tooltips', # text shown on hovering over each point, in an SVG only: an array for one set, a hash of arrays for several | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | violin_helper => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 'color', # one color for every violin; "colors" is the hash of one per key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 'colors', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 'edgecolor', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 'key_order', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 'medians', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 'logscale', # array: "x" and/or "y" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 'orientation',# {'vertical', 'horizontal'}, default: 'vertical' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 'whiskers' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | wide_helper => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 'color', # a hash, with each key assigned to a color "blue" or something | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 'show_legend', # be default on; should be 0 if off | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | # plot_type => the %opt key holding that type's own keywords. "plt" dispatches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | # on the same pairing (%dispatch, inside plt), but the option lists are needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | # out here too, so that a keyword rejected before dispatch can still be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | # reported against the list for the type the caller actually asked for. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 24 | our %opt_key_of_type = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | bar => 'barplot_helper', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | barh => 'barplot_helper', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | boxplot => 'boxplot_helper', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | colored_table => 'colored_table_helper', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | hexbin => 'hexbin_helper', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | hist => 'hist_helper', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | hist2d => 'hist2d_helper', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | imshow => 'imshow_helper', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | pie => 'pie_helper', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | plot => 'plot_helper', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | scatter => 'scatter_helper', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | venn_proportional_area => 'venn_proportional_area_helper', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | violin => 'violin_helper', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | violinplot => 'violin_helper', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | wide => 'wide_helper', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 24 | my @all_opt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | my %types_of_opt; # keyword => array of the plot types whose own list has it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 24 | foreach my $type ( sort keys %opt_key_of_type ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 360 | foreach my $keyword ( @{ $opt{ $opt_key_of_type{$type} } } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 4032 | push @all_opt, $keyword; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 4032 | ▶ | next if grep { $_ eq $type } @{ $types_of_opt{$keyword} // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$types_of_opt{$keyword} // []
MC/DC100%1/1
$types_of_opt{$keyword} // []
$types_of_opt{$keyword}
Truth table100%2/2
A
A= $types_of_opt{$keyword}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 3888 | push @{ $types_of_opt{$keyword} }, $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 27524 | ▶ | sub edit_distance { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
edit_distance: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | # Optimal string alignment distance between two strings. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # Levenshtein with one extra case: two adjacent characters swapped count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | # as one edit, not two, because "widht" for "width" and "hsit" for "hist" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | # are the commonest way to mistype a keyword and a plain Levenshtein | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # threshold tight enough to be useful misses them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | # Three rows of the matrix are kept, since the transposition case reaches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | # two rows back; that is the only difference from the usual two-row form. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 27524 | my ( $x, $y ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 27524 | my @prev2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 27524 | my @prev = ( 0 .. length $y ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 27524 | foreach my $i ( 1 .. length $x ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 207242 | my @cur = ($i); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 207242 | foreach my $j ( 1 .. length $y ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 1811152 | my $xc = substr( $x, $i - 1, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 1811152 | my $yc = substr( $y, $j - 1, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 1811152 | ▶ | my $cost = ( $xc eq $yc ) ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 1811152 | $cur[$j] = min( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | $cur[ $j - 1 ] + 1, # insertion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | $prev[$j] + 1, # deletion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | $prev[ $j - 1 ] + $cost # substitution, or a match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 1811152 | ▶ | if ( ( $i > 1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$i > 1 and $j > 1 and $xc eq substr($y, $j - 2, 1) and $yc eq substr($x, $i - 2, 1)
$i > 1 and $j > 1 and $xc eq substr($y, $j - 2, 1)
$i > 1 and $j > 1
MC/DC100%4/4
$i > 1 and $j > 1 and $xc eq substr($y, $j - 2, 1) and $yc eq substr($x, $i - 2, 1)
$i > 1
$j > 1
$xc eq substr($y, $j - 2, 1)
$yc eq substr($x, $i - 2, 1)
Truth table100%5/5
A and B and C and D
A= $i > 1B= $j > 1C= $xc eq substr($y, $j - 2, 1)D= $yc eq substr($x, $i - 2, 1)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | && ( $j > 1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | && ( $xc eq substr( $y, $j - 2, 1 ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | && ( $yc eq substr( $x, $i - 2, 1 ) ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 7433 | $cur[$j] = min( $cur[$j], $prev2[ $j - 2 ] + 1 ); # transposition | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 207242 | @prev2 = @prev; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 207242 | @prev = @cur; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 27524 | return $prev[ length $y ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 27492 | ▶ | sub resembles { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resembles: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # Whether $keyword is a plausible reading of the mistyped $bad. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | # $bad and $keyword arrive already normalised (case folded, "." and "_" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | # dropped) so that the separator slips this module invites -- "key.order" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # for "key_order", "show.legend" for "show_legend" -- cost nothing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | # Two ways in, for two kinds of mistake. Containment catches a keyword | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | # reached for by the wrong name: "xlim" for "set_xlim", "legend" for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | # "show_legend". It is capped at 6 characters of difference, because | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | # without a cap "log" pulls in "LogFormatterExponent" and every other | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | # method with "log" buried in it. Edit distance catches the typing slips, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # at one edit per three characters and never fewer than one: a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | # 4-character keyword such as "xlim" admits a single edit ("ylim"), and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | # only from 6 characters is a second allowed. A flat threshold of 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | # instead matches most of the 4-character method names against each other. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 27492 | my ( $bad, $keyword ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 27492 | my $difference = abs( length($keyword) - length($bad) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 27492 | ▶ | if ( $difference <= 6 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 22394 | ▶ | return 1 if index( $keyword, $bad ) >= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 22328 | ▶ | return 1 if index( $bad, $keyword ) >= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 27393 | ▶ | my $max_edits = int( length($bad) / 3 ) || 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
int length($bad) / 3 || 1
MC/DC100%1/1
int length($bad) / 3 || 1
int length($bad) / 3
Truth table100%2/2
A
A= int length($bad) / 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 27393 | return ( edit_distance( $bad, $keyword ) <= $max_edits ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 27766 | ▶ | sub normalise_keyword { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalise_keyword: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | # Case folded with "." and "_" dropped, so that keywords are compared on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | # their letters alone. This module spells the same idea both ways in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | # different places ("cb_min" beside "cblabel"), so a caller has no way to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | # be sure which separator a keyword uses. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 27766 | my ($keyword) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 27766 | $keyword = lc $keyword; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 27766 | $keyword =~ s/[._]//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 27766 | return $keyword; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 66 | ▶ | sub similar_keywords { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
similar_keywords: called CC=10 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | # The accepted keywords that a mistyped one plausibly meant, closest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | # first. $preferred, if given, is the plot type's own keyword list: those | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | # are ranked ahead of equally-close matplotlib method names, since a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | # caller writing "log" at a "hist" wants "logscale", not "loglog". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 66 | my ( $bad, $accepted, $preferred ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 66 | my $norm = normalise_keyword($bad); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 66 | ▶ | return () if $norm eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 66 | ▶ | my %is_preferred = map { $_ => 1 } @{ $preferred // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$preferred // []
MC/DC100%1/1
$preferred // []
$preferred
Truth table100%2/2
A
A= $preferred
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 66 | my ( %seen, @scored ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 66 | foreach my $keyword ( @{$accepted} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 24660 | ▶ | next if $seen{$keyword}++; # the accepted lists are concatenated, so they repeat | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 24020 | ▶ | next unless resembles( $norm, normalise_keyword($keyword) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 81 | ▶ | push @scored, [ $is_preferred{$keyword} ? 0 : 1, edit_distance( $norm, normalise_keyword($keyword) ), $keyword ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | @scored = sort { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 66 | ▶ | $a->[0] <=> $b->[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$Matplotlib::Simple::a->[0] <=> $Matplotlib::Simple::b->[0] || $Matplotlib::Simple::a->[1] <=> $Matplotlib::Simple::b->[1] || $Matplotlib::Simple::a->[2] cmp $Matplotlib::Simple::b->[2]
$Matplotlib::Simple::a->[0] <=> $Matplotlib::Simple::b->[0] or $Matplotlib::Simple::a->[1] <=> $Matplotlib::Simple::b->[1]
MC/DC0%0/3
$Matplotlib::Simple::a->[0] <=> $Matplotlib::Simple::b->[0] || $Matplotlib::Simple::a->[1] <=> $Matplotlib::Simple::b->[1] || $Matplotlib::Simple::a->[2] cmp $Matplotlib::Simple::b->[2]
$Matplotlib::Simple::a->[0] <=> $Matplotlib::Simple::b->[0]
$Matplotlib::Simple::a->[1] <=> $Matplotlib::Simple::b->[1]
$Matplotlib::Simple::a->[2] cmp $Matplotlib::Simple::b->[2]
Truth table75%3/4
A or B || C
A= $Matplotlib::Simple::a->[0] <=> $Matplotlib::Simple::b->[0]B= $Matplotlib::Simple::a->[1] <=> $Matplotlib::Simple::b->[1]C= $Matplotlib::Simple::a->[2] cmp $Matplotlib::Simple::b->[2]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | || $a->[1] <=> $b->[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | || $a->[2] cmp $b->[2] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | } @scored; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | # 5, measured: take every option of every plot type in turn and ask what | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | # the types that do not accept it would suggest for it (1688 cases). 82 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | # of them produce more than 5 suggestions -- up to 14 -- and in every one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | # of the 82, everything past the 5th is a matplotlib method name that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | # merely shares a stem ("pcolor", "Colormap", "tripcolor" for "color"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | # never an option of any plot type. Re-measure before raising this. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 66 | ▶ | splice @scored, 5 if scalar @scored > 5; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 66 | return map { $_->[2] } @scored; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 62 | ▶ | sub keywords_of_other_types { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keywords_of_other_types: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | # The keywords that resemble the mistyped one, are not accepted here, but | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | # are accepted by some other plot type. The caller looks each one up in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | # %types_of_opt to say which types those are. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | # This is the mistake the module's shape invites most. "stacked" is real, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | # and so are "notch" and "bins" -- just not for the plot type in hand -- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | # so a bare "isn't defined" reads like the module is wrong. Naming the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | # types that do take the keyword answers the question the caller is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | # actually asking. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 62 | my ( $bad, $accepted ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 62 | my $norm = normalise_keyword($bad); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 62 | ▶ | return () if $norm eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 62 | my %is_accepted = map { $_ => 1 } @{$accepted}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 62 | my @scored; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 62 | foreach my $keyword ( sort keys %types_of_opt ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 4030 | ▶ | next if $is_accepted{$keyword}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 3247 | ▶ | next unless resembles( $norm, normalise_keyword($keyword) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 35 | push @scored, [ edit_distance( $norm, normalise_keyword($keyword) ), $keyword ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 62 | ▶ | @scored = sort { $a->[0] <=> $b->[0] || $a->[1] cmp $b->[1] } @scored; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$Matplotlib::Simple::a->[0] <=> $Matplotlib::Simple::b->[0] || $Matplotlib::Simple::a->[1] cmp $Matplotlib::Simple::b->[1]
MC/DC0%0/2
$Matplotlib::Simple::a->[0] <=> $Matplotlib::Simple::b->[0] || $Matplotlib::Simple::a->[1] cmp $Matplotlib::Simple::b->[1]
$Matplotlib::Simple::a->[0] <=> $Matplotlib::Simple::b->[0]
$Matplotlib::Simple::a->[1] cmp $Matplotlib::Simple::b->[1]
Truth table66%2/3
A || B
A= $Matplotlib::Simple::a->[0] <=> $Matplotlib::Simple::b->[0]B= $Matplotlib::Simple::a->[1] cmp $Matplotlib::Simple::b->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | # Fewer than the cap above, because each of these costs a whole line of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | # the message, and they are drawn from the 85 keywords the plot types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | # define between them rather than the 450-odd names a plot also accepts, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | # so the ranking has much less to choose between. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 62 | ▶ | splice @scored, 4 if scalar @scored > 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 62 | return map { $_->[1] } @scored; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 62 | ▶ | sub bad_keyword_error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bad_keyword_error: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | # Die naming each unrecognised keyword, with the accepted keywords it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | # resembles. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | # The accepted set is not one list: "notch" is a boxplot keyword and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | # "stacked" a bar keyword, and each helper validates against its own. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | # caller passes the list it just checked against, so the suggestions are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | # the ones that would have worked where the caller was. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | # args: bad => array ref of the unrecognised keywords | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | # accepted => array ref of the keywords that would have been taken | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | # preferred => array ref, optional: the subset to rank first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | # type => the plot_type being drawn, when one is known | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | # sub => the subroutine doing the checking, named when the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | # type is not known (several subplots, no one type) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 62 | my ($args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | my $where = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | defined $args->{type} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 62 | ▶ | ? "for plot_type \"$args->{type}\"" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | : "in $args->{sub}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 62 | my ( @lines, $any_help ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 62 | foreach my $bad ( sort @{ $args->{bad} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 62 | my @similar = similar_keywords( $bad, $args->{accepted}, $args->{preferred} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 62 | ▶ | if ( scalar @similar > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 36 | $any_help = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 36 | push @lines, "\"$bad\" isn't defined $where, perhaps you meant one of these defined keywords: (" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | . join( ', ', @similar ) . ')'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 26 | push @lines, "\"$bad\" isn't defined $where"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 62 | foreach my $keyword ( keywords_of_other_types( $bad, $args->{accepted} ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 35 | $any_help = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | push @lines, "\t\"$keyword\" is a defined keyword, but for plot_type " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 35 | . join( ', ', @{ $types_of_opt{$keyword} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | # Nothing resembled anything, here or elsewhere, so the caller has been | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | # given no way forward: fall back to printing the whole accepted list, as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | # this module did before it could suggest anything. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 62 | ▶ | unless ($any_help) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 15 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 15 | my @sorted = sort grep { !$seen{$_}++ } @{ $args->{accepted} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 15 | p @sorted, array_max => scalar @sorted; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 15 | say STDERR "the keywords above are the ones defined $where."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 62 | die join( "\n", @lines ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 1327 | ▶ | sub check_plot_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_plot_type: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | # Die unless "plot_type" names a type this module draws, saying which of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | # the types it resembles was probably meant. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | # "plot_type" is the one argument to plt whose *value* is drawn from a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | # fixed list, so a typo in it deserves the same answer a typo in a keyword | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | # gets: the suggestions come from the matcher above, run over the type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | # names instead of over a type's options. Before this, a mistyped type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | # printed the whole args hash and died "barr isn't defined" at a single | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | # plot, and reached %dispatch as an undef code ref -- "Can't use an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | # undefined value as a subroutine reference" -- at a subplot. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | # It is also checked before the keywords are, because an unrecognised type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | # leaves plt with no type-specific option list to check them against: the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | # check falls back to the union of every type's options, and the caller is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | # told which of their options do not exist rather than that their type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | # does not. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | # args: type => the plot_type given, which must be defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | # where => optional phrase saying which plot it was given for, e.g. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | # 'at subplot 2'; omitted for a single plot, which has only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | # the one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 1327 | my ($args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 1327 | my $type = $args->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 1327 | ▶ | return if defined $opt_key_of_type{$type}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 15 | ▶ | my $where = defined $args->{where} ? " $args->{where}" : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 15 | my $norm = normalise_keyword($type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 15 | my @scored; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 15 | foreach my $known ( sort keys %opt_key_of_type ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 225 | ▶ | next unless resembles( $norm, normalise_keyword($known) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 15 | push @scored, [ edit_distance( $norm, normalise_keyword($known) ), $known ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 15 | ▶ | @scored = sort { $a->[0] <=> $b->[0] || $a->[1] cmp $b->[1] } @scored; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$Matplotlib::Simple::a->[0] <=> $Matplotlib::Simple::b->[0] || $Matplotlib::Simple::a->[1] cmp $Matplotlib::Simple::b->[1]
MC/DC0%0/2
$Matplotlib::Simple::a->[0] <=> $Matplotlib::Simple::b->[0] || $Matplotlib::Simple::a->[1] cmp $Matplotlib::Simple::b->[1]
$Matplotlib::Simple::a->[0] <=> $Matplotlib::Simple::b->[0]
$Matplotlib::Simple::a->[1] cmp $Matplotlib::Simple::b->[1]
Truth table66%2/3
A || B
A= $Matplotlib::Simple::a->[0] <=> $Matplotlib::Simple::b->[0]B= $Matplotlib::Simple::a->[1] cmp $Matplotlib::Simple::b->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | # No cap, unlike the keyword suggestions: there are 15 plot types in all, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | # so the whole list is shorter than the 5 suggestions a keyword is allowed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | # and printing all of it costs the reader nothing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 15 | ▶ | if ( scalar @scored > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | die "\"$type\" isn't a defined plot_type$where, perhaps you meant one of these defined plot types: (" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 12 | . join( ', ', map { $_->[1] } @scored ) . ')'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 3 | die "\"$type\" isn't a defined plot_type$where; the defined plot types are: (" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | . join( ', ', sort keys %opt_key_of_type ) . ')'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 8476 | ▶ | sub decoded_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decoded_text: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | # A string as characters, for writing through the script's UTF-8 layer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | # Raw UTF-8 bytes -- a key read from a file with no decoding layer, or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | # written in a script without "use utf8" -- are decoded, or each byte of a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | # "\x{3c1}" would be written as a character of its own. A string that is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | # already characters is left alone, and so is one whose bytes are not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | # UTF-8: a native "\xb0C" is the two characters it says, and decoding it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | # regardless, as quote_text did, turned the degree sign into U+FFFD. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 8476 | my ($str) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 8476 | ▶ | return $str if ( not defined $str ) || Encode::is_utf8($str) || ( $str !~ m/[\x80-\xff]/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not defined $str or &Encode::is_utf8($str) or not $str =~ /[\x80-\xff]/
not defined $str or &Encode::is_utf8($str)
MC/DC66%2/3
not defined $str or &Encode::is_utf8($str) or not $str =~ /[\x80-\xff]/
not defined $str
&Encode::is_utf8($str)
not $str =~ /[\x80-\xff]/
Truth table75%3/4
not(A) or B or not(C)
A= not defined $strB= &Encode::is_utf8($str)C= not $str =~ /[\x80-\xff]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 13 | my $copy = $str; # decode() with FB_CROAK consumes its argument | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 13 | my $decoded = eval { Encode::decode( 'UTF-8', $copy, Encode::FB_CROAK ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 13 | ▶ | return defined $decoded ? $decoded : $str; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 751 | ▶ | sub decoded_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decoded_data: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | # decoded_text of every string in a structure bound for write_data. A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | # number is passed through untouched: a regex match would mark it as a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | # string, and the JSON encoder would then write it as one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | # The structure is copied only along the way to a string that decoding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | # changes, and returned as it is when there is none, which is nearly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | # always. A copy of the whole was made every time, and for a 1500 x 1500 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | # imshow it took 0.64 s of plt's 3.25 s and another copy of the image in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | # memory. Nothing that reads the result changes it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 751 | my ($data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 751 | my $decoded = redecoded($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 751 | ▶ | return defined $decoded ? $decoded : $data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 883 | ▶ | sub redecoded { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
redecoded: called CC=20 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | # decoded_data's walk: $data with every string decoded, or undef if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | # decoding changes nothing in it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 883 | my ($data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 883 | my $ref = ref $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 883 | ▶ | if ( $ref eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 371 | my $copy; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 371 | foreach my $i ( 0 .. $#{$data} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 1342 | my $item = $data->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | # Inline, to save a call per cell of an image: what is neither a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | # reference nor a string with a byte above 0x7f is left alone. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 1342 | ▶ | next if ( not ref $item ) && ( ( not defined $item ) || looks_like_number($item) || ( $item !~ m/[\x80-\xff]/ ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
not ref $item and !defined($item) || &looks_like_number($item) || !($item =~ /[\x80-\xff]/)
not defined $item or &looks_like_number($item) or not $item =~ /[\x80-\xff]/
not defined $item or &looks_like_number($item)
MC/DC100%4/4
not ref $item and !defined($item) || &looks_like_number($item) || !($item =~ /[\x80-\xff]/)
not ref $item
not defined $item
&looks_like_number($item)
not $item =~ /[\x80-\xff]/
Truth table100%5/5
not(A) and not(B) or C or not(D)
A= not ref $itemB= not defined $itemC= &looks_like_number($item)D= not $item =~ /[\x80-\xff]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 126 | my $decoded = redecoded($item); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 126 | ▶ | next unless defined $decoded; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 3 | ▶ | $copy //= [ @{$data} ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$copy //= [@{$data;}]
MC/DC100%1/1
$copy //= [@{$data;}]
$copy
Truth table100%2/2
A
A= $copy
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 3 | $copy->[$i] = $decoded; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 371 | return $copy; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 512 | ▶ | if ( $ref eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 3 | my $copy; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 3 | foreach my $key ( keys %{$data} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 6 | my $new_key = decoded_text($key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 6 | my $decoded = redecoded( $data->{$key} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 6 | ▶ | next if ( $new_key eq $key ) && ( not defined $decoded ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$new_key eq $key and not defined $decoded
MC/DC100%2/2
$new_key eq $key and not defined $decoded
$new_key eq $key
not defined $decoded
Truth table100%3/3
A and not(B)
A= $new_key eq $keyB= not defined $decoded
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 2 | ▶ | $copy //= { %{$data} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$copy //= {%{$data;}}
MC/DC100%1/1
$copy //= {%{$data;}}
$copy
Truth table100%2/2
A
A= $copy
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 2 | ▶ | delete $copy->{$key} if $new_key ne $key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 2 | ▶ | $copy->{$new_key} = defined $decoded ? $decoded : $data->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 3 | return $copy; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 509 | ▶ | return undef if $ref || ( not defined $data ) || looks_like_number($data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$ref or not defined $data or &looks_like_number($data)
$ref or not defined $data
MC/DC33%1/3
$ref or not defined $data or &looks_like_number($data)
$ref
not defined $data
&looks_like_number($data)
Truth table50%2/4
A or not(B) or C
A= $refB= not defined $dataC= &looks_like_number($data)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 507 | my $text = decoded_text($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 507 | ▶ | return ( $text eq $data ) ? undef : $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 1638 | ▶ | sub py_str { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
py_str: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | # Render a Perl string as a Python single-quoted string literal. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | # Legend labels, colorbar labels and the like are user data (data keys, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | # group names), so a name such as "Farmer's" would otherwise close the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | # literal early and emit unparseable Python. Backslashes are doubled | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | # first, which also makes a mathtext label like '$\alpha$' survive as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | # written instead of being read as a Python escape. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 1638 | my ($str) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 1638 | ▶ | $str = decoded_text( $str // '' ); # data keys reach here as raw bytes as often as labels do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$str // ""
MC/DC0%0/1
$str // ""
$str
Truth table50%1/2
A
A= $str
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 1638 | $str =~ s/\\/\\\\/g; # backslash first, or the escapes below get doubled | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 1638 | $str =~ s/'/\\'/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 1638 | $str =~ s/\n/\\n/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 1638 | $str =~ s/\r/\\r/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 1638 | $str =~ s/\t/\\t/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | # Every other control character as a hex escape. A NUL went through as it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | # stood, and Python refuses the whole script for it: "source code string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | # cannot contain null bytes". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 1638 | $str =~ s/([\x00-\x08\x0b\x0c\x0e-\x1f\x7f])/sprintf( '\\x%02x', ord $1 )/ge; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 1638 | return "'$str'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 72231 | ▶ | sub is_finite { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_finite: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | # Whether a value that passed looks_like_number is neither NaN nor infinite. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 72231 | my $v = 0 + $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 72231 | ▶ | return ( ( $v == $v ) && ( $v != 9**9**9 ) && ( $v != -9**9**9 ) ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$v == $v and $v != "Inf" and $v != "-Inf"
$v == $v and $v != "Inf"
MC/DC100%3/3
$v == $v and $v != "Inf" and $v != "-Inf"
$v == $v
$v != "Inf"
$v != "-Inf"
Truth table100%4/4
A and B and C
A= $v == $vB= $v != "Inf"C= $v != "-Inf"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 87066 | ▶ | sub as_double { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_double: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | # A number rounded to a C double, which numpy, R and gnuplot all compute in. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | # A perl whose NV is a long double or a __float128 (quadmath) computes more | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | # precisely, so a statistic worked out here as numpy works it out came out | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | # a digit or two away from numpy's on those perls, and in a different bin. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 87066 | return unpack 'd', pack 'd', $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 38886 | ▶ | sub double_literal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
double_literal: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | # A finite number as a literal that reads back as the same double: in 15 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | # significant digits, or 17 where 15 would not. Perl stringifies a computed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | # number to 15 digits on a double perl, so 1/3 lost its last two, and on a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | # quadmath perl to 36, which no double has. Whether 15 read back is asked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | # of C's strtod, which R and gnuplot read with: perl 5.10.1 read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | # "-6.06404429188014e-15" a double away from it, and so wrote 17 digits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | # where 15 were enough. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 38886 | my $v = as_double( $_[0] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 38886 | my $s = sprintf '%.15g', $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 38886 | ▶ | return ( as_double( scalar POSIX::strtod($s) ) == $v ) ? $s : sprintf '%.17g', $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 10194 | ▶ | sub is_nan { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_nan: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | # Whether a value is a number that is NaN: a missing value, for the helpers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | # that drop missing values rather than draw them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 10194 | ▶ | return 0 unless looks_like_number( $_[0] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 10193 | my $v = 0 + $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 10193 | ▶ | return ( $v != $v ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 32484 | ▶ | sub nonfinite_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nonfinite_name: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | # "nan", "inf" or "-inf" for a non-finite number, as numpy's float() reads | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | # them; undef for a finite one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 32484 | ▶ | return undef if is_finite( $_[0] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 12 | my $v = 0 + $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 12 | ▶ | return ( $v != $v ) ? 'nan' : ( $v > 0 ) ? 'inf' : '-inf'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 243 | ▶ | sub check_numbers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_numbers: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | # Die unless every value of an option is a defined number, naming the option. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 243 | my ( $values, $what, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 243 | ▶ | my @bad = grep { ( not defined ) || ( not looks_like_number($_) ) } @{$values}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $_ && &looks_like_number($_)
MC/DC50%1/2
defined $_ && &looks_like_number($_)
defined $_
&looks_like_number($_)
Truth table66%2/3
A && B
A= defined $_B= &looks_like_number($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 243 | ▶ | return if scalar @bad == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 11 | ▶ | die "$what must be numeric for $current_sub, but was given \"" . join( '", "', map { $_ // 'undef' } @bad ) . '"'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_ // "undef"
MC/DC0%0/1
$_ // "undef"
$_
Truth table50%1/2
A
A= $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 404 | ▶ | sub finite_values { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finite_values: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | # The values of a list that are numbers and finite, for a range computed in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | # Perl: min() and max() over a NaN answer by the order of the list, and an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | # infinite end leaves a range that nothing can be drawn in. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 404 | ▶ | return grep { ( defined ) && looks_like_number($_) && is_finite($_) } @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
defined $_ && &looks_like_number($_) && is_finite($_)
defined $_ and &looks_like_number($_)
MC/DC66%2/3
defined $_ && &looks_like_number($_) && is_finite($_)
defined $_
&looks_like_number($_)
is_finite($_)
Truth table75%3/4
A and B && C
A= defined $_B= &looks_like_number($_)C= is_finite($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 3106 | ▶ | sub bool_option { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bool_option: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | # A yes-or-no option as 1 or 0, read as Python reads a bool. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | # The documentation gives these options as Python bools -- "log => 'True'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | # -- and the code tested them for Perl truth, so "log => 'False'" turned | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | # the log scale on, the string being true in Perl. "True" and "False" in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | # any case, and any number, are taken; anything else is refused, naming the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | # option, since a word such as "yes" could mean either. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 3106 | my ( $value, $option, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 3106 | ▶ | return 0 unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 2147 | ▶ | if ( ref $value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 0 | die "\"$option\" is True or False (or 1 or 0) for $current_sub, not a " . ( ref $value ) . ' reference'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 2147 | ▶ | return 1 if $value =~ m/^\s*true\s*$/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 2052 | ▶ | return 0 if $value =~ m/^\s*(?:false|none)?\s*$/i; # "" and None are false in Python too | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 2008 | ▶ | return ( ( 0 + $value ) != 0 ) ? 1 : 0 if looks_like_number($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 7 | die "\"$option\" is True or False (or 1 or 0) for $current_sub, not \"$value\""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 315 | ▶ | sub cb_limits { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cb_limits: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | # "cb_min" and "cb_max" as the "vmin" and "vmax" a helper writes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | # colored_table takes the ends of its color scale as cb_min and cb_max, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | # and every other helper with a colorbar accepts them too, since they are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | # in @cb_arg -- but read vmin and vmax, where it read anything, and left | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | # cb_min and cb_max unread. Each is now the other's synonym. Giving both | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | # for the same end is refused, rather than one of them silently winning. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | # Each caller checks the result is a number, as it checked vmin and vmax. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 315 | my ( $plot, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 315 | foreach my $pair ( [ 'cb_min', 'vmin' ], [ 'cb_max', 'vmax' ] ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 629 | my ( $cb, $v ) = @{$pair}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 629 | ▶ | next unless defined $plot->{$cb}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 12 | ▶ | if ( defined $plot->{$v} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 1 | die "\"$cb\" and \"$v\" both set the same end of the color scale in $current_sub; give one of them"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 11 | $plot->{$v} = delete $plot->{$cb}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 62 | ▶ | sub check_key_order { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_key_order: called CC=9 SCAR=22.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | # The keys an ordering option names, as a list, dying unless it is an array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | # of distinct keys of "data". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | # Without this the missing key reaches the writer as an undef and dies as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | # "Use of uninitialized value in join or string", which names neither the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | # key that is missing nor the option that asked for it. A key named twice | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | # was drawn twice, and in a venn_proportional_area, whose sets are counted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | # from "data", it put one set in place of another: "key_order => ['A','A']" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | # drew A against itself and left B out. A string died as "Can't use string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | # as an ARRAY ref", and an empty array left nothing to draw. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | # args: keys => the option's value, which should be an array ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | # data => the data hash they must all be keys of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | # option => the option they came from, e.g. "key_order" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | # sub => the helper doing the checking | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 62 | my ($args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 62 | my $keys = $args->{keys}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 62 | ▶ | if ( ref $keys ne 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 1 | ▶ | my $got = ref $keys ? ( ref $keys ) . ' reference' : '"' . ( $keys // 'undef' ) . '"'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$keys // "undef"
MC/DC0%0/1
$keys // "undef"
$keys
Truth table50%1/2
A
A= $keys
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 1 | die "\"$args->{option}\" is an array of keys of \"data\" in $args->{sub}, not $got"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 61 | ▶ | if ( scalar @{$keys} == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 1 | die "\"$args->{option}\" is an empty array in $args->{sub}; give the keys of \"data\" in the order to draw them"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 60 | ▶ | if ( grep { ( not defined ) || ( ref ) } @{$keys} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
!defined($_) || ref $_
MC/DC0%0/2
!defined($_) || ref $_
!defined($_)
ref $_
Truth table33%1/3
not(A) || B
A= !defined($_)B= ref $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | die "\"$args->{option}\" holds something that is not a key of \"data\" in $args->{sub}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 60 | my %n_named; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 60 | my @twice = grep { $n_named{$_}++ == 1 } @{$keys}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 60 | ▶ | if ( scalar @twice > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 2 | die "\"$args->{option}\" names " . join( ', ', map { "\"$_\"" } @twice ) . " more than once in $args->{sub}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 58 | my @missing = grep { not exists $args->{data}{$_} } @{$keys}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 58 | ▶ | if ( scalar @missing > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 10 | p @missing; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 10 | die "the above keys are named in \"$args->{option}\" but are not keys of \"data\" in $args->{sub}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 48 | return @{$keys}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 55 | ▶ | sub bar_series { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bar_series: called CC=14 SCAR=26.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | # The series of a bar or barh whose "data" is a hash of hashes -- its inner | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | # keys -- in the order drawn: from the bottom of a stack up, left to right | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | # side by side, and down the legend. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | # "label" names them in that order, and must name each exactly once; with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | # no "label" they are sorted, ignoring case. Every engine sorted them and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | # then wrote over "label" with the sorted names, so a "label" given with a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | # hash of hashes was dropped without a word, and no option could put | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | # "staffed" under "authorized" in a stack. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | # args: plot => the plot, whose "data" is a hash of hashes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | # sub => the caller's name, for the messages | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 55 | my ($args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 55 | my ( $plot, $sub ) = @{$args}{ 'plot', 'sub' }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 55 | my %inner; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 55 | foreach my $k1 ( keys %{ $plot->{data} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 68 | $inner{$_}++ foreach keys %{ $plot->{data}{$k1} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | # "|| $a cmp $b": two inner keys differing only in case ("a", "A") tied, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | # and hash order then chose which series came first, from run to run. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 55 | ▶ | my @sorted = sort { lc $a cmp lc $b || $a cmp $b } keys %inner; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
lc $a cmp lc $b || $a cmp $b
MC/DC0%0/2
lc $a cmp lc $b || $a cmp $b
lc $a cmp lc $b
$a cmp $b
Truth table66%2/3
A || B
A= lc $a cmp lc $bB= $a cmp $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 55 | my $label = $plot->{label}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 55 | ▶ | return @sorted unless defined $label; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 30 | ▶ | if ( ( ref $label ne 'ARRAY' ) || ( grep { ( not defined ) || ( ref ) } @{$label} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
ref $label ne "ARRAY" or grep {not defined $_ or ref $_;} @{$label;}
!defined($_) || ref $_
MC/DC50%1/2
ref $label ne "ARRAY" or grep {not defined $_ or ref $_;} @{$label;}
ref $label ne "ARRAY"
grep {not defined $_ or ref $_;} @{$label;}
MC/DC0%0/2
!defined($_) || ref $_
!defined($_)
ref $_
Truth table66%2/3
A or B
A= ref $label ne "ARRAY"B= grep {not defined $_ or ref $_;} @{$label;}
Truth table33%1/3
not(A) || B
A= !defined($_)B= ref $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 3 | ▶ | my $got = ( ref $label ne 'ARRAY' ) ? ( ref $label ? ( ref $label ) . ' reference' : "\"$label\"" ) : 'an array holding something other than a name'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 3 | die "\"label\" of a hash of hashes in $sub is an array of the inner keys of \"data\", in the order to draw the series, not $got"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 27 | my %n_named; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 27 | my @twice = grep { $n_named{$_}++ == 1 } @{$label}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 27 | ▶ | die "\"label\" names " . join( ', ', map { "\"$_\"" } @twice ) . " more than once in $sub" if scalar @twice > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 24 | my @unknown = grep { not exists $inner{$_} } @{$label}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 24 | ▶ | if ( scalar @unknown > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 3 | ▶ | die "\"label\" names " . join( ', ', map { "\"$_\"" } @unknown ) . " in $sub, but no hash in \"data\" has " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | . ( scalar @unknown == 1 ? 'that key' : 'those keys' ) . '; with a hash of hashes, "label" gives the order of its inner keys: ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 3 | . join( ', ', map { "\"$_\"" } @sorted ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | # Left out of "label", a series would be left out of the figure. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 21 | my @unnamed = grep { not exists $n_named{$_} } @sorted; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 21 | ▶ | if ( scalar @unnamed > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 3 | die "\"label\" leaves out the series " . join( ', ', map { "\"$_\"" } @unnamed ) . " in $sub; with a hash of hashes it gives the order of every inner key of \"data\""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 18 | return @{$label}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 539 | ▶ | sub logscale_axes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logscale_axes: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | # The axes a "logscale" option asks for, refusing anything that is not an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | # axis name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | # The check this replaces was m/^([^xy])$/, which only ever saw one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | # character: "xy" and "" both passed it and emitted ax.set_xyscale("log") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | # and ax.set_scale("log"), neither of which matplotlib has. A scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | # "logscale => 'y'" died inside the dereference, as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | # "Can't use string ("y") as an ARRAY ref". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | # "bar"/"barh" are not callers: their "logscale" is the scalar synonym for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | # "log", documented as such. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 539 | my ( $logscale, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 539 | ▶ | return () unless defined $logscale; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 41 | ▶ | if ( ref $logscale ne 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 11 | ▶ | my $got = ref $logscale ? ( ref $logscale ) . ' reference' : "\"$logscale\""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 11 | die "\"logscale\" must be an array of axis names, e.g. [ 'y' ], but $current_sub was given $got"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | 30 | ▶ | my @bad = grep { ( not defined $_ ) || ( $_ !~ m/^[xy]$/ ) } @{$logscale}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $_ && $_ =~ /^[xy]$/
MC/DC50%1/2
defined $_ && $_ =~ /^[xy]$/
defined $_
$_ =~ /^[xy]$/
Truth table66%2/3
A && B
A= defined $_B= $_ =~ /^[xy]$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 30 | ▶ | if ( scalar @bad > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 6 | p $logscale; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | die 'only "x" and "y" are allowed in "logscale" for ' . $current_sub | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 6 | ▶ | . ', not "' . join( '", "', map { $_ // 'undef' } @bad ) . '"'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_ // "undef"
MC/DC0%0/1
$_ // "undef"
$_
Truth table50%1/2
A
A= $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 24 | return @{$logscale}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 61 | ▶ | sub table_cells { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table_cells: called CC=13 SCAR=25.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | # The keys of a colored_table's rows and columns, in the order drawn, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | # its cells, as ( \@row_keys, \@cols, \%data ). colored_table_helper draws | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | # these, and shared_table_range scales the colors of several tables by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | # them, so that a cell "col_labels" leaves out of a table is left out of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | # the scale it shares as well. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 61 | my ( $plot, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 61 | my $mirror = bool_option( $plot->{mirror}, 'mirror', $current_sub ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | # The rows and the columns. "data" is documented as outer key = row and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | # inner key = column, but both were taken from the outer keys, so a column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | # that was only ever an inner key was dropped: of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | # { H => { H => 432, Cl => 427 }, C => { H => 413, Cl => 339 } } the table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | # drew columns C and H, lost every Cl value and left the C column empty. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | # "col_labels" still selects the rows and the columns together, as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | # documented, and "mirror", which reflects the table, makes it square. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 61 | my %inner; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 61 | foreach my $k1 ( keys %{ $plot->{data} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 111 | my $ref = ref $plot->{data}{$k1}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 111 | ▶ | if ( $ref ne 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 1 | ▶ | die "$current_sub takes a hash of hashes, but row \"$k1\" of \"data\" is " . ( $ref ? "a $ref reference" : 'a scalar' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 110 | $inner{$_} = 1 foreach keys %{ $plot->{data}{$k1} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 60 | my %every_key = ( %inner, map { $_ => 1 } keys %{ $plot->{data} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 60 | my ( @row_keys, @cols, %data ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 60 | ▶ | if (defined $plot->{col_labels}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | @cols = check_key_order({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | keys => $plot->{col_labels}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 5 | data => \%every_key, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | option => 'col_labels', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | sub => $current_sub | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 4 | @row_keys = @cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | } elsif ( $mirror ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | 7 | @row_keys = sort keys %every_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 7 | @cols = @row_keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 48 | @row_keys = sort keys %{ $plot->{data} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 48 | @cols = sort keys %inner; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 59 | foreach my $k1 ( keys %{ $plot->{data} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 109 | foreach my $k2 ( keys %{ $plot->{data}{$k1} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | 189 | $data{$k1}{$k2} = $plot->{data}{$k1}{$k2}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | # A reflection fills only the cells the caller left empty. It used to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | # overwrite, so where both $data{A}{B} and $data{B}{A} were given, which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | # one the table showed depended on hash order. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | 59 | ▶ | if ( $mirror ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 8 | foreach my $k1 ( keys %{ $plot->{data} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 17 | foreach my $k2 ( keys %{ $plot->{data}{$k1} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 28 | ▶ | $data{$k2}{$k1} = $plot->{data}{$k1}{$k2} unless defined $data{$k2}{$k1}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 59 | return ( \@row_keys, \@cols, \%data ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 104 | ▶ | sub bin_counts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bin_counts: called CC=8 SCAR=21.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | # "xbins" and "ybins" for hexbin and hist2d, each a whole number of at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | # least 1, set to its default of 15 where not given. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | # Only 0 was refused. A negative count reached numpy, which refused it as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | # "'minlength' must not be negative", and a word died at int() as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | # 'Argument "ten" isn't numeric'. A fraction was cut to its whole part, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | # that "xbins => 1.5" drew one bin. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 104 | my ( $plot, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 104 | foreach my $bins ( 'xbins', 'ybins' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 203 | ▶ | $plot->{$bins} = $plot->{$bins} // 15; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$plot->{$bins} // 15
MC/DC100%1/1
$plot->{$bins} // 15
$plot->{$bins}
Truth table100%2/2
A
A= $plot->{$bins}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 203 | my $n = $plot->{$bins}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 203 | ▶ | if ( ( ref $n ) || ( not looks_like_number($n) ) || ( not is_finite($n) ) || ( $n != int $n ) || ( $n < 1 ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition58%7/12
ref $n or not &looks_like_number($n) or not is_finite($n) or $n != int $n or $n < 1
ref $n or not &looks_like_number($n) or not is_finite($n) or $n != int $n
ref $n or not &looks_like_number($n) or not is_finite($n)
ref $n or not &looks_like_number($n)
MC/DC40%2/5
ref $n or not &looks_like_number($n) or not is_finite($n) or $n != int $n or $n < 1
ref $n
not &looks_like_number($n)
not is_finite($n)
$n != int $n
$n < 1
Truth table50%3/6
A or not(B) or not(C) or D or E
A= ref $nB= not &looks_like_number($n)C= not is_finite($n)D= $n != int $nE= $n < 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 6 | die "\"$bins\" must be a whole number of at least 1 for $current_sub, not \"$n\""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 197 | $plot->{$bins} = int $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 81 | ▶ | sub linspace { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
linspace: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | # numpy.linspace(start, stop, num): num points from start to stop, each | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | # i * step + start and the last exactly stop, as numpy 2.5.2's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | # function_base.linspace makes them; for an engine to bin or sample | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | # where numpy does. Written as start + (stop - start) * i / n, the points | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | # rounded differently: a value on an edge fell into the next bin, and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | # last edge could come out below stop, so that the maximum was in no bin. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 81 | my ( $start, $stop, $num ) = map { as_double($_) } @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | 81 | ▶ | return ($start) if $num == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | # Each step is rounded to a double, as numpy's are; see as_double. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 81 | my $step = as_double( as_double( $stop - $start ) / ( $num - 1 ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 81 | return ( ( map { as_double( as_double( $_ * $step ) + $start ) } 0 .. $num - 2 ), $stop ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | 0 | ▶ | sub logspace { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logspace: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | # numpy.logspace(np.log10(lo), np.log10(hi), num), as the matplotlib engine | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | # writes a hist2d's edges on a log axis: 10 to the power of each point of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | # linspace, so that, unlike linspace, the last need not be exactly hi. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 0 | my ( $lo, $hi, $num ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 0 | return map { as_double( 10**$_ ) } linspace( POSIX::log10($lo), POSIX::log10($hi), $num ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 9 | ▶ | sub check_twinx_args { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_twinx_args: called CC=5 SCAR=16.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | # Die naming any keyword of a "twinx_args" hash that no axes, figure or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | # pyplot method answers to. plot_args checks its own arguments, not the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | # hash it is handed to write out, so a typo such as "ylable" was dropped | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | # without a word. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | 9 | my ( $twinx_args, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | 9 | my @accepted = ( @ax_methods, @fig_methods, @plt_methods ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 9 | my %accepted = map { $_ => 1 } @accepted; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 9 | foreach my $set ( sort keys %{$twinx_args} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | 9 | my $ref = ref $twinx_args->{$set}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | 9 | ▶ | if ( $ref ne 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 0 | ▶ | die "\"twinx_args\" for \"$set\" must be a hash of axes options, but " . ( $ref ? "a $ref reference" : 'a scalar' ) . ' was entered'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 9 | my @bad = grep { not $accepted{$_} } keys %{ $twinx_args->{$set} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 9 | ▶ | next if scalar @bad == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | 1 | bad_keyword_error({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | bad => \@bad, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | accepted => \@accepted, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | sub => "$current_sub \"twinx_args\" for \"$set\"" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | 411 | ▶ | sub check_scatter_values { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_scatter_values: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | # Die unless every value of one scatter axis is a defined number. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | # Only undefined values were refused before, and only for x and y: a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | # string in any axis, or anything at all in the color axis, was written | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | # into the script as it stands and died there as a python NameError. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 411 | my ( $values, $what, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | 411 | ▶ | if ( ref $values ne 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | 1 | ▶ | my $got = ref $values ? ( ref $values ) . ' reference' : 'a scalar'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 1 | die "$current_sub: $what must be an array of numbers, not $got"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 410 | my @bad = grep { not looks_like_number( $values->[$_] ) } 0 .. $#{$values}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 410 | ▶ | return if scalar @bad == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 3 | p @bad; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 3 | die "$what is undefined or not a number at the above indices in $current_sub"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 166 | ▶ | sub check_scatter_lengths { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_scatter_lengths: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | # Die unless the axes of one scatter set -- x, y and the color key, if any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | # -- hold the same number of values, as the documentation requires. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | # matplotlib refused a mismatch as "x and y must be the same size", which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | # named neither the keys nor the set. An axis that is not an array is left | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | # for check_scatter_values to refuse. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | 166 | my ( $set, $keys, $where, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | 166 | my @arrays = grep { ref $set->{$_} eq 'ARRAY' } @{$keys}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | 166 | my %lengths = map { scalar @{ $set->{$_} } => 1 } @arrays; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | 166 | ▶ | return if scalar keys %lengths <= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | die "$current_sub: the axes$where must all have the same number of values, but " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 2 | . join( ', ', map { "\"$_\" has " . scalar @{ $set->{$_} } } @arrays ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 31 | ▶ | sub check_wide_runs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_wide_runs: called CC=17 SCAR=28.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | # Validate one group's runs for "wide", naming the offending run. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | # A group is an ARRAY of [ \@x, \@y ] pairs. Getting that shape wrong -- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | # passing "plot"'s single [ \@x, \@y ] pair, say -- otherwise dies deep | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | # inside the writer with "Can't use string ("0") as an ARRAY ref", which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | # says nothing about which group was malformed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | 31 | my ( $runs, $where, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | 31 | ▶ | if ( ref $runs ne 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | 1 | ▶ | my $got = ref $runs ? ( ref $runs ) . ' reference' : 'a scalar'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | 1 | die "$current_sub: $where must be an ARRAY of [ \\\@x, \\\@y ] pairs, not $got"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | 30 | ▶ | if ( scalar @{$runs} == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 1 | die "$current_sub: $where holds no runs"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 29 | foreach my $i ( 0 .. $#{$runs} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 58 | my $run = $runs->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 58 | ▶ | unless (( ref $run eq 'ARRAY' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
ref $run eq "ARRAY" and scalar @{$run;} == 2 and ref $run->[0] eq "ARRAY" and ref $run->[1] eq "ARRAY"
ref $run eq "ARRAY" and scalar @{$run;} == 2 and ref $run->[0] eq "ARRAY"
ref $run eq "ARRAY" and scalar @{$run;} == 2
MC/DC25%1/4
ref $run eq "ARRAY" and scalar @{$run;} == 2 and ref $run->[0] eq "ARRAY" and ref $run->[1] eq "ARRAY"
ref $run eq "ARRAY"
scalar @{$run;} == 2
ref $run->[0] eq "ARRAY"
ref $run->[1] eq "ARRAY"
Truth table40%2/5
A and B and C and D
A= ref $run eq "ARRAY"B= scalar @{$run;} == 2C= ref $run->[0] eq "ARRAY"D= ref $run->[1] eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 58 | && ( scalar @{$run} == 2 ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | && ( ref $run->[0] eq 'ARRAY' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | && ( ref $run->[1] eq 'ARRAY' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 1 | die "$current_sub: run $i of $where must be [ \\\@x, \\\@y ]; a group is an ARRAY of such pairs, so a lone pair needs one more ARRAY around it"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 57 | my $n_x = scalar @{ $run->[0] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | 57 | my $n_y = scalar @{ $run->[1] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | 57 | ▶ | if ( $n_x != $n_y ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | 1 | die "$current_sub: run $i of $where has $n_x x values but $n_y y values"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 56 | ▶ | if ( $n_x == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | 0 | die "$current_sub: run $i of $where is empty"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | 56 | foreach my $axis ( 0, 1 ) { # 0 = x, 1 = y | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | 112 | my @bad = grep { !looks_like_number($_) } @{ $run->[$axis] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | 112 | ▶ | next if scalar @bad == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 1 | ▶ | my $name = $axis == 0 ? 'x' : 'y'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | # only the first few, so a wholly non-numeric run does not print itself | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 1 | my $shown = join '", "', @bad[ 0 .. min( $#bad, 4 ) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 1 | die "$current_sub: run $i of $where has non-numeric $name value(s): \"$shown\""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | # looks_like_number takes "inf" and "nan". An infinite x was written into | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | # np.linspace as a bare name, a NameError; a NaN x sorts last and is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | # interpolated across as though it were a point. An infinite y has no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | # mean. A NaN y is a gap, which the mean below already steps around. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 55 | my @nonfinite_x = grep { not is_finite($_) } @{ $run->[0] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 55 | ▶ | my @infinite_y = grep { ( not is_finite($_) ) && ( not is_nan($_) ) } @{ $run->[1] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
is_finite($_) || is_nan($_)
MC/DC50%1/2
is_finite($_) || is_nan($_)
is_finite($_)
is_nan($_)
Truth table66%2/3
A || B
A= is_finite($_)B= is_nan($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 55 | ▶ | if ( scalar @nonfinite_x > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 1 | die "$current_sub: run $i of $where has x value(s) that are not finite: \"" . join( '", "', @nonfinite_x[ 0 .. min( $#nonfinite_x, 4 ) ] ) . '"'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 54 | ▶ | if ( scalar @infinite_y > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | 1 | die "$current_sub: run $i of $where has infinite y value(s): \"" . join( '", "', @infinite_y[ 0 .. min( $#infinite_y, 4 ) ] ) . '"'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 32 | ▶ | sub normalise_p { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalise_p: called CC=22 SCAR=31.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | # "p" is a flat list of subplots: ONE array element == ONE subplot. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | # p => [ \%h, \%h, ... ] each hash is its own subplot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | # p => [ \%h, [ \%h, \%h ], \%h, ... ] an inner array of hashes is a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | # single subplot holding several | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | # plots on the same axes (the 1st | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | # hash is the base plot, the rest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | # are "add"itions/overlays) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | # The plain-hash and inner-array forms may be mixed freely in one "p". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | # Using "p" means top-level "plot_type"/"data" are not used. If no grid is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | # given, the subplots are laid out on an automatically-sized near-square | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | # grid; pass nrow(s)/ncol(s) to override. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | 32 | my ( $args, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | 32 | ▶ | $current_sub = $current_sub // 'plt'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$current_sub // "plt"
MC/DC0%0/1
$current_sub // "plt"
$current_sub
Truth table50%1/2
A
A= $current_sub
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | 32 | my $p = delete $args->{p}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | 32 | ▶ | if ( ref $p ne 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | 1 | die "$current_sub: \"p\" must be an ARRAY reference (one element per subplot)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 31 | ▶ | if ( scalar @{$p} == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | 1 | die "$current_sub: \"p\" is empty"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | # "p" supersedes the older interface; forbid mixing to avoid ambiguity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | 30 | foreach my $clash ( grep { defined $args->{$_} } ( 'plot_type', 'data', 'plots', 'add' ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | 4 | die "$current_sub: \"$clash\" cannot be combined with \"p\""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | 26 | my @plots; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | 26 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | 26 | foreach my $subplot ( @{$p} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | 45 | my $ref = ref $subplot; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | 45 | ▶ | if ( $ref eq 'HASH' ) { # one subplot, one plot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 32 | push @plots, { %{$subplot} }; # shallow copy; don't mutate caller | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | } elsif ( $ref eq 'ARRAY' ) { # one subplot, several overlaid plots | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | 12 | ▶ | if ( scalar @{$subplot} == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | 1 | die "$current_sub: subplot $i in \"p\" is an empty array"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 11 | my @g = @{$subplot}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | 11 | my $main = shift @g; # 1st hash is the base plot | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | 11 | foreach my $plot ( $main, @g ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | 22 | ▶ | if ( ref $plot ne 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | 1 | die "$current_sub: subplot $i in \"p\": every plot must be a HASH reference"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | 10 | my %plot = %{$main}; # shallow copy of the base plot | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | # the rest overlay on the same axes. A new array, not a push: the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | # copy above shares the base plot's own "add" array with the caller. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | 10 | ▶ | $plot{add} = [ @{ $plot{add} // [] }, @g ] if scalar @g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$plot{"add"} // []
MC/DC100%1/1
$plot{"add"} // []
$plot{"add"}
Truth table100%2/2
A
A= $plot{"add"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | 10 | push @plots, \%plot; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | 1 | die "$current_sub: subplot $i in \"p\" must be a HASH reference (one plot) or an ARRAY of HASH references (overlaid plots), not a \"$ref\" reference"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | 42 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | 23 | $args->{plots} = \@plots; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | # convenience: choose a subplot grid. With neither dimension given, use a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | # near-square grid; with exactly one given (and positive), derive the other | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | # so e.g. "ncols => 1" stacks the subplots in a single column. Empty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | # trailing cells are pruned later by the engine. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | 23 | my $n = scalar @plots; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | 23 | ▶ | my $ncols = $args->{ncols} // $args->{ncol}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args->{"ncols"} // $args->{"ncol"}
MC/DC50%1/2
$args->{"ncols"} // $args->{"ncol"}
$args->{"ncols"}
$args->{"ncol"}
Truth table66%2/3
A // B
A= $args->{"ncols"}B= $args->{"ncol"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | 23 | ▶ | my $nrows = $args->{nrows} // $args->{nrow}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$args->{"nrows"} // $args->{"nrow"}
MC/DC100%2/2
$args->{"nrows"} // $args->{"nrow"}
$args->{"nrows"}
$args->{"nrow"}
Truth table100%3/3
A // B
A= $args->{"nrows"}B= $args->{"nrow"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | 23 | ▶ | if ( ( not defined $ncols ) && ( not defined $nrows ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
defined $ncols || defined $nrows
MC/DC100%2/2
defined $ncols || defined $nrows
defined $ncols
defined $nrows
Truth table100%3/3
A || B
A= defined $ncolsB= defined $nrows
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | 16 | $ncols = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | 16 | ▶ | $ncols++ while ( $ncols * $ncols ) < $n; # ceil(sqrt $n), no floats | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | 16 | $args->{ncols} = $ncols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | 16 | $args->{nrows} = int( ( $n + $ncols - 1 ) / $ncols ); # ceil($n / $ncols) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | ▶ | } elsif ( ( not defined $ncols ) && ( $nrows > 0 ) ) { # only rows given | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not defined $ncols and $nrows > 0
MC/DC50%1/2
not defined $ncols and $nrows > 0
not defined $ncols
$nrows > 0
Truth table66%2/3
not(A) and B
A= not defined $ncolsB= $nrows > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | 3 | $args->{ncols} = int( ( $n + $nrows - 1 ) / $nrows ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | ▶ | } elsif ( ( not defined $nrows ) && ( $ncols > 0 ) ) { # only cols given | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not defined $nrows and $ncols > 0
MC/DC50%1/2
not defined $nrows and $ncols > 0
not defined $nrows
$ncols > 0
Truth table66%2/3
not(A) and B
A= not defined $nrowsB= $ncols > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | 3 | $args->{nrows} = int( ( $n + $ncols - 1 ) / $ncols ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | 23 | return $args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | 1219 | ▶ | sub copy_plot_hashes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
copy_plot_hashes: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | # A copy of plt's arguments, deep enough that nothing plt does is seen by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | # the caller. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | # plt and its helpers write into the hashes they are given: "add" is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | # deleted once drawn, "title" is renamed "set_title", a subplot is told | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | # whether to draw its colorbar, and array "data" is rewrapped as a hash. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | # Under plt({ ... }) those were the caller's own hashes, so the same hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | # drawn twice lost its overlays the second time. The hashes are copied, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | # at every level plt writes to -- the top, each subplot, each "add" graph -- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | # and the data inside them is not: it is only read, and can be large. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | # Anything of the wrong shape is passed through as it is, for the checks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | # in plt to refuse by name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | # "p" is copied too, subplot by subplot and overlay by overlay. It was not, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | # and normalise_p copies only the subplot hashes it builds, so an overlay | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | # drawn through "p" -- the 2nd hash of an inner array, or an "add" graph -- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | # was the caller's own: a hist overlay came back with its array "data" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | # rewrapped as { A => [...] } and a "plot_type" it had not been given. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | 1219 | my ($args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | 1441 | ▶ | my $copy_plot = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | 1441 | my ($plot) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | 1441 | ▶ | return $plot unless ref $plot eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | 1438 | $plot = { %{$plot} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | 1438 | ▶ | if ( ref $plot->{add} eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | 45 | ▶ | $plot->{add} = [ map { ref $_ eq 'HASH' ? { %{$_} } : $_ } @{ $plot->{add} } ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | 1438 | return $plot; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | 1219 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | 1219 | my $copy = $copy_plot->($args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | 1219 | ▶ | if ( ref $copy->{plots} eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | 85 | $copy->{plots} = [ map { $copy_plot->($_) } @{ $copy->{plots} } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | 1219 | ▶ | if ( ref $copy->{p} eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | $copy->{p} = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | 34 | ▶ | map { ref $_ eq 'ARRAY' ? [ map { $copy_plot->($_) } @{$_} ] : $copy_plot->($_) } @{ $copy->{p} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | 1219 | return $copy; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | 1219 | ▶ | sub refuse_dotted_keywords { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
refuse_dotted_keywords: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | # Die naming every keyword given in its pre-0.319 dotted spelling, where | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | # it was given, and what it is called now. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | # Most of them would be refused anyway, with the new name among the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | # suggestions, since similar_keywords ignores separators. "plot.type" and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | # "output.file" would not: plt looks for "plot_type" and "output_file" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | # before it checks any keyword, so a script written for 0.318 died with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | # "either "show" or "output_file" must be defined", which never mentions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | # the key the caller actually wrote. This runs first, so that every old | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | # script fails the same way. It visits the levels copy_plot_hashes copies. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | 1219 | my ( $args, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | 1219 | my @found; # "old" => "new" at <where>, one per dotted key | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | 1489 | ▶ | my $check_keys = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | 1489 | my ( $plot, $where ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | 1489 | ▶ | return unless ref $plot eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | 1484 | foreach my $key ( sort grep { exists $undotted_keyword{$_} } keys %{$plot} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | 8 | push @found, "\"$key\" is now \"$undotted_keyword{$key}\"$where"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | 1219 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | 1441 | ▶ | my $check = sub { # a plot and its "add" graphs, which do not nest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | 1441 | my ( $plot, $where ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | 1441 | $check_keys->( $plot, $where ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | 1441 | ▶ | return unless ( ref $plot eq 'HASH' ) && ( ref $plot->{add} eq 'ARRAY' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $plot eq "HASH" and ref $plot->{"add"} eq "ARRAY"
MC/DC100%2/2
ref $plot eq "HASH" and ref $plot->{"add"} eq "ARRAY"
ref $plot eq "HASH"
ref $plot->{"add"} eq "ARRAY"
Truth table100%3/3
A and B
A= ref $plot eq "HASH"B= ref $plot->{"add"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | 45 | foreach my $i ( 0 .. $#{ $plot->{add} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | 48 | $check_keys->( $plot->{add}[$i], " in \"add\" graph $i$where" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | 1219 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | 1219 | $check->( $args, '' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | 1219 | ▶ | if ( ref $args->{plots} eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | 85 | $check->( $args->{plots}[$_], " at subplot $_" ) foreach 0 .. $#{ $args->{plots} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | 1219 | ▶ | if ( ref $args->{p} eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | 34 | foreach my $i ( 0 .. $#{ $args->{p} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | 54 | my $entry = $args->{p}[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | 54 | ▶ | my @graphs = ref $entry eq 'ARRAY' ? @{$entry} : ($entry); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | 54 | $check->( $_, " at \"p\" entry $i" ) foreach @graphs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | 1219 | ▶ | return if scalar @found == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | 7 | die "$current_sub: keywords are spelled with \"_\", not \".\", since 0.319: " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | . join( '; ', @found ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | # "df": a data frame given whole, with the columns to plot named by role, in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | # place of "data" built by hand. The four shapes are those of Stats::LikeR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | # (lib/Stats/LikeR.pm, _df_shape, Stats::LikeR 0.3213): an array of hashes (one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | # hash per row), a hash of arrays (one array per column), a hash of hashes (row | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | # name => { column => value }) and an array of arrays (columns by 0-based | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | # position). They are recognised by their structure, so the frame can come from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | # anywhere; Stats::LikeR is not loaded. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | # frames_to_data rewrites every plot hash holding "df" into the "data" its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | # plot_type already takes, before anything else in plt looks at it, so no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | # helper knows that a frame was ever given. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | # plot_type => the roles it reads columns from: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | # take => the roles it accepts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | # need => the roles it cannot be drawn without | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | # many => the one role that may name several columns, as an array ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | # rows => 1 if "x" may be left out of a hash-of-hashes frame, whose row names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | # are then the labels | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | # each => 1 if each column is one distribution of its own: "many" may be left | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | # out, for every column of numbers, and without "by" the columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | # need not be the same length, since no row is read across them | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | 24 | my %frame_roles = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | bar => { take => [ 'x', 'y', 'by' ], need => ['y'], many => 'y', rows => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | barh => { take => [ 'x', 'y', 'by' ], need => ['y'], many => 'y', rows => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | boxplot => { take => [ 'y', 'by' ], need => ['y'], many => 'y' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | colored_table => { take => [ 'x', 'y' ], need => [], many => 'y', rows => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | hexbin => { take => [ 'x', 'y' ], need => [ 'x', 'y' ] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | hist => { take => [ 'x', 'by' ], need => [], many => 'x', each => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | hist2d => { take => [ 'x', 'y' ], need => [ 'x', 'y' ] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | pie => { take => [ 'x', 'y' ], need => ['y'], rows => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | plot => { take => [ 'x', 'y', 'by' ], need => [ 'x', 'y' ], many => 'y' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | scatter => { take => [ 'x', 'y', 'by' ], need => [ 'x', 'y' ] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | violin => { take => [ 'y', 'by' ], need => [], many => 'y', each => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | violinplot => { take => [ 'y', 'by' ], need => [], many => 'y', each => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | 24 | my @frame_keys = ( 'df', 'x', 'y', 'by' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | 77 | ▶ | sub frame_shape { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
frame_shape: called CC=13 SCAR=26.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | # "AoA", "AoH", "HoA" or "HoH": which of the four shapes a frame is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | 77 | my ( $df, $where ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | 77 | my $ref = ref $df; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | 77 | ▶ | if ( $ref eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | 48 | foreach my $row ( @{$df} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | 50 | ▶ | next unless defined $row; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | 48 | ▶ | return 'AoA' if ref $row eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | 45 | ▶ | return 'AoH' if ref $row eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | 1 | ▶ | die "\"df\"$where is an array, so its rows must be ARRAY (AoA) or HASH (AoH) references, but one is " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | . ( ref $row ? 'a ' . ref $row . ' reference' : "\"$row\"" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | 0 | die "\"df\"$where has no rows"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | 29 | ▶ | if ( $ref eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | 29 | ▶ | die "\"df\"$where has no columns" if scalar keys %{$df} == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | 29 | my %kinds = map { ( ref $_ ) => 1 } values %{$df}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | 29 | my @kinds = sort keys %kinds; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | 29 | ▶ | return 'HoA' if "@kinds" eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | 6 | ▶ | return 'HoH' if "@kinds" eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | die "\"df\"$where is a hash, so its values must all be ARRAY (HoA, column => values) or all HASH (HoH, row => { column => value }) references, but they are: " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | 1 | ▶ | . join( ', ', map { $_ eq '' ? 'not references' : $_ } @kinds ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | 0 | ▶ | die "\"df\"$where must be an ARRAY (AoA, AoH) or HASH (HoA, HoH) reference, not " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | . ( $ref eq '' ? 'a plain value' : "a $ref reference" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | 15 | ▶ | sub frame_column_names { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
frame_column_names: called CC=7 SCAR=21.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | # Every column name of a frame, sorted; for an AoA, every position. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | 15 | my ( $df, $shape ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | 15 | ▶ | return sort keys %{$df} if $shape eq 'HoA'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | 11 | ▶ | if ( $shape eq 'AoA' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | 0 | my $width = max( 0, map { scalar @{$_} } grep { defined } @{$df} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | 0 | return 0 .. $width - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | 11 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | 11 | ▶ | foreach my $row ( $shape eq 'HoH' ? values %{$df} : @{$df} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | 50 | ▶ | next unless ref $row eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | 50 | $seen{$_} = 1 foreach keys %{$row}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | 11 | return sort keys %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | 65 | ▶ | sub frame_columns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
frame_columns: called CC=29 SCAR=33.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | # The named columns of a frame as arrays, row by row in step with one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | # another, and the row names, which only a hash of hashes has. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | # A row's cells are all taken from that row in the one pass, rather than a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | # column at a time, so that x and y cannot come from different rows | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | # whatever the shape. Rows run in the frame's own order; a hash of hashes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | # has none, and its rows are taken in the sorted order of their names, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | # which is the order Stats::LikeR's vals() and view() give them. A column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | # that no row has is refused by name, as Stats::LikeR refuses it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | # $ragged is true when no row is read across the columns, so that the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | # columns of a hash of arrays need not be the same length; Stats::LikeR's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | # group_by gives one column per group, each as long as its group. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | # $given maps a column to the option that named it ("x", "y", "by" or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | # "color_key"), and $sub is the caller's name; both are optional, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | # serve only to say, when a column is missing, which option named it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | 65 | my ( $df, $shape, $columns, $where, $ragged, $given, $sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | 65 | ▶ | $given //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$given //= {}
MC/DC0%0/1
$given //= {}
$given
Truth table50%1/2
A
A= $given
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | # how a missing column is introduced: 'scatter: "dG", given as "x",' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | 5 | ▶ | my $named = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | 5 | my ($column) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | return ( defined $sub ? "$sub: " : '' ) . "\"$column\"" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | 5 | ▶ | . ( defined $given->{$column} ? ", given as \"$given->{$column}\"," : '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | 65 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | 65 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | 65 | my @columns = grep { not $seen{$_}++ } @{$columns}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | 65 | my ( %out, @row_names ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | 4 | ▶ | my $missing = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | 4 | my ($column) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | 4 | my @have = frame_column_names( $df, $shape ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | 4 | my @close = similar_keywords( $column, \@have ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | # 20: enough to show a typical table whole, while a wide one from a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | # spreadsheet does not bury the message under hundreds of names. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | 4 | ▶ | my $shown = scalar @have > 20 ? join( ', ', @have[ 0 .. 19 ] ) . ', ...' : join( ', ', @have ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | die $named->($column) . " is not a column in the dataframe \"df\"$where" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | 4 | ▶ | . ( scalar @close ? '; perhaps you meant ' . join( ' or ', map { "\"$_\"" } @close ) : '' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | . ". Its columns are: $shown"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | 65 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | 65 | ▶ | if ( $shape eq 'HoA' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | 23 | foreach my $column (@columns) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | 52 | ▶ | $missing->($column) unless exists $df->{$column}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | 51 | $out{$column} = $df->{$column}; # only read from here on, so not copied | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | 22 | my %n_rows = map { $_ => scalar @{ $df->{$_} } } @columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | 22 | my %lengths = map { $_ => 1 } values %n_rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | 22 | ▶ | if ( ( not $ragged ) && ( scalar keys %lengths > 1 ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $ragged and scalar keys %lengths > 1
MC/DC100%2/2
not $ragged and scalar keys %lengths > 1
not $ragged
scalar keys %lengths > 1
Truth table100%3/3
not(A) and B
A= not $raggedB= scalar keys %lengths > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | die "the columns of \"df\"$where must all have the same number of rows, but they have " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | 4 | . join( ', ', map { "\"$_\" $n_rows{$_}" } @columns ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | 18 | return ( \%out, [] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | 42 | ▶ | if ( $shape eq 'AoA' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | 3 | my $width = max( 0, map { scalar @{$_} } grep { defined } @{$df} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | 3 | my %position; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | 3 | foreach my $column (@columns) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | 5 | ▶ | if ( ( $column !~ m/^-?\d+$/ ) || ( $column >= $width ) || ( $column < -$width ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not $column =~ /^-?\d+$/ or $column >= $width or $column < -$width
not $column =~ /^-?\d+$/ or $column >= $width
MC/DC33%1/3
not $column =~ /^-?\d+$/ or $column >= $width or $column < -$width
not $column =~ /^-?\d+$/
$column >= $width
$column < -$width
Truth table50%2/4
not(A) or B or C
A= not $column =~ /^-?\d+$/B= $column >= $widthC= $column < -$width
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | 1 | die $named->($column) . " is not a column in the dataframe \"df\"$where, which is an array of arrays, whose columns are 0-based positions from 0 to " . ( $width - 1 ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | . ' (or negative, from the end)'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | 4 | ▶ | $position{$column} = $column < 0 ? $width + $column : $column; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | 4 | $out{$column} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | 2 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | 2 | foreach my $row ( @{$df} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | # An undefined row is a row with no values, left out by the caller's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | # plot like any other row missing one. frame_shape and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | # frame_column_names already stepped over it, and this died on it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | 9 | ▶ | if ( not defined $row ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | 1 | push @{ $out{$_} }, undef foreach @columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | 1 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | 8 | ▶ | die "row $i of \"df\"$where is not an ARRAY reference" unless ref $row eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | 8 | push @{ $out{$_} }, $row->[ $position{$_} ] foreach @columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | 8 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1393 | 2 | return ( \%out, [] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1395 | 39 | my @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1396 | 39 | ▶ | if ( $shape eq 'HoH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1397 | 5 | @row_names = sort keys %{$df}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1398 | 5 | @rows = @{$df}{@row_names}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1399 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1400 | 34 | @rows = @{$df}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1402 | 39 | my %found; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1403 | 39 | foreach my $i ( 0 .. $#rows ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1404 | 200 | ▶ | if ( ( $shape eq 'AoH' ) && ( not defined $rows[$i] ) ) { # as for an array of arrays above | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$shape eq "AoH" and not defined $rows[$i]
MC/DC100%2/2
$shape eq "AoH" and not defined $rows[$i]
$shape eq "AoH"
not defined $rows[$i]
Truth table100%3/3
A and not(B)
A= $shape eq "AoH"B= not defined $rows[$i]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1405 | 1 | push @{ $out{$_} }, undef foreach @columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1406 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1408 | 199 | ▶ | if ( ref $rows[$i] ne 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1409 | 0 | ▶ | die 'row ' . ( $shape eq 'HoH' ? "\"$row_names[$i]\"" : $i ) . " of \"df\"$where is not a HASH reference"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1411 | 199 | foreach my $column (@columns) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1412 | 499 | ▶ | $found{$column} = 1 if exists $rows[$i]{$column}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1413 | 499 | push @{ $out{$column} }, $rows[$i]{$column}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1414 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1416 | 39 | foreach my $column (@columns) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1417 | 92 | ▶ | $missing->($column) unless $found{$column}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1419 | 36 | return ( \%out, \@row_names ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1420 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1421 | 38 | ▶ | sub complete_rows { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
complete_rows: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1422 | # The indices of the rows that have a value in every one of the columns. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1423 | 38 | my ( $cells, $columns ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1424 | 38 | my $n = scalar @{ $cells->{ $columns->[0] } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1425 | return grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1426 | 38 | my $i = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1427 | 183 | not grep { not defined $cells->{$_}[$i] } @{$columns} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1428 | } 0 .. $n - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1430 | 69 | ▶ | sub check_dropped { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_dropped: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1431 | # Say how many rows were left out for want of a value, as ggplot2's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1432 | # "Removed 3 rows containing missing values" does: a missing value cannot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1433 | # be drawn, and refusing every frame with one in it would refuse most real | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1434 | # data, but rows leaving a plot without a word would be worse. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1435 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1436 | # Die if that was every row. Only plot without "by", and scatter, hexbin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1437 | # and hist2d, checked for themselves, and scatter's message left out the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1438 | # "by" column; the rest made an empty "data" and died as '"data" is an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1439 | # empty hash', about an option the caller had never given. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1440 | 69 | my ( $n_kept, $n, $columns, $where, $sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1441 | 69 | ▶ | if ( $n_kept == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1442 | 7 | my @names = map { "\"$_\"" } @{$columns}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1443 | 7 | ▶ | die "$sub: no row of \"df\"$where has a value in " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1444 | . ( scalar @names == 1 ? $names[0] : scalar @names == 2 ? "both $names[0] and $names[1]" : 'every one of ' . join( ', ', @names ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1445 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1446 | 62 | ▶ | return if $n_kept == $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1447 | warn "$sub: left out " . ( $n - $n_kept ) . " of $n rows of \"df\"$where, which have no value in " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1448 | 24 | . join( ' or ', map { "\"$_\"" } @{$columns} ) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1450 | 21 | ▶ | sub group_order { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
group_order: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1451 | # The distinct values of a grouping column, in numeric order when every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1452 | # one is a number and in string order otherwise: 2 before 10, as a reader | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1453 | # expects, where the sorted order of keys would put 10 first. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1454 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1455 | # A NaN made "<=>" return undef, which FATAL warnings turned into a death | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1456 | # in sort, so NaN and the infinities count as text. Values that are equal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1457 | # as numbers, "2" and "2.0", are ordered as strings: they came in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1458 | # order of a hash's keys, which changes from run to run. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1459 | 21 | my @values = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1460 | 21 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1461 | 21 | my @groups = grep { not $seen{$_}++ } @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1462 | 55 | ▶ | return ( grep { ( not looks_like_number($_) ) || ( not is_finite($_) ) } @groups ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
&looks_like_number($_) && is_finite($_)
MC/DC100%2/2
&looks_like_number($_) && is_finite($_)
&looks_like_number($_)
is_finite($_)
Truth table100%3/3
A && B
A= &looks_like_number($_)B= is_finite($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1463 | ? sort @groups | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1464 | 21 | ▶ | : sort { ( $a <=> $b ) || ( $a cmp $b ) } @groups; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$a <=> $b || $a cmp $b
MC/DC0%0/2
$a <=> $b || $a cmp $b
$a <=> $b
$a cmp $b
Truth table66%2/3
A || B
A= $a <=> $bB= $a cmp $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1465 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1466 | 11 | ▶ | sub first_seen { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
first_seen: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1467 | # The distinct values of a column, in the order of the rows they first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1468 | # appear in. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1469 | 11 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1470 | 11 | return grep { not $seen{$_}++ } @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1472 | 1399 | ▶ | sub frame_to_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
frame_to_data: called CC=132 SCAR=49.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1473 | # Rewrite one plot hash holding "df" into the "data" its plot_type takes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1474 | # deleting "df", "x", "y" and "by", and filling in the options that say | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1475 | # what the columns were: "key_order" or "keys", so that x is drawn on the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1476 | # x axis rather than wherever the sorted names put it, and the axis | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1477 | # labels, which the caller's own still override. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1478 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1479 | # The plot hash is plt's own copy, made by copy_plot_hashes, so writing to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1480 | # it leaves the caller's as it was. The frame is only read. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1481 | 1399 | my ( $plot, $type, $where, $sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1482 | 1399 | ▶ | if ( not exists $plot->{df} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1483 | 1319 | my @stray = grep { exists $plot->{$_} } ( 'x', 'y', 'by' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1484 | 1319 | ▶ | return unless scalar @stray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1485 | 1 | ▶ | die "$sub: " . join( ', ', map { "\"$_\"" } @stray ) . "$where name" . ( scalar @stray == 1 ? 's' : '' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1486 | . ' columns of "df", but no "df" was given'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1487 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1488 | 80 | ▶ | die "$sub: \"df\"$where is undefined" unless defined $plot->{df}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1489 | 80 | ▶ | die "$sub: \"df\" and \"data\" cannot both be given$where; \"df\" is turned into \"data\"" if exists $plot->{data}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1490 | 79 | ▶ | die "$sub: \"df\"$where needs a \"plot_type\" to say how its columns are drawn" unless defined $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1491 | 79 | ▶ | check_plot_type({ type => $type, where => ( $where eq '' ? undef : substr( $where, 1 ) ) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1492 | 79 | my $roles = $frame_roles{$type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1493 | 79 | ▶ | if ( not defined $roles ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1494 | 1 | die "$sub: plot_type \"$type\"$where does not take \"df\"; give it \"data\". The plot types that take \"df\" are: " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1495 | . join( ', ', sort keys %frame_roles ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1496 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1497 | 78 | my %takes = map { $_ => 1 } @{ $roles->{take} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1498 | 78 | ▶ | my @refused = grep { ( exists $plot->{$_} ) && ( not $takes{$_} ) } ( 'x', 'y', 'by' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
exists $plot->{$_} && !$takes{$_}
MC/DC100%2/2
exists $plot->{$_} && !$takes{$_}
exists $plot->{$_}
!$takes{$_}
Truth table100%3/3
A && not(B)
A= exists $plot->{$_}B= !$takes{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1499 | 78 | ▶ | if ( scalar @refused ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1500 | die "$sub: plot_type \"$type\"$where takes its columns of \"df\" in " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1501 | 1 | . join( ' and ', map { "\"$_\"" } @{ $roles->{take} } ) . ', not in ' . join( ' or ', map { "\"$_\"" } @refused ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1502 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1503 | 77 | my $df = $plot->{df}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1504 | 77 | my $shape = frame_shape( $df, $where ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1505 | 75 | my @need = @{ $roles->{need} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1506 | 75 | ▶ | push @need, 'x' if ( $takes{x} ) && ( $roles->{rows} ) && ( $shape ne 'HoH' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$takes{"x"} and $roles->{"rows"} and $shape ne "HoH"
$takes{"x"} and $roles->{"rows"}
MC/DC100%3/3
$takes{"x"} and $roles->{"rows"} and $shape ne "HoH"
$takes{"x"}
$roles->{"rows"}
$shape ne "HoH"
Truth table100%4/4
A and B and C
A= $takes{"x"}B= $roles->{"rows"}C= $shape ne "HoH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1507 | 75 | ▶ | push @need, $roles->{many} if ( $roles->{each} ) && ( defined $plot->{by} ); # the one column "by" splits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$roles->{"each"} and defined $plot->{"by"}
MC/DC100%2/2
$roles->{"each"} and defined $plot->{"by"}
$roles->{"each"}
defined $plot->{"by"}
Truth table100%3/3
A and B
A= $roles->{"each"}B= defined $plot->{"by"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1508 | 75 | my @absent = grep { not defined $plot->{$_} } @need; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1509 | 75 | ▶ | if ( scalar @absent ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1510 | 5 | ▶ | die "$sub: plot_type \"$type\"$where needs " . join( ' and ', map { "\"$_\"" } @absent ) . ' to name ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
grep {$_ eq "x";} @absent and $roles->{"rows"}
MC/DC100%2/2
grep {$_ eq "x";} @absent and $roles->{"rows"}
grep {$_ eq "x";} @absent
$roles->{"rows"}
Truth table100%3/3
A and B
A= grep {$_ eq "x";} @absentB= $roles->{"rows"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1511 | . ( scalar @absent == 1 ? 'a column' : 'columns' ) . ' of "df"' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1512 | 5 | . ( ( grep { $_ eq 'x' } @absent ) && ( $roles->{rows} ) ? '; only a hash of hashes has row names to label it by instead' : '' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1513 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1514 | # Each role as a list of column names; only $roles->{many} may hold more than one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1515 | 70 | my %col; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1516 | 70 | foreach my $role ( 'x', 'y', 'by' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1517 | 209 | ▶ | next unless defined $plot->{$role}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1518 | 118 | my $value = $plot->{$role}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1519 | 118 | ▶ | my @names = ref $value eq 'ARRAY' ? @{$value} : ($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1520 | 118 | ▶ | if ( ( ref $value ne '' ) && ( ref $value ne 'ARRAY' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $value ne "" and ref $value ne "ARRAY"
MC/DC0%0/2
ref $value ne "" and ref $value ne "ARRAY"
ref $value ne ""
ref $value ne "ARRAY"
Truth table66%2/3
A and B
A= ref $value ne ""B= ref $value ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1521 | 0 | ▶ | die "$sub: \"$role\"$where names a column of \"df\", or for \"" . ( $roles->{many} // $role ) . '" an array of them, not a ' . ref($value) . ' reference'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$roles->{"many"} // $role
MC/DC0%0/2
$roles->{"many"} // $role
$roles->{"many"}
$role
Truth table0%0/3
A // B
A= $roles->{"many"}B= $role
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1522 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1523 | 118 | ▶ | die "$sub: \"$role\"$where is an empty array" if scalar @names == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1524 | 118 | ▶ | my @bad = grep { ( not defined $_ ) || ( ref $_ ) } @names; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
!defined($_) || ref $_
MC/DC0%0/2
!defined($_) || ref $_
!defined($_)
ref $_
Truth table33%1/3
not(A) || B
A= !defined($_)B= ref $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1525 | 118 | ▶ | die "$sub: \"$role\"$where holds something that is not a column name" if scalar @bad; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1526 | 118 | ▶ | if ( ( scalar @names > 1 ) && ( ( $roles->{many} // '' ) ne $role ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
scalar @names > 1 and ($roles->{"many"} // "") ne $role
$roles->{"many"} // ""
MC/DC100%2/2
scalar @names > 1 and ($roles->{"many"} // "") ne $role
scalar @names > 1
$roles->{"many"}
Truth table100%3/3
A and B
A= scalar @names > 1B= $roles->{"many"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1527 | die "$sub: \"$role\"$where can name only one column for plot_type \"$type\"" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1528 | 1 | ▶ | . ( defined $roles->{many} ? "; \"$roles->{many}\" is the one that takes several" : '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1529 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1530 | 117 | $col{$role} = \@names; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1532 | 69 | ▶ | my $many = $roles->{many} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$roles->{"many"} // ""
MC/DC100%1/1
$roles->{"many"} // ""
$roles->{"many"}
Truth table100%2/2
A
A= $roles->{"many"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1533 | 69 | ▶ | if ( ( defined $col{by} ) && ( defined $col{$many} ) && ( scalar @{ $col{$many} } > 1 ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $col{"by"} and defined $col{$many} and scalar @{$col{$many};} > 1
defined $col{"by"} and defined $col{$many}
MC/DC100%3/3
defined $col{"by"} and defined $col{$many} and scalar @{$col{$many};} > 1
defined $col{"by"}
defined $col{$many}
scalar @{$col{$many};} > 1
Truth table100%4/4
A and B and C
A= defined $col{"by"}B= defined $col{$many}C= scalar @{$col{$many};} > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1534 | 1 | die "$sub: \"by\"$where splits one column into groups, so \"$many\" can name only one column when \"by\" is given"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1535 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1536 | 68 | ▶ | my $color_key = ( $type eq 'scatter' ) ? $plot->{color_key} : undef; # a column too, for scatter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1537 | 68 | ▶ | if ( ( defined $color_key ) && ( ref $color_key ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $color_key and ref $color_key
MC/DC0%0/2
defined $color_key and ref $color_key
defined $color_key
ref $color_key
Truth table66%2/3
A and B
A= defined $color_keyB= ref $color_key
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1538 | 0 | die "$sub: \"color_key\"$where names one column of \"df\""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1539 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1540 | 68 | ▶ | my @used = ( map { @{ $col{$_} // [] } } ( 'x', 'y', 'by' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$col{$_} // []
MC/DC100%1/1
$col{$_} // []
$col{$_}
Truth table100%2/2
A
A= $col{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1541 | 68 | ▶ | push @used, $color_key if defined $color_key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1542 | 68 | my %n_named; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1543 | 68 | my @twice = grep { $n_named{$_}++ == 1 } @used; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1544 | 68 | ▶ | if ( scalar @twice ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1545 | # The columns become the keys of "data", so one named twice would be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1546 | # drawn against itself, or silently once. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1547 | 1 | die "$sub: " . join( ', ', map { "\"$_\"" } @twice ) . "$where is named more than once among the columns of \"df\" to plot"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1548 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1549 | 67 | ▶ | foreach my $option ( grep { exists $plot->{$_} } ( 'keys', ( $type =~ m/^(?:hexbin|hist2d)$/ ? 'key_order' : () ) ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1550 | 2 | die "$sub: \"$option\"$where cannot be given with \"df\": \"x\" and \"y\" already say which column goes on which axis"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1551 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1552 | 65 | my @default_y; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1553 | 65 | ▶ | if ( ( $type eq 'colored_table' ) && ( not defined $col{y} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$type eq "colored_table" and not defined $col{"y"}
MC/DC100%2/2
$type eq "colored_table" and not defined $col{"y"}
$type eq "colored_table"
not defined $col{"y"}
Truth table100%3/3
A and not(B)
A= $type eq "colored_table"B= not defined $col{"y"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1554 | 2 | ▶ | my %is_x = map { $_ => 1 } @{ $col{x} // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$col{"x"} // []
MC/DC100%1/1
$col{"x"} // []
$col{"x"}
Truth table100%2/2
A
A= $col{"x"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1555 | 2 | @default_y = grep { not $is_x{$_} } frame_column_names( $df, $shape ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1556 | 2 | $col{y} = \@default_y; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1557 | 2 | ▶ | @used = ( @{ $col{x} // [] }, @default_y ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$col{"x"} // []
MC/DC100%1/1
$col{"x"} // []
$col{"x"}
Truth table100%2/2
A
A= $col{"x"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1558 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1559 | 65 | ▶ | my $every_column = ( $roles->{each} ) && ( not defined $col{$many} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$roles->{'each'} && !defined($col{$many})
MC/DC100%2/2
$roles->{'each'} && !defined($col{$many})
$roles->{'each'}
!defined($col{$many})
Truth table100%3/3
A && not(B)
A= $roles->{'each'}B= !defined($col{$many})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1560 | 65 | ▶ | @used = frame_column_names( $df, $shape ) if $every_column; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1561 | 65 | my %given; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1562 | 65 | foreach my $role ( 'x', 'y', 'by' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1563 | 195 | ▶ | $given{$_} = $role foreach @{ $col{$role} // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$col{$role} // []
MC/DC100%1/1
$col{$role} // []
$col{$role}
Truth table100%2/2
A
A= $col{$role}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1564 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1565 | 65 | ▶ | $given{$color_key} = 'color_key' if defined $color_key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1566 | 65 | ▶ | my ( $cells, $row_names ) = frame_columns( $df, $shape, \@used, $where, $roles->{each} && ( not defined $col{by} ), \%given, $sub ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$roles->{'each'} && !defined($col{'by'})
MC/DC100%2/2
$roles->{'each'} && !defined($col{'by'})
$roles->{'each'}
!defined($col{'by'})
Truth table100%3/3
A && not(B)
A= $roles->{'each'}B= !defined($col{'by'})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1567 | # the longest column, as the columns of "each" need not be the same length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1568 | 56 | ▶ | my $n_rows = scalar( @{$row_names} ) || max( 0, map { scalar @{ $cells->{$_} } } @used ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
scalar @{$row_names;} || &max(0, map({scalar @{$cells->{$_};};} @used))
MC/DC0%0/2
scalar @{$row_names;} || &max(0, map({scalar @{$cells->{$_};};} @used))
scalar @{$row_names;}
&max(0, map({scalar @{$cells->{$_};};} @used))
Truth table66%2/3
A || B
A= scalar @{$row_names;}B= &max(0, map({scalar @{$cells->{$_};};} @used))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1569 | 56 | ▶ | die "\"df\"$where has no rows" if $n_rows == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1570 | 56 | ▶ | if ($every_column) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1571 | # Every column that holds numbers and nothing else, as pandas' DataFrame.hist | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1572 | # and .boxplot take every numeric column: a column of names or of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1573 | # categories is not a distribution, and most tables have one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1574 | my @numeric = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1575 | 9 | my @values = grep { defined } @{ $cells->{$_} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1576 | 27 | ▶ | ( scalar @values ) && ( not grep { not looks_like_number($_) } @values ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
scalar @values && !grep({not &looks_like_number($_);} @values)
MC/DC50%1/2
scalar @values && !grep({not &looks_like_number($_);} @values)
scalar @values
!grep({not &looks_like_number($_);} @values)
Truth table66%2/3
A && not(B)
A= scalar @valuesB= !grep({not &looks_like_number($_);} @values)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1577 | } @used; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1578 | 9 | ▶ | die "$sub: \"df\"$where has no column of numbers to draw" if scalar @numeric == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1579 | # in numeric order when every name is a number, as the groups of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1580 | # group_by are, so that 4, 6 and 8 cylinders are drawn in that order | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1581 | 6 | $col{$many} = [ group_order(@numeric) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1582 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1583 | 53 | ▶ | my ($x) = @{ $col{x} // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$col{"x"} // []
MC/DC100%1/1
$col{"x"} // []
$col{"x"}
Truth table100%2/2
A
A= $col{"x"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1584 | 53 | ▶ | my ($by) = @{ $col{by} // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$col{"by"} // []
MC/DC100%1/1
$col{"by"} // []
$col{"by"}
Truth table100%2/2
A
A= $col{"by"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1585 | 53 | ▶ | my @y = @{ $col{y} // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$col{"y"} // []
MC/DC100%1/1
$col{"y"} // []
$col{"y"}
Truth table100%2/2
A
A= $col{"y"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1586 | 53 | my %data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1587 | 48 | ▶ | my $label_axis = sub { # default an axis label to a column name; py_str because a column name is data, see hist2d_helper | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1588 | 48 | my ( $axis, $column ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1589 | 48 | ▶ | return unless defined $column; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1590 | 27 | ▶ | return if ( defined $plot->{$axis} ) || ( defined $plot->{"set_$axis"} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $plot->{$axis} or defined $$plot{"set_$axis"}
MC/DC50%1/2
defined $plot->{$axis} or defined $$plot{"set_$axis"}
defined $plot->{$axis}
defined $$plot{"set_$axis"}
Truth table66%2/3
A or B
A= defined $plot->{$axis}B= defined $$plot{"set_$axis"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1591 | 26 | $plot->{$axis} = py_str($column); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1592 | 53 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1593 | 53 | ▶ | if ( $type =~ m/^(?:bar|barh|pie|colored_table)$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1594 | # The labels: column "x", or the row names of a hash of hashes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1595 | 18 | ▶ | my $labels = defined $x ? $cells->{$x} : $row_names; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1596 | 18 | ▶ | if ( $type eq 'colored_table' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1597 | # $x is undefined for a hash of hashes labelled by its row names, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1598 | # and the message died as "Use of uninitialized value $x". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1599 | 3 | ▶ | if ( scalar @y == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1600 | 1 | ▶ | die "$sub: \"df\"$where has no columns " . ( defined $x ? "but \"$x\" " : '' ) . 'to put in the table'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1601 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1602 | 2 | my %row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1603 | 2 | foreach my $i ( grep { defined $labels->[$_] } 0 .. $n_rows - 1 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1604 | 12 | my $label = $labels->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1605 | 12 | ▶ | die "$sub: \"$label\" appears in more than one row of \"$x\" in \"df\"$where, and colored_table has one row per label" if $row{$label}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1606 | # An undefined cell is left out, which colored_table draws as undefined. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1607 | 12 | $row{$label} = { map { $_ => $cells->{$_}[$i] } grep { defined $cells->{$_}[$i] } @y }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1608 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1609 | 2 | ▶ | check_dropped( scalar keys %row, $n_rows, [$x], $where, $sub ) if defined $x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1610 | 2 | %data = %row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1611 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1612 | 15 | ▶ | my @value_cols = ( @y, ( defined $by ? $by : () ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1613 | 15 | my @kept = grep { defined $labels->[$_] } complete_rows( $cells, \@value_cols ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1614 | 15 | ▶ | check_dropped( scalar @kept, $n_rows, [ ( defined $x ? $x : () ), @value_cols ], $where, $sub ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1615 | 12 | my @labels = map { $labels->[$_] } @kept; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1616 | 12 | ▶ | my $what = $type eq 'pie' ? 'wedge' : 'bar'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1617 | 12 | ▶ | if ( defined $by ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1618 | # A pivot: one series per group, one bar per label in each. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1619 | 3 | my @groups = group_order( map { $cells->{$by}[$_] } @kept ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1620 | 3 | my %cell; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1621 | 3 | foreach my $i (@kept) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1622 | 12 | my ( $label, $group ) = ( $labels->[$i], $cells->{$by}[$i] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1623 | 12 | ▶ | if ( exists $cell{$label}{$group} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1624 | 1 | die "$sub: more than one row of \"df\"$where has \"$x\" = \"$label\" and \"$by\" = \"$group\", and a grouped $type draws one bar for each pair: aggregate the rows first, e.g. with Stats::LikeR's agg or pivot_table"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1625 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1626 | 11 | $cell{$label}{$group} = $cells->{ $y[0] }[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1627 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1628 | 2 | my @labels_once = first_seen(@labels); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1629 | 2 | my @gaps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1630 | 2 | foreach my $label (@labels_once) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1631 | 4 | push @gaps, map { "\"$label\"/\"$_\"" } grep { not exists $cell{$label}{$_} } @groups; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1632 | 4 | $data{$label} = [ map { $cell{$label}{$_} } @groups ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1633 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1634 | 2 | ▶ | if ( scalar @gaps ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1635 | 1 | ▶ | splice @gaps, 5, scalar(@gaps) - 5, '...' if scalar @gaps > 5; # enough to see the pattern | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1636 | 1 | ▶ | die "$sub: no row of \"df\"$where has a value for " . join( ', ', @gaps ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1637 | . ' (' . ( defined $x ? "\"$x\"" : 'row name' ) . "/\"$by\"), and a grouped $type needs one for every pair"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1638 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1639 | 1 | ▶ | $plot->{label} = $plot->{label} // [@groups]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$plot->{"label"} // [@groups]
MC/DC0%0/1
$plot->{"label"} // [@groups]
$plot->{"label"}
Truth table50%1/2
A
A= $plot->{"label"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1640 | 1 | ▶ | if ( ref $plot->{color} eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1641 | # The series are the groups, so a color keyed by group can be put in their order here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1642 | 1 | my @uncolored = grep { not defined $plot->{color}{$_} } @groups; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1643 | 0 | ▶ | die "$sub: \"color\"$where has no color for the groups " . join( ', ', map { "\"$_\"" } @uncolored ) if scalar @uncolored; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1644 | 1 | $plot->{color} = [ @{ $plot->{color} }{@groups} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1645 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1646 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1647 | 9 | my %row_of; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1648 | 9 | foreach my $i (@kept) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1649 | 42 | my $label = $labels->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1650 | 42 | ▶ | if ( exists $row_of{$label} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1651 | 1 | die "$sub: \"$label\" appears in more than one row of \"$x\" in \"df\"$where, and $type draws one $what per label: aggregate the rows first, e.g. with Stats::LikeR's agg"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1652 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1653 | 41 | $row_of{$label} = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1654 | 41 | ▶ | $data{$label} = scalar @y == 1 ? $cells->{ $y[0] }[$i] : [ map { $cells->{$_}[$i] } @y ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1655 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1656 | 8 | ▶ | if ( scalar @y > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1657 | 1 | ▶ | $plot->{label} = $plot->{label} // [@y]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$plot->{"label"} // [@y]
MC/DC0%0/1
$plot->{"label"} // [@y]
$plot->{"label"}
Truth table50%1/2
A
A= $plot->{"label"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1658 | 1 | ▶ | if ( ref $plot->{color} eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1659 | 1 | my @uncolored = grep { not defined $plot->{color}{$_} } @y; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1660 | 0 | ▶ | die "$sub: \"color\"$where has no color for the columns " . join( ', ', map { "\"$_\"" } @uncolored ) if scalar @uncolored; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1661 | 1 | $plot->{color} = [ @{ $plot->{color} }{@y} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1662 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1663 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1664 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1665 | # The rows of a table are in an order of their own, which the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1666 | # sorted labels would lose. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1667 | 9 | ▶ | $plot->{key_order} = $plot->{key_order} // [ first_seen(@labels) ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$plot->{"key_order"} // [first_seen(@labels)]
MC/DC0%0/1
$plot->{"key_order"} // [first_seen(@labels)]
$plot->{"key_order"}
Truth table50%1/2
A
A= $plot->{"key_order"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1668 | 9 | ▶ | if ( $type ne 'pie' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1669 | 8 | ▶ | my ( $label_axis_name, $value_axis_name ) = $type eq 'barh' ? ( 'ylabel', 'xlabel' ) : ( 'xlabel', 'ylabel' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1670 | 8 | $label_axis->( $label_axis_name, $x ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1671 | 8 | ▶ | $label_axis->( $value_axis_name, scalar @y == 1 ? $y[0] : undef ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1672 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1673 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1674 | } elsif ( $type =~ m/^(?:hist|boxplot|violin|violinplot)$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1675 | # One distribution per column, or one per group of a single column. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1676 | 17 | ▶ | my @value_cols = $type eq 'hist' ? @{ $col{x} } : @y; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1677 | 17 | ▶ | if ( defined $by ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1678 | 4 | my $column = $value_cols[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1679 | 4 | my @kept = complete_rows( $cells, [ $column, $by ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1680 | 4 | check_dropped( scalar @kept, $n_rows, [ $column, $by ], $where, $sub ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1681 | 3 | push @{ $data{ $cells->{$by}[$_] } }, $cells->{$column}[$_] foreach @kept; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1682 | 3 | ▶ | $plot->{key_order} = $plot->{key_order} // [ group_order( keys %data ) ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$plot->{"key_order"} // [group_order(keys %data)]
MC/DC0%0/1
$plot->{"key_order"} // [group_order(keys %data)]
$plot->{"key_order"}
Truth table50%1/2
A
A= $plot->{"key_order"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1683 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1684 | # Column by column: a value missing from one column says nothing about the others. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1685 | 13 | foreach my $column (@value_cols) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1686 | 30 | $data{$column} = [ grep { defined } @{ $cells->{$column} } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1687 | 30 | check_dropped( scalar @{ $data{$column} }, scalar @{ $cells->{$column} }, [$column], $where, $sub ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1688 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1689 | 12 | ▶ | $plot->{key_order} = $plot->{key_order} // [@value_cols]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$plot->{"key_order"} // [@value_cols]
MC/DC0%0/1
$plot->{"key_order"} // [@value_cols]
$plot->{"key_order"}
Truth table50%1/2
A
A= $plot->{"key_order"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1690 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1691 | 15 | ▶ | my $values = scalar @value_cols == 1 ? $value_cols[0] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1692 | 15 | ▶ | if ( $type eq 'hist' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1693 | 6 | ▶ | $label_axis->( ( $plot->{orientation} // '' ) eq 'horizontal' ? 'ylabel' : 'xlabel', $values ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$plot->{"orientation"} // ""
MC/DC0%0/1
$plot->{"orientation"} // ""
$plot->{"orientation"}
Truth table50%1/2
A
A= $plot->{"orientation"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1694 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1695 | 9 | ▶ | my $horizontal = ( $plot->{orientation} // '' ) eq 'horizontal'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$plot->{"orientation"} // ""
MC/DC100%1/1
$plot->{"orientation"} // ""
$plot->{"orientation"}
Truth table100%2/2
A
A= $plot->{"orientation"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1696 | 9 | ▶ | $label_axis->( $horizontal ? 'xlabel' : 'ylabel', $values ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1697 | 9 | ▶ | $label_axis->( $horizontal ? 'ylabel' : 'xlabel', $by ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1698 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1699 | } elsif ( $type =~ m/^(?:scatter|hist2d|hexbin)$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1700 | 13 | ▶ | my @axes = ( $x, $y[0], ( defined $color_key ? $color_key : () ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1701 | 13 | ▶ | my @kept = complete_rows( $cells, [ @axes, ( defined $by ? $by : () ) ] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1702 | 13 | ▶ | check_dropped( scalar @kept, $n_rows, [ @axes, ( defined $by ? $by : () ) ], $where, $sub ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1703 | 12 | ▶ | if ( defined $by ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1704 | 2 | foreach my $i (@kept) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1705 | 9 | push @{ $data{ $cells->{$by}[$i] }{$_} }, $cells->{$_}[$i] foreach @axes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1706 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1707 | # in numeric order when the groups are numbers, as for every other | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1708 | # type; the sets of a scatter were drawn in sorted order, 10 before 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1709 | 2 | ▶ | $plot->{key_order} = $plot->{key_order} // [ group_order( keys %data ) ] if $type eq 'scatter'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$plot->{"key_order"} // [group_order(keys %data)]
MC/DC0%0/1
$plot->{"key_order"} // [group_order(keys %data)]
$plot->{"key_order"}
Truth table50%1/2
A
A= $plot->{"key_order"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1710 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1711 | 10 | $data{$_} = [ @{ $cells->{$_} }[@kept] ] foreach @axes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1712 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1713 | # The helpers' labels are taken from these, so they need not be set here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1714 | 12 | ▶ | if ( $type eq 'scatter' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1715 | 10 | $plot->{'keys'} = [@axes]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1716 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1717 | 2 | $plot->{key_order} = [ $x, $y[0] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1718 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1719 | } elsif ( $type eq 'plot' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1720 | # One line per y column, or per group: each in the order of x, as a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1721 | # line through a table's rows is meant to be read, the ties in row order. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1722 | 6 | ▶ | my $line = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1723 | 6 | my ( $y_col, @rows ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1724 | 6 | my @xs = @{ $cells->{$x} }[@rows]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1725 | 6 | ▶ | if ( not grep { not looks_like_number($_) } @xs ) { # a word is refused by plot_helper, by name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1726 | 6 | ▶ | @rows = @rows[ sort { $xs[$a] <=> $xs[$b] || $a <=> $b } 0 .. $#rows ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$xs[$a] <=> $xs[$b] || $a <=> $b
MC/DC0%0/2
$xs[$a] <=> $xs[$b] || $a <=> $b
$xs[$a] <=> $xs[$b]
$a <=> $b
Truth table33%1/3
A || B
A= $xs[$a] <=> $xs[$b]B= $a <=> $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1727 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1728 | 6 | return [ [ @{ $cells->{$x} }[@rows] ], [ @{ $cells->{$y_col} }[@rows] ] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1729 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1730 | 5 | ▶ | if ( defined $by ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1731 | 2 | my @kept = complete_rows( $cells, [ $x, $y[0], $by ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1732 | 2 | check_dropped( scalar @kept, $n_rows, [ $x, $y[0], $by ], $where, $sub ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1733 | 1 | my %rows_of; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1734 | 1 | push @{ $rows_of{ $cells->{$by}[$_] } }, $_ foreach @kept; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1735 | 1 | $data{$_} = $line->( $y[0], @{ $rows_of{$_} } ) foreach keys %rows_of; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1736 | 1 | ▶ | $plot->{key_order} = $plot->{key_order} // [ group_order( keys %rows_of ) ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$plot->{"key_order"} // [group_order(keys %rows_of)]
MC/DC0%0/1
$plot->{"key_order"} // [group_order(keys %rows_of)]
$plot->{"key_order"}
Truth table50%1/2
A
A= $plot->{"key_order"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1737 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1738 | 3 | foreach my $y_col (@y) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1739 | 4 | my @kept = complete_rows( $cells, [ $x, $y_col ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1740 | 4 | check_dropped( scalar @kept, $n_rows, [ $x, $y_col ], $where, $sub ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1741 | 4 | $data{$y_col} = $line->( $y_col, @kept ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1742 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1743 | 3 | ▶ | $plot->{key_order} = $plot->{key_order} // [@y]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$plot->{"key_order"} // [@y]
MC/DC0%0/1
$plot->{"key_order"} // [@y]
$plot->{"key_order"}
Truth table50%1/2
A
A= $plot->{"key_order"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1744 | # One line needs no legend: the y axis already says what it is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1745 | 3 | ▶ | $plot->{show_legend} = $plot->{show_legend} // 0 if scalar @y == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$plot->{"show_legend"} // 0
MC/DC0%0/1
$plot->{"show_legend"} // 0
$plot->{"show_legend"}
Truth table50%1/2
A
A= $plot->{"show_legend"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1746 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1747 | 4 | $label_axis->( 'xlabel', $x ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1748 | 4 | ▶ | $label_axis->( 'ylabel', defined $by || scalar @y == 1 ? $y[0] : undef ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $by or scalar @y == 1
MC/DC100%2/2
defined $by or scalar @y == 1
defined $by
scalar @y == 1
Truth table100%3/3
A or B
A= defined $byB= scalar @y == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1749 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1750 | 0 | die "plot_type \"$type\" is in %frame_roles but frame_to_data has no branch for it"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1751 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1752 | 42 | delete @{$plot}{@frame_keys}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1753 | 42 | $plot->{data} = \%data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1754 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1755 | 1199 | ▶ | sub frames_to_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
frames_to_data: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1756 | # frame_to_data for every plot hash plt will draw: the top level, each | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1757 | # subplot, and each "add" graph, which takes its subplot's plot_type when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1758 | # it has none of its own. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1759 | 1199 | my ( $args, $sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1760 | 1278 | ▶ | my $graphs = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1761 | 1278 | my ( $plot, $at ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1762 | 1278 | ▶ | return unless ref $plot->{add} eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1763 | 49 | foreach my $graph ( @{ $plot->{add} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1764 | 55 | ▶ | next unless ref $graph eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1765 | 53 | ▶ | frame_to_data( $graph, $graph->{plot_type} // $plot->{plot_type}, " for an \"add\" graph$at", $sub ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$graph->{"plot_type"} // $plot->{"plot_type"}
MC/DC0%0/2
$graph->{"plot_type"} // $plot->{"plot_type"}
$graph->{"plot_type"}
$plot->{"plot_type"}
Truth table66%2/3
A // B
A= $graph->{"plot_type"}B= $plot->{"plot_type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1766 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1767 | 1199 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1768 | 1199 | ▶ | if ( ref $args->{plots} eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1769 | 103 | my @top = grep { exists $args->{$_} } @frame_keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1770 | 103 | ▶ | if ( scalar @top ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1771 | 1 | ▶ | die "$sub: " . join( ', ', map { "\"$_\"" } @top ) . ' belong' . ( scalar @top == 1 ? 's' : '' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1772 | . ' to a subplot when "plots" or "p" is given, not to the figure'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1773 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1774 | 102 | foreach my $j ( 0 .. $#{ $args->{plots} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1775 | 191 | my $plot = $args->{plots}[$j]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1776 | 191 | ▶ | next unless ref $plot eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1777 | 190 | frame_to_data( $plot, $plot->{plot_type}, " at subplot $j", $sub ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1778 | 190 | $graphs->( $plot, " at subplot $j" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1779 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1780 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1781 | 1096 | frame_to_data( $args, $args->{plot_type}, '', $sub ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1782 | 1088 | $graphs->( $args, '' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1783 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1784 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1785 | 10 | ▶ | sub shared_table_range { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shared_table_range: called CC=17 SCAR=30.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1786 | # One color scale for the colored_tables that share a colorbar, as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1787 | # "cb_min" and "cb_max" for each that does not give its own. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1788 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1789 | # A table colors its cells in Perl's order of things, from the range of its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1790 | # own cells, so tables sharing a colorbar each spread their own range over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1791 | # the whole colormap, and the one colorbar -- drawn from the last of them -- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1792 | # was true only of that one. shared_color_scale cannot reach them, because | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1793 | # their colors are fixed when the table is drawn. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1794 | 10 | my ( $args, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1795 | 10 | ▶ | my @tables = grep { ( $args->{plots}[$_]{plot_type} // '' ) eq 'colored_table' } @{ $args->{shared_colorbar} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{"plots"}[$_]{"plot_type"} // ""
MC/DC0%0/1
$args->{"plots"}[$_]{"plot_type"} // ""
$args->{"plots"}[$_]{"plot_type"}
Truth table50%1/2
A
A= $args->{"plots"}[$_]{"plot_type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1796 | 10 | ▶ | return if scalar @tables < 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1797 | # Any one table on a log scale puts them all on one, so this is known | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1798 | # before the first cell is looked at. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1799 | 3 | my $log = grep { bool_option( $_->{cb_logscale}, 'cb_logscale', $current_sub ) } map { $args->{plots}[$_] } @tables; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1800 | # The range is kept as it goes, a row at a time; every cell of every table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1801 | # was gathered into one list first, a copy of all of them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1802 | 3 | my ( $lo, $hi ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1803 | 3 | foreach my $plot ( map { $args->{plots}[$_] } @tables ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1804 | 6 | ▶ | next unless ref $plot->{data} eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1805 | # The cells the table draws, not every cell of "data": a cell that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1806 | # "col_labels" left out stretched the shared scale, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1807 | # "default_undefined" was counted in whether or not any cell was | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1808 | # undefined. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1809 | 6 | my ( $row_keys, $cols, $cells ) = table_cells( $plot, $current_sub ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1810 | 6 | foreach my $k1 ( @{$row_keys} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1811 | 8 | ▶ | my @row = finite_values( map { $cells->{$k1}{$_} // $plot->{default_undefined} } @{$cols} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$cells->{$k1}{$_} // $plot->{"default_undefined"}
MC/DC0%0/2
$cells->{$k1}{$_} // $plot->{"default_undefined"}
$cells->{$k1}{$_}
$plot->{"default_undefined"}
Truth table66%2/3
A // B
A= $cells->{$k1}{$_}B= $plot->{"default_undefined"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1812 | 0 | ▶ | @row = grep { $_ > 0 } @row if $log; # a log scale starts above 0, as colored_table_helper's does | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1813 | 8 | ▶ | next if scalar @row == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1814 | 8 | my ( $row_lo, $row_hi ) = ( min(@row), max(@row) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1815 | 8 | ▶ | $lo = $row_lo if ( not defined $lo ) || ( $row_lo < $lo ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $lo or $row_lo < $lo
MC/DC50%1/2
not defined $lo or $row_lo < $lo
not defined $lo
$row_lo < $lo
Truth table66%2/3
not(A) or B
A= not defined $loB= $row_lo < $lo
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1816 | 8 | ▶ | $hi = $row_hi if ( not defined $hi ) || ( $row_hi > $hi ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $hi or $row_hi > $hi
MC/DC0%0/2
not defined $hi or $row_hi > $hi
not defined $hi
$row_hi > $hi
Truth table66%2/3
not(A) or B
A= not defined $hiB= $row_hi > $hi
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1817 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1818 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1819 | 3 | ▶ | return if not defined $lo; # each table refuses an empty one by name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1820 | 3 | foreach my $plot ( map { $args->{plots}[$_] } @tables ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1821 | 6 | ▶ | $plot->{cb_min} = $plot->{cb_min} // $lo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$plot->{"cb_min"} // $lo
MC/DC0%0/2
$plot->{"cb_min"} // $lo
$plot->{"cb_min"}
$lo
Truth table33%1/3
A // B
A= $plot->{"cb_min"}B= $lo
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1822 | 6 | ▶ | $plot->{cb_max} = $plot->{cb_max} // $hi; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$plot->{"cb_max"} // $hi
MC/DC0%0/2
$plot->{"cb_max"} // $hi
$plot->{"cb_max"}
$hi
Truth table33%1/3
A // B
A= $plot->{"cb_max"}B= $hi
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1823 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1824 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1825 | 1224 | ▶ | sub check_add { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_add: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1826 | # Die unless an "add" option, where given, is an array of hashes, one per | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1827 | # graph. A string in it died as 'Can't use string ("1") as a HASH ref'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1828 | 1224 | my ( $add, $where ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1829 | 1224 | ▶ | return unless defined $add; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1830 | 39 | ▶ | if ( ref $add ne 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1831 | 1 | ▶ | die "\"add\"$where must be an array (of anonymous hashes), but you entered " . ( ref $add ? 'a ' . ref($add) . ' reference' : "\"$add\"" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1832 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1833 | 38 | my @not_hash = grep { ref $add->[$_] ne 'HASH' } 0 .. $#{$add}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1834 | 38 | ▶ | if ( scalar @not_hash > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1835 | 2 | die "\"add\"$where holds one HASH reference per graph, but index " . join( ', ', @not_hash ) . ' is not one'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1836 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1837 | # An "add" inside an "add" graph. The matplotlib engine draws the graphs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1838 | # of "add" and never looks inside one for more, so the inner graphs were | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1839 | # left out of the figure without a word, where gnuplot and ggplot2 refused | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1840 | # them. Every graph of a subplot goes in the one "add", so there is nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1841 | # a nested one could mean that the flat one does not say. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1842 | 36 | my @nested = grep { exists $add->[$_]{add} } 0 .. $#{$add}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1843 | 36 | ▶ | if ( scalar @nested > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1844 | 6 | die "\"add\"$where graph " . join( ', ', @nested ) . ' has an "add" of its own, which is not drawn: list every graph of the subplot in the one "add"'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1845 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1846 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1847 | # The shape of "data" each plot_type reads. plot, scatter, imshow, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1848 | # venn_proportional_area and wide are not here: each checks its own. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1849 | 24 | my %data_shape = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1850 | bar => 'hash', barh => 'hash', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1851 | colored_table => 'hash', pie => 'hash', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1852 | hexbin => 'hash of arrays', hist2d => 'hash of arrays', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1853 | boxplot => 'sets', hist => 'sets', # sets = an array of values, or a hash of them | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1854 | violin => 'sets', violinplot => 'sets', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1855 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1856 | 1172 | ▶ | sub check_data_shape { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_data_shape: called CC=15 SCAR=27.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1857 | # Die naming the plot unless its "data" has the shape its plot_type reads. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1858 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1859 | # The helpers of these types dereferenced "data" without looking, so an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1860 | # array given to bar died as "Not a HASH reference" and a hash of numbers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1861 | # given to boxplot as 'Can't use string ("1") as an ARRAY ref', neither | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1862 | # naming "data" or the plot. An "add" graph was not checked at all: with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1863 | # "data => {}" a violin wrote violinplot([]) and the script died in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1864 | # matplotlib as "IndexError: too many indices for array". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1865 | 1172 | my ( $plot, $type, $where, $sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1866 | 1172 | ▶ | my $shape = $data_shape{ $type // '' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$type // ""
MC/DC0%0/1
$type // ""
$type
Truth table50%1/2
A
A= $type
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1867 | 1172 | ▶ | return unless defined $shape; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1868 | 793 | my $data = $plot->{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1869 | 793 | ▶ | die "$sub: \"data\"$where is not defined" unless defined $data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1870 | 792 | my $ref = ref $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1871 | 792 | ▶ | if ( ( $ref eq 'ARRAY' ) && ( $shape eq 'sets' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ref eq "ARRAY" and $shape eq "sets"
MC/DC100%2/2
$ref eq "ARRAY" and $shape eq "sets"
$ref eq "ARRAY"
$shape eq "sets"
Truth table100%3/3
A and B
A= $ref eq "ARRAY"B= $shape eq "sets"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1872 | 43 | ▶ | die "$sub: \"data\"$where is an empty array" if scalar @{$data} == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1873 | 42 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1874 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1875 | 749 | ▶ | if ( $ref ne 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1876 | 9 | ▶ | my $wanted = ( $shape eq 'sets' ) ? 'an array of values, or a hash of them,' : "a $shape"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1877 | 9 | ▶ | die "$sub: \"data\"$where must be $wanted for $type, not " . ( $ref ? ( $ref eq 'ARRAY' ? 'an' : 'a' ) . " $ref reference" : "\"$data\"" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1878 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1879 | 740 | ▶ | die "$sub: \"data\"$where is an empty hash" if scalar keys %{$data} == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1880 | 739 | ▶ | return if $shape eq 'hash'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1881 | 304 | my @not_array = grep { ref $data->{$_} ne 'ARRAY' } sort keys %{$data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1882 | 304 | ▶ | if ( scalar @not_array > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1883 | die "$sub: each key of \"data\"$where is an array of values for $type, but " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1884 | 6 | ▶ | . join( ', ', map { "\"$_\"" } @not_array ) . ( scalar @not_array == 1 ? ' is' : ' are' ) . ' not'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1885 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1886 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1887 | # The pyplot functions that act on the whole figure rather than on the current | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1888 | # axes, and so mean the same at the top of a figure of several subplots as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1889 | # anywhere. Every other one -- "title", "xscale", "ylim", "legend" -- acts on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1890 | # whichever axes is current, which there is the last subplot drawn. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1891 | 24 | my %figure_pyplot = map { $_ => 1 } qw(draw figimage figlegend figtext pause savefig set_loglevel show subplots_adjust suptitle tight_layout); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1892 | 90 | ▶ | sub refuse_figure_keywords { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
refuse_figure_keywords: called CC=13 SCAR=25.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1893 | # Die naming each keyword at the top of a figure of several subplots that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1894 | # would not reach the subplots it seems to be about. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1895 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1896 | # The top level was checked against every plot type's options, then only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1897 | # the figure's ("fig.") methods, pyplot's and a few of plt's own were | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1898 | # written. A "color", "cmap", "set_xlabel" or "add" there was accepted and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1899 | # dropped; a pyplot "title" or "xscale" was written as plt.title(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1900 | # landing on the last subplot and replacing that subplot's own title. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1901 | 90 | my ( $args, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1902 | 90 | my %plot_arg = map { $_ => 1 } ( 'add', 'cmap', 'plot', 'twinx' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1903 | 90 | my %plt_method = map { $_ => 1 } @plt_methods; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1904 | 90 | my %fig_method = map { $_ => 1 } @fig_methods; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1905 | 90 | my @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1906 | 90 | foreach my $key ( sort keys %{$args} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1907 | 521 | ▶ | next if $fig_method{$key} || $figure_pyplot{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$fig_method{$key} or $figure_pyplot{$key}
MC/DC100%2/2
$fig_method{$key} or $figure_pyplot{$key}
$fig_method{$key}
$figure_pyplot{$key}
Truth table100%3/3
A or B
A= $fig_method{$key}B= $figure_pyplot{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1908 | 507 | ▶ | next if grep { $_ eq $key } ( 'sharex', 'sharey', @plt_arg ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1909 | 456 | ▶ | next if ( $key eq 'cbpad' ) && ( defined $args->{shared_colorbar} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "cbpad" and defined $args->{"shared_colorbar"}
MC/DC0%0/2
$key eq "cbpad" and defined $args->{"shared_colorbar"}
$key eq "cbpad"
defined $args->{"shared_colorbar"}
Truth table66%2/3
A and B
A= $key eq "cbpad"B= defined $args->{"shared_colorbar"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1910 | 456 | ▶ | if ( $plt_method{$key} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1911 | 2 | ▶ | push @lines, "\"$key\" acts on one subplot, and here it would act on the last one drawn: give it in the hash of the subplot it belongs to" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1912 | . ( $key =~ m/^(?:title|xlabel|ylabel|legend)$/ ? ' ("suptitle", "supxlabel", "supylabel" and "figlegend" act on the whole figure)' : '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1913 | } elsif ( $key eq 'cbpad' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1914 | 1 | push @lines, '"cbpad" at the top of a figure only places a "shared_colorbar"; without one, give it in the hash of the subplot whose colorbar it places'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1915 | 114609 | ▶ | } elsif ( ( grep { $_ eq $key } @ax_methods, @all_opt ) || $plot_arg{$key} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
grep {$_ eq $key;} @Matplotlib::Simple::ax_methods, @all_opt or $plot_arg{$key}
MC/DC100%2/2
grep {$_ eq $key;} @Matplotlib::Simple::ax_methods, @all_opt or $plot_arg{$key}
grep {$_ eq $key;} @Matplotlib::Simple::ax_methods, @all_opt
$plot_arg{$key}
Truth table100%3/3
A or B
A= grep {$_ eq $key;} @Matplotlib::Simple::ax_methods, @all_optB= $plot_arg{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1916 | 4 | push @lines, "\"$key\" belongs to one subplot: give it in the hash of the subplot it belongs to"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1917 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1918 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1919 | 90 | ▶ | return if scalar @lines == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1920 | 7 | die "$current_sub: with \"plots\" or \"p\", these keywords at the top of the figure would not be drawn where they seem to belong: " . join( '; ', @lines ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1921 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1922 | # The engines that draw plt's figures: the value of "engine" => the module that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1923 | # draws with it, which is loaded only when a figure asks for it. matplotlib is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1924 | # the default and draws everything this module accepts. Every other engine | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1925 | # declares what it draws, and check_engine refuses the rest by name: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1926 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1927 | # our %types = ( bar => [ 'color', 'key_order', ... ], ... ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1928 | # the plot types it draws, each with the keywords of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1929 | # %opt it reads for that type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1930 | # our @plot_keywords = ( 'title', 'xlabel', ... ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1931 | # the keywords any plot it draws may carry, alone or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1932 | # in a subplot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1933 | # our @figure_keywords = ( 'suptitle', 'scale', ... ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1934 | # the keywords of the figure as a whole, at the top | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1935 | # level of a single plot or of "plots" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1936 | # sub render { my ( $args, $context ) = @_; ... } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1937 | # as Matplotlib::Simple::Matplotlib::render, which documents | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1938 | # what it is given; returns the script's path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1939 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1940 | # Each engine draws both styles (%styles); render finds the one asked for in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1941 | # $context->{style}. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1942 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1943 | # Matplotlib::Simple::Matplotlib instead sets $draws_everything, and is not checked. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1944 | 24 | our %engine_module = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1945 | ggplot2 => 'Matplotlib::Simple::Ggplot2', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1946 | gnuplot => 'Matplotlib::Simple::Gnuplot', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1947 | matplotlib => 'Matplotlib::Simple::Matplotlib', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1948 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1949 | 24 | my $default_engine = 'matplotlib'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1950 | 1048 | ▶ | sub engine_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
engine_name: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1951 | # The engine a figure asked for, "matplotlib" if it asked for none, with its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1952 | # module loaded; "engine" itself is taken out of the arguments, so that no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1953 | # engine's own keyword checks meet it. Dies naming the engines there are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1954 | # for any other value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1955 | 1048 | my ( $args, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1956 | 1048 | my $engine = delete $args->{engine}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1957 | 1048 | ▶ | $engine = $default_engine unless defined $engine; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1958 | 1048 | ▶ | if ( ( ref $engine ) || ( not defined $engine_module{$engine} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $engine or not defined $Matplotlib::Simple::engine_module{$engine}
MC/DC100%2/2
ref $engine or not defined $Matplotlib::Simple::engine_module{$engine}
ref $engine
not defined $Matplotlib::Simple::engine_module{$engine}
Truth table100%3/3
A or not(B)
A= ref $engineB= not defined $Matplotlib::Simple::engine_module{$engine}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1959 | 2 | ▶ | my $got = ref $engine ? 'a ' . ( ref $engine ) . ' reference' : "\"$engine\""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1960 | 2 | die "$current_sub: \"engine\" is one of " . join( ', ', map { "\"$_\"" } sort keys %engine_module ) . ", not $got"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1961 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1962 | 1046 | ( my $file = "$engine_module{$engine}.pm" ) =~ s{::}{/}g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1963 | 1046 | require $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1964 | 1046 | return $engine; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1965 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1966 | # How the figure looks: the value of "style" => what it means. The default, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1967 | # "native", matches the engine: it lets the engine choose for itself its own | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1968 | # palette and default colormap, its own statistics where it has a function for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1969 | # them, its own theme and legend placement. "matplotlib" has every engine draw | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1970 | # what matplotlib draws -- its colors and colormaps, its binning, quartiles and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1971 | # densities, computed in Perl as numpy and scipy compute them, and its layout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1972 | # -- so that changing "engine" changes the renderer and not the figure. What | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1973 | # the caller gave is drawn either way: the data, the key order, a "color" or a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1974 | # "cmap", the labels, limits, log scales and the size. matplotlib draws the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1975 | # same figure for both, its native look being matplotlib's. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1976 | 24 | our %styles = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1977 | matplotlib => 'what matplotlib draws, whichever engine draws it', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1978 | native => "the engine's own palette, statistics and theme", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1979 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1980 | 24 | my $default_style = 'native'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1981 | 1046 | ▶ | sub style_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
style_name: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1982 | # The style a figure asked for, "native" if it asked for none; "style" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1983 | # is taken out of the arguments, as "engine" is by engine_name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1984 | 1046 | my ( $args, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1985 | 1046 | my $style = delete $args->{style}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1986 | 1046 | ▶ | $style = $default_style unless defined $style; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1987 | 1046 | ▶ | if ( ( ref $style ) || ( not defined $styles{$style} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $style or not defined $Matplotlib::Simple::styles{$style}
MC/DC50%1/2
ref $style or not defined $Matplotlib::Simple::styles{$style}
ref $style
not defined $Matplotlib::Simple::styles{$style}
Truth table66%2/3
A or not(B)
A= ref $styleB= not defined $Matplotlib::Simple::styles{$style}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1988 | 2 | ▶ | my $got = ref $style ? 'a ' . ( ref $style ) . ' reference' : "\"$style\""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1989 | 2 | die "$current_sub: \"style\" is one of " . join( '; ', map { "\"$_\", $styles{$_}" } sort keys %styles ) . "; not $got"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1990 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1991 | 1044 | return $style; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1992 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1993 | 1190 | ▶ | sub refuse_subplot_choices { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
refuse_subplot_choices: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1994 | # Die if a subplot, or an "add" graph, gives a choice that belongs to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1995 | # whole figure. One engine draws the whole figure in one style, and one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1996 | # script is written, to one file, and run or not; each is given once, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1997 | # beside "plots" or "p". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1998 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1999 | # "execute" and "fh" in a subplot or an "add" graph, and "output_file" in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2000 | # an "add" graph, were accepted and never read. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2001 | 1190 | my ( $args, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2002 | 1190 | my %why = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2003 | engine => 'one engine draws the whole figure in one style', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2004 | style => 'one engine draws the whole figure in one style', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2005 | execute => 'the figure is one script, which is run or not', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2006 | fh => 'the figure is one script, written to one file', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2007 | output_file => 'the figure is saved to one file', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2008 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2009 | 1190 | ▶ | my @plots = ( $args, @{ ( ref $args->{plots} eq 'ARRAY' ) ? $args->{plots} : [] } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2010 | 1190 | foreach my $i ( 0 .. $#plots ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2011 | 1381 | my $plot = $plots[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2012 | 1381 | ▶ | next unless ref $plot eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2013 | 1380 | ▶ | my $where = ( $i == 0 ) ? '' : ' at subplot ' . ( $i - 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2014 | 1380 | foreach my $choice ( sort keys %why ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2015 | 6870 | ▶ | if ( ( $i > 0 ) && ( exists $plot->{$choice} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$i > 0 and exists $plot->{$choice}
MC/DC100%2/2
$i > 0 and exists $plot->{$choice}
$i > 0
exists $plot->{$choice}
Truth table100%3/3
A and B
A= $i > 0B= exists $plot->{$choice}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2016 | 7 | die "$current_sub: \"$choice\"$where: $why{$choice}, so give \"$choice\" once, beside \"plots\" or \"p\""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2017 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2018 | 6863 | ▶ | next unless ref $plot->{add} eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2019 | 234 | ▶ | if ( grep { ( ref $_ eq 'HASH' ) && ( exists $_->{$choice} ) } @{ $plot->{add} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $_ eq 'HASH' && exists $_->{$choice}
MC/DC100%2/2
ref $_ eq 'HASH' && exists $_->{$choice}
ref $_ eq 'HASH'
exists $_->{$choice}
Truth table100%3/3
A && B
A= ref $_ eq 'HASH'B= exists $_->{$choice}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2020 | 8 | die "$current_sub: \"$choice\" in an \"add\" graph$where: $why{$choice}, so give \"$choice\" once, at the top level"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2021 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2022 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2023 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2024 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2025 | 1044 | ▶ | sub check_engine { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_engine: called CC=19 SCAR=29.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2026 | # Die unless the engine draws every plot type and reads every keyword the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2027 | # figure asks for, naming each one it does not, and what it does draw. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2028 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2029 | # An engine that met a keyword it had no counterpart for could only leave | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2030 | # it out, and a figure missing its error bars, or drawn with a different | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2031 | # kind of color scale, looks right to someone who did not know to look. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2032 | # matplotlib draws all of it, so the message says so. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2033 | 1044 | my ( $engine, $args, $single_plot, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2034 | 1044 | my $module = $engine_module{$engine}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2035 | 24 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2036 | 1044 | ▶ | return if ${"${module}::draws_everything"}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2037 | 381 | my %types = %{"${module}::types"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2038 | 381 | my %plot_kw = map { $_ => 1 } @{"${module}::plot_keywords"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2039 | 381 | my %figure_kw = map { $_ => 1 } ( @{"${module}::figure_keywords"}, 'execute', 'fh', 'output_file' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2040 | 381 | my %grid_kw = map { $_ => 1 } ( 'ncol', 'ncols', 'nrow', 'nrows', 'plots' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2041 | # Keywords given with the value that asks for nothing, which no engine has | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2042 | # to draw, and which are left out of the list of what it draws: "show => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2043 | # 0", which a program for matplotlib may pass, was refused, so that it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2044 | # could not change "engine" without dropping it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2045 | 381 | my %asks_nothing = ( show => !$args->{show} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2046 | 381 | my ( @lines, %listed ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2047 | 30 | ▶ | my $refuse_keys = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2048 | 30 | my ( $bad, $what ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2049 | 30 | ▶ | return if scalar @{$bad} == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2050 | 20 | push @lines, join( ', ', map { "\"$_\"" } @{$bad} ) . $what; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2051 | 381 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2052 | 381 | ▶ | if ( $single_plot == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2053 | 15 | ▶ | $refuse_keys->( [ grep { ( not $figure_kw{$_} ) && ( not $grid_kw{$_} ) && ( not $asks_nothing{$_} ) } sort keys %{$args} ], ' for the figure' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$figure_kw{$_} || $grid_kw{$_} || $asks_nothing{$_}
$figure_kw{$_} or $grid_kw{$_}
MC/DC100%3/3
$figure_kw{$_} || $grid_kw{$_} || $asks_nothing{$_}
$figure_kw{$_}
$grid_kw{$_}
$asks_nothing{$_}
Truth table100%4/4
A or B || C
A= $figure_kw{$_}B= $grid_kw{$_}C= $asks_nothing{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2054 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2055 | 381 | ▶ | my @drawn = ( $single_plot == 1 ) ? ( [ $args, '' ] ) : map { [ $args->{plots}[$_], " at subplot $_" ] } 0 .. $#{ $args->{plots} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2056 | 381 | foreach my $drawn (@drawn) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2057 | 395 | my ( $plot, $at ) = @{$drawn}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2058 | 395 | ▶ | foreach my $graph ( $plot, @{ $plot->{add} // [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$plot->{"add"} // []
MC/DC100%1/1
$plot->{"add"} // []
$plot->{"add"}
Truth table100%2/2
A
A= $plot->{"add"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2059 | 404 | ▶ | my $where = ( $graph == $plot ) ? $at : " for an \"add\" graph$at"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2060 | 404 | my $type = $graph->{plot_type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2061 | 404 | ▶ | if ( not defined $types{$type} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2062 | 7 | push @lines, "plot_type \"$type\"$where"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2063 | 7 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2064 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2065 | 397 | my %ok = ( %plot_kw, map { $_ => 1 } ( @{ $types{$type} }, 'data', 'plot_type' ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2066 | 397 | ▶ | if ( $graph == $plot ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2067 | 389 | $ok{add} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2068 | 389 | ▶ | %ok = ( %ok, %figure_kw, %grid_kw ) if $single_plot == 1; # plt sets "nrows" and "ncols" to 1 for a single plot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2069 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2070 | 397 | ▶ | my @bad = grep { ( not $ok{$_} ) && ( ( $graph != $args ) || ( not $asks_nothing{$_} ) ) } sort keys %{$graph}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
!$ok{$_} && ($graph != $args || !$asks_nothing{$_})
$graph != $args or not $asks_nothing{$_}
MC/DC66%2/3
!$ok{$_} && ($graph != $args || !$asks_nothing{$_})
!$ok{$_}
$graph != $args
not $asks_nothing{$_}
Truth table75%3/4
not(A) && B or not(C)
A= !$ok{$_}B= $graph != $argsC= not $asks_nothing{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2071 | 397 | ▶ | next if scalar @bad == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2072 | 15 | $refuse_keys->( \@bad, " for plot_type \"$type\"$where" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2073 | 15 | $listed{$type} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2074 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2075 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2076 | 381 | ▶ | return if scalar @lines == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2077 | 27 | ▶ | my @types_drawn = map { "$_ (" . ( join( ', ', @{ $types{$_} } ) || 'nothing of its own' ) . ')' } sort keys %listed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
join(', ', @{$types{$_};}) || 'nothing of its own'
MC/DC0%0/1
join(', ', @{$types{$_};}) || 'nothing of its own'
join(', ', @{$types{$_};})
Truth table50%1/2
A
A= join(', ', @{$types{$_};})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2078 | 27 | ▶ | die "$current_sub: the $engine engine does not draw " . join( '; ', @lines ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2079 | . ". It draws the plot types " . join( ', ', sort keys %types ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2080 | . ( scalar @types_drawn ? ', with these keywords of their own: ' . join( '; ', @types_drawn ) : '' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2081 | . '; and at any plot: ' . join( ', ', sort keys %plot_kw ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2082 | . '; and for the figure: ' . join( ', ', sort keys %figure_kw ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2083 | . ". engine => 'matplotlib', the default, draws all of it"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2084 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2085 | 24 | my $n_scripts = 0; # scripts this process has named, for script_handle | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2086 | 963 | ▶ | sub script_handle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
script_handle: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2087 | # The file an engine writes its script into, given a UTF-8 layer: the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2088 | # caller's "fh", or a new temporary file with the engine's suffix. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2089 | 963 | my ( $args, $suffix, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2090 | 963 | my $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2091 | 963 | ▶ | if ( defined $args->{fh} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2092 | 7 | my $ref = ref $args->{fh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2093 | 7 | ▶ | if ($ref ne 'File::Temp') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2094 | 0 | p $args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2095 | 0 | die "$current_sub received a \"$ref\" for \"fh\", which isn't a \"File::Temp\" object."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2096 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2097 | 7 | $fh = $args->{fh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2098 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2099 | # File::Spec->tmpdir(), not a literal "/tmp": on MSWin32 there is no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2100 | # /tmp, and File::Temp dies with "Parent directory (\tmp\) does not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2101 | # exist" (CPAN Testers FAIL for 0.312 on Strawberry perl 5.42.2). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2102 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2103 | # The process, the time and a count lead the name, ahead of the X's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2104 | # File::Temp fills from rand(). The scripts are kept, and a caller who | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2105 | # seeds rand() with a fixed "srand 7" got the same names on every run, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2106 | # each run stepping past the scripts the runs before it had left, until | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2107 | # File::Temp gave up: "Have exceeded the maximum number of attempts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2108 | # (1000) to open temp file". Reseeding here would have cured it at the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2109 | # price of the caller's own sequence, which a fixed seed is there to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2110 | # keep. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2111 | 956 | $fh = File::Temp->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2112 | DIR => File::Spec->tmpdir, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2113 | TEMPLATE => sprintf( 'matplotlib-simple-%d-%d-%d-XXXXXX', $$, time, $n_scripts++ ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2114 | SUFFIX => $suffix, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2115 | UNLINK => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2116 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2118 | # Non-ASCII key names (e.g. Greek letters like ρ, τ) arrive as wide | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2119 | # characters when the caller has "use utf8", so give the output filehandle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2120 | # a UTF-8 encoding layer. Without it, "say $fh" dies with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2121 | # "Wide character in say" under this module's "warnings FATAL => 'all'". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2122 | # Only add the layer if it isn't already present, to avoid double-encoding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2123 | # a filehandle that was passed in. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2124 | 963 | ▶ | unless ( grep { /utf-?8/i } PerlIO::get_layers($fh) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2125 | # Checked by hand because this module does not "use autodie" (see | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2126 | # CLAUDE.md): binmode reports failure by returning undef, and an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2127 | # unchecked failure here would stay silent until the first wide | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2128 | # character reached the file and died as "Wide character in say". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2129 | # The message is autodie's own, which read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2130 | # "Can't binmode($fh, ':encoding(UTF-8)'): Bad file descriptor". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2131 | 960 | ▶ | binmode( $fh, ':encoding(UTF-8)' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2132 | or die "Can't binmode(" . $fh->filename . ", ':encoding(UTF-8)'): $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2134 | 963 | say 'temp file is ' . $fh->filename; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2135 | 963 | return $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2137 | 7 | ▶ | sub run_script { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_script: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2138 | # Run a command, the engine's interpreter and its script, and print what | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2139 | # it printed; die with what it printed if it fails. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2140 | 7 | my ($command) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2141 | 7 | my $errno; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2142 | 7 | ▶ | my ($stdout, $stderr, $exit) = capture { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2143 | # The list form, not "python3 $file": the one-argument form goes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2144 | # through the shell and splits on whitespace, so a temp directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2145 | # with a space in it -- %TEMP% on a Windows smoker sits under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2146 | # C:\Users\<name>, and a user name with a space is ordinary -- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2147 | # would run python against a truncated path. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2148 | # Departs from this file's "warnings FATAL => 'all'" on purpose, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2149 | # for this statement only: with exec warnings fatal, a missing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2150 | # interpreter dies right here as "Can't exec "python3"", system() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2151 | # never returns, and the three failure modes below get reported | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2152 | # two different ways. autodie raised all three as one kind of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2153 | # exception naming the command, which is what this restores. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2154 | 24 | ▶ | no warnings 'exec'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2155 | 7 | my $status = system( @{$command} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2156 | # Read here, not after capture(): capture() does its own file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2157 | # operations on the way out and they overwrite $!, which was | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2158 | # observed to leave "failed to start:" with nothing after it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2159 | 7 | $errno = "$!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2160 | 7 | $status; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2161 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2162 | 7 | ▶ | if ($exit != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2163 | 3 | say STDERR "STDOUT = $stdout"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2164 | 3 | say STDERR "STDERR = $stderr"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2165 | # The three ways system() reports failure, told apart because | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2166 | # they call for different fixes: no interpreter, a killed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2167 | # process, and an error in the script. "use autodie" used to raise | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2168 | # these through IPC::System::Simple, but it threw from inside | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2169 | # capture(), so the two lines above -- the python traceback, the only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2170 | # thing that says what is actually wrong -- were never reached. See | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2171 | # CLAUDE.md. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2172 | 3 | my $why; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2173 | 3 | ▶ | if ( $exit == -1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2174 | 1 | $why = "failed to start: $errno"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2175 | } elsif ( $exit & 127 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2176 | 0 | $why = 'died to signal ' . ( $exit & 127 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2177 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2178 | 2 | $why = 'unexpectedly returned exit value ' . ( $exit >> 8 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2180 | 3 | die join( ' ', @{$command} ) . " $why"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2182 | # What the script printed, which capture{} above took out of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2183 | # terminal. The script reports things the caller has no other way to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2184 | # learn -- the range of a hist's bin heights, a hist2d's density range, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2185 | # both computed by matplotlib as it draws -- and those lines were | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2186 | # captured and then dropped on the floor on every successful run, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2187 | # only a *failing* run ever showed them. Already newline-terminated by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2188 | # the interpreter, hence print and not say. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2189 | 4 | ▶ | print $stdout if length $stdout; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2190 | # What it wrote to STDERR, which a successful run does not show: the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2191 | # gnuplot engine reads gnuplot's version from it for the creator note. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2192 | 4 | return $stderr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2194 | 31 | ▶ | sub program_from_env { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
program_from_env: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2195 | # The first of these environment variables that is set and not empty, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2196 | # taken whole -- a path such as "C:\Program Files\gnuplot\bin\gnuplot.exe" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2197 | # has spaces in it, and is not split on them -- or undef if none is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2198 | 31 | foreach my $name (@_) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2199 | 31 | ▶ | return $ENV{$name} if ( defined $ENV{$name} ) && ( $ENV{$name} ne '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $ENV{$name} and $ENV{$name} ne ""
MC/DC100%2/2
defined $ENV{$name} and $ENV{$name} ne ""
defined $ENV{$name}
$ENV{$name} ne ""
Truth table100%3/3
A and B
A= defined $ENV{$name}B= $ENV{$name} ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2201 | 27 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2203 | 1074 | ▶ | sub creator_note { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
creator_note: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2204 | # Where a figure came from, for the note an engine leaves in the file it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2205 | # writes: the script that called plt, the call, this module and Perl. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2206 | # engine adds its own name and version, and the user and the host, which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2207 | # its script reads as it runs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2208 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2209 | # The script's own directory, not the working directory: run from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2210 | # elsewhere, "perl dir/plot.pl" was noted as "<cwd>/plot.pl", and from / | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2211 | # as "//plot.pl". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2212 | 1074 | my ($current_sub) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2213 | return File::Spec->catfile( $RealBin, $RealScript ) . " called using \"$current_sub\" in " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2214 | 1074 | ▶ | . ( $INC{'Matplotlib/Simple.pm'} // __FILE__ ) . " version $VERSION with Perl " . sprintf( '%vd', $^V ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$INC{"Matplotlib/Simple.pm"} // __FILE__
MC/DC0%0/1
$INC{"Matplotlib/Simple.pm"} // __FILE__
$INC{"Matplotlib/Simple.pm"}
Truth table50%1/2
A
A= $INC{"Matplotlib/Simple.pm"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2216 | 176 | ▶ | sub svg_creator_metadata { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
svg_creator_metadata: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2217 | # The <metadata> an SVG from matplotlib carries its Creator note in, as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2218 | # two strings: what comes before the note, which must be XML-escaped | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2219 | # already, and what comes after. Laid out as matplotlib 3.11.2 writes it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2220 | # (backend_svg._write_metadata), so that a figure from any engine keeps its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2221 | # note in the one place, <dc:creator><cc:Agent><dc:title>. Each starts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2222 | # on a new line, to follow the <svg ...> tag it goes after. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2223 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2224 | 176 | "\n <metadata>\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2225 | . ' <rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">' . "\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2226 | . " <cc:Work>\n <dc:creator>\n <cc:Agent>\n <dc:title>", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2227 | "</dc:title>\n </cc:Agent>\n </dc:creator>\n </cc:Work>\n </rdf:RDF>\n </metadata>" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2228 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2230 | # What the engines other than matplotlib read the keywords as. The keywords | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2231 | # are matplotlib's, and so are the conventions of their values: text may be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2232 | # Python of the caller's own (quote_text in Matplotlib::Simple::Matplotlib), a color is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2233 | # one of matplotlib's names, an axis range is the arguments of set_xlim. These | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2234 | # turn each into something any engine can write, and refuse what has no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2235 | # meaning outside matplotlib by name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2236 | 70 | ▶ | sub plain_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
plain_text: called CC=15 SCAR=27.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2237 | # A title or a label as the text it shows. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2238 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2239 | # Text that quote_text would leave as Python is read as Python: a string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2240 | # literal, which may carry an r, u or b prefix, is its contents, escapes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2241 | # and all, so "xlabel => py_str($column)" from frame_to_data and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2242 | # "title => '\"Two groups, mean and s.d.\"'" both come out as the words. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2243 | # A literal followed by keyword arguments, such as "fontsize = 20", or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2244 | # keyword arguments alone, are matplotlib's, and are refused. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2245 | 70 | my ( $text, $option, $engine, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2246 | 70 | $text = decoded_text($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2247 | 70 | ▶ | return $text if $text =~ m/^([^\"\',]+)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2248 | 47 | ▶ | if ( $text =~ m/^\s*([rRbBuUfF]{0,2})(['"])((?:\\.|(?!\2)[^\\])*)\2\s*(,.*)?$/s ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2249 | 21 | my ( $prefix, $body, $rest ) = ( lc $1, $3, $4 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2250 | 21 | ▶ | if ( ( defined $rest ) && ( $rest !~ m/^,\s*$/ ) ) { # a trailing comma alone is still one argument to Python | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $rest and not $rest =~ /^,\s*$/
MC/DC100%2/2
defined $rest and not $rest =~ /^,\s*$/
defined $rest
not $rest =~ /^,\s*$/
Truth table100%3/3
A and not(B)
A= defined $restB= not $rest =~ /^,\s*$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2251 | 3 | die "$current_sub: \"$option\" is given matplotlib's arguments$rest after its text; the $engine engine takes the text alone"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2253 | 18 | ▶ | if ( $prefix =~ m/f/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2254 | 3 | die "$current_sub: \"$option\" is a Python f-string, which only matplotlib's Python can fill in; give the $engine engine the text as it should read"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2256 | 15 | ▶ | return $body if $prefix =~ m/r/; # a raw string keeps its backslashes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2257 | # Python's escapes, as its lexical analysis lists them: octal of one to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2258 | # three digits, which "\0" alone stood for, so that "\012" was a NUL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2259 | # and "12"; and a character by its Unicode name, \N{...}, which Python | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2260 | # matches without regard to case. One Python does not know is left as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2261 | # written, as Python leaves an unknown escape. The braces of \N{...} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2262 | # are written [{] and [}], not \{ and \}: inside s{}{} perl 5.18 reads | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2263 | # \{ as a useless escape and warns, which FATAL warnings made a failure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2264 | # to compile. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2265 | 14 | my %escape = ( n => "\n", t => "\t", r => "\r", a => "\a", b => "\b", f => "\f", v => "\x0b", "\\" => "\\", "'" => "'", '"' => '"', "\n" => '' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2266 | 14 | require charnames; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2267 | 14 | $body =~ s{\\(?:x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4})|U([0-9a-fA-F]{8})|([0-7]{1,3})|N[{]([^{}]+)[}]|(.))}{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2268 | defined $1 ? chr hex $1 : defined $2 ? chr hex $2 : defined $3 ? chr hex $3 : defined $4 ? chr oct $4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2269 | : defined $5 ? ( defined charnames::vianame( uc $5 ) ? chr charnames::vianame( uc $5 ) : "\\N{$5}" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2270 | 15 | ▶ | : exists $escape{$6} ? $escape{$6} : "\\$6" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2271 | }gse; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2272 | 14 | return $body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2274 | 26 | ▶ | if ( $text =~ m/^\s*[A-Za-z_]\w*\s*=[^=]/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2275 | 2 | die "$current_sub: \"$option\" is given as matplotlib's keyword arguments, \"$text\"; the $engine engine takes the text alone"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2277 | 24 | return $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2279 | 15 | ▶ | sub axis_limits { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
axis_limits: called CC=14 SCAR=26.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2280 | # The two ends of an axis range given as set_xlim's arguments -- "0, 10", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2281 | # "(0, 10)" or [ 0, 10 ] -- as ( $lo, $hi ), either undef for None, which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2282 | # leaves that end where the engine puts it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2283 | 15 | my ( $value, $option, $engine, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2284 | 15 | my @ends; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2285 | 15 | ▶ | if ( ref $value eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2286 | 2 | @ends = @{$value}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2287 | } elsif ( not ref $value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2288 | 13 | ▶ | ( my $inner = $value // '' ) =~ s/^\s*[\(\[]\s*(.*?)\s*[\)\]]\s*$/$1/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$value // ""
MC/DC0%0/1
$value // ""
$value
Truth table50%1/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2289 | 13 | @ends = map { ( my $end = $_ ) =~ s/^\s+|\s+$//g; $end } split /,/, $inner, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2291 | 15 | ▶ | if ( ( scalar @ends == 2 ) && ( not grep { ( defined $_ ) && ( $_ ne 'None' ) && ( ( not looks_like_number($_) ) || ( not is_finite($_) ) ) } @ends ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%10/12
scalar @ends == 2 and not grep({defined $_ and $_ ne "None" and not &looks_like_number($_) && is_finite($_);} @ends)
defined $_ && $_ ne 'None' && !(&looks_like_number($_) && is_finite($_))
defined $_ and $_ ne "None"
&looks_like_number($_) && is_finite($_)
MC/DC100%2/2
scalar @ends == 2 and not grep({defined $_ and $_ ne "None" and not &looks_like_number($_) && is_finite($_);} @ends)
scalar @ends == 2
not grep({defined $_ and $_ ne "None" and not &looks_like_number($_) && is_finite($_);} @ends)
MC/DC50%2/4
defined $_ && $_ ne 'None' && !(&looks_like_number($_) && is_finite($_))
defined $_
$_ ne "None"
&looks_like_number($_)
is_finite($_)
Truth table100%3/3
A and not(B)
A= scalar @ends == 2B= not grep({defined $_ and $_ ne "None" and not &looks_like_number($_) && is_finite($_);} @ends)
Truth table60%3/5
A and B && not(C && D)
A= defined $_B= $_ ne "None"C= &looks_like_number($_)D= is_finite($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2292 | 9 | ▶ | return map { ( ( not defined $_ ) || ( $_ eq 'None' ) ) ? undef : 0 + $_ } @ends; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $_ or $_ eq "None"
MC/DC50%1/2
not defined $_ or $_ eq "None"
not defined $_
$_ eq "None"
Truth table66%2/3
not(A) or B
A= not defined $_B= $_ eq "None"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2294 | 6 | ▶ | my $got = ref $value ? 'a ' . ( ref $value ) . ' reference' . ( ref $value eq 'ARRAY' ? ' of ' . scalar( @{$value} ) : '' ) : '"' . ( $value // 'undef' ) . '"'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
$value // "undef"
MC/DC0%0/1
$value // "undef"
$value
Truth table50%1/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2295 | 6 | die "$current_sub: \"$option\" is two finite numbers for the $engine engine, the bottom and the top of the axis, such as \"0, 10\" or [ 0, 10 ], with None for an end left where it falls; not $got"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2297 | 8 | ▶ | sub axis_scale { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
axis_scale: called CC=7 SCAR=20.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2298 | # "log" or "linear" from an "xscale", "yscale", "set_xscale" or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2299 | # "set_yscale", quoted or not. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2300 | 8 | my ( $value, $option, $engine, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2301 | 8 | ▶ | my $scale = ( ref $value ) ? '' : ( $value // '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$value // ""
MC/DC0%0/1
$value // ""
$value
Truth table50%1/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2302 | 8 | $scale =~ s/^\s*(['"]?)(\w+)\1\s*$/$2/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2303 | 8 | ▶ | return $scale if ( $scale eq 'log' ) || ( $scale eq 'linear' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$scale eq "log" or $scale eq "linear"
MC/DC100%2/2
$scale eq "log" or $scale eq "linear"
$scale eq "log"
$scale eq "linear"
Truth table100%3/3
A or B
A= $scale eq "log"B= $scale eq "linear"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2304 | 1 | ▶ | die "$current_sub: \"$option\" is \"log\" or \"linear\" for the $engine engine, not \"" . ( ref $value ? ref $value : $value // 'undef' ) . '"'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$value // "undef"
MC/DC0%0/1
$value // "undef"
$value
Truth table50%1/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2306 | 275 | ▶ | sub color_hex { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
color_hex: called CC=27 SCAR=33.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2307 | # A matplotlib color as "#rrggbb", or "#rrggbbaa" where it has an alpha | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2308 | # below 1: one of matplotlib's names (Matplotlib::Simple::Colors), a hex code, a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2309 | # gray level from "0" to "1", or an RGB or RGBA tuple of numbers from 0 to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2310 | # 1, as an array or as Python. The names are matplotlib's because gnuplot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2311 | # and R each have their own lists, which differ from it and from each other. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2312 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2313 | # A NaN channel is neither below 0 nor above 1, and came out as "#NaN8080". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2314 | 275 | my ( $color, $option, $engine, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2315 | 275 | require Matplotlib::Simple::Colors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2316 | 24 | ▶ | my $named = do { no warnings 'once'; \%Matplotlib::Simple::Colors::named }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2317 | 275 | my @channels; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2318 | 275 | ▶ | if ( ref $color eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2319 | 10 | @channels = @{$color}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2320 | ▶ | } elsif ( ( defined $color ) && ( not ref $color ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $color and not ref $color
MC/DC0%0/2
defined $color and not ref $color
defined $color
not ref $color
Truth table33%1/3
A and not(B)
A= defined $colorB= not ref $color
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2321 | 265 | ( my $name = $color ) =~ s/^\s*(['"]?)(.*?)\1\s*$/$2/s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2322 | 265 | ▶ | return $named->{$name} if defined $named->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2323 | 20 | ▶ | return $named->{ lc $name } if defined $named->{ lc $name }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2324 | 19 | ▶ | if ( $name =~ m/^#([0-9a-fA-F]{3,4})$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2325 | 1 | my $hex = lc join '', map { $_ x 2 } split //, $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2326 | 1 | ▶ | return '#' . ( ( $hex =~ m/ff$/ ) && ( length $hex == 8 ) ? substr( $hex, 0, 6 ) : $hex ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$hex =~ /ff$/ and length $hex == 8
MC/DC0%0/2
$hex =~ /ff$/ and length $hex == 8
$hex =~ /ff$/
length $hex == 8
Truth table33%1/3
A and B
A= $hex =~ /ff$/B= length $hex == 8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2328 | 18 | ▶ | if ( $name =~ m/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2329 | 8 | my $hex = lc $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2330 | 8 | ▶ | return '#' . ( ( $hex =~ m/ff$/ ) && ( length $hex == 8 ) ? substr( $hex, 0, 6 ) : $hex ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$hex =~ /ff$/ and length $hex == 8
MC/DC50%1/2
$hex =~ /ff$/ and length $hex == 8
$hex =~ /ff$/
length $hex == 8
Truth table66%2/3
A and B
A= $hex =~ /ff$/B= length $hex == 8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2332 | 10 | ▶ | if ( ( looks_like_number($name) ) && ( $name >= 0 ) && ( $name <= 1 ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition83%5/6
&looks_like_number($name) and $name >= 0 and $name <= 1
&looks_like_number($name) and $name >= 0
MC/DC66%2/3
&looks_like_number($name) and $name >= 0 and $name <= 1
&looks_like_number($name)
$name >= 0
$name <= 1
Truth table75%3/4
A and B and C
A= &looks_like_number($name)B= $name >= 0C= $name <= 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2333 | 2 | @channels = ( $name, $name, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2334 | } elsif ( $name =~ m/^\s*[\(\[](.*)[\)\]]\s*$/s ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2335 | 3 | @channels = map { ( my $channel = $_ ) =~ s/^\s+|\s+$//g; $channel } split /,/, $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2338 | 20 | ▶ | if ( ( ( scalar @channels == 3 ) || ( scalar @channels == 4 ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
scalar @channels == 3 || scalar @channels == 4 and not grep({not defined $_ && &looks_like_number($_) && is_finite($_) or $_ < 0 or $_ > 1;} @channels)
scalar @channels == 3 or scalar @channels == 4
MC/DC100%3/3
scalar @channels == 3 || scalar @channels == 4 and not grep({not defined $_ && &looks_like_number($_) && is_finite($_) or $_ < 0 or $_ > 1;} @channels)
scalar @channels == 3
scalar @channels == 4
not grep({not defined $_ && &looks_like_number($_) && is_finite($_) or $_ < 0 or $_ > 1;} @channels)
Truth table100%5/5
A or B and not(C)
A= scalar @channels == 3B= scalar @channels == 4C= not grep({not defined $_ && &looks_like_number($_) && is_finite($_) or $_ < 0 or $_ > 1;} @channels)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2339 | 49 | ▶ | && ( not grep { ( not defined ) || ( not looks_like_number($_) ) || ( not is_finite($_) ) || ( $_ < 0 ) || ( $_ > 1 ) } @channels ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%8/12
!(defined $_ && &looks_like_number($_) && is_finite($_)) || $_ < 0 || $_ > 1
not defined $_ && &looks_like_number($_) && is_finite($_) or $_ < 0
defined $_ && &looks_like_number($_) && is_finite($_)
defined $_ and &looks_like_number($_)
MC/DC40%2/5
!(defined $_ && &looks_like_number($_) && is_finite($_)) || $_ < 0 || $_ > 1
defined $_
&looks_like_number($_)
is_finite($_)
$_ < 0
$_ > 1
Truth table50%3/6
not(A and B && C) or D || E
A= defined $_B= &looks_like_number($_)C= is_finite($_)D= $_ < 0E= $_ > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2340 | 8 | ▶ | pop @channels if ( scalar @channels == 4 ) && ( $channels[3] == 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
scalar @channels == 4 and $channels[3] == 1
MC/DC100%2/2
scalar @channels == 4 and $channels[3] == 1
scalar @channels == 4
$channels[3] == 1
Truth table100%3/3
A and B
A= scalar @channels == 4B= $channels[3] == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2341 | 8 | return '#' . join( '', map { sprintf '%02x', int( $_ * 255 + 0.5 ) } @channels ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2343 | 12 | ▶ | my $got = ref $color ? 'a ' . ( ref $color ) . ' reference' : '"' . ( $color // 'undef' ) . '"'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$color // "undef"
MC/DC0%0/1
$color // "undef"
$color
Truth table50%1/2
A
A= $color
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2344 | 12 | die "$current_sub: $option is not a color the $engine engine knows: $got. It takes matplotlib's base, CSS4 and \"tab:\" names, \"C0\" to \"C9\", \"#rrggbb\", a gray level from 0 to 1, or (r, g, b) from 0 to 1"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2346 | 41 | ▶ | sub colormap_colors { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
colormap_colors: called CC=8 SCAR=21.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2347 | # The colors of a matplotlib colormap from its low end to its high end, as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2348 | # "#rrggbb", read from Matplotlib::Simple::Colors; a name ending in "_r" is the map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2349 | # reversed, as in matplotlib. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2350 | 41 | my ( $name, $engine, $current_sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2351 | 41 | require Matplotlib::Simple::Colors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2352 | 24 | ▶ | my $maps = do { no warnings 'once'; \%Matplotlib::Simple::Colors::colormap }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2353 | 41 | ▶ | my $text = ( ref $name ) ? '' : ( $name // '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$name // ""
MC/DC0%0/1
$name // ""
$name
Truth table50%1/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2354 | 41 | $text =~ s/^\s*(['"]?)(.*?)\1\s*$/$2/s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2355 | 41 | ▶ | my $reversed = ( $text =~ s/_r$// ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2356 | 41 | ▶ | if ( not defined $maps->{$text} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2357 | die "$current_sub: \"cmap\" \"" . ( ref $name ? ref $name : $name // 'undef' ) . "\" is not a colormap the $engine engine has; it has " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2358 | 3 | ▶ | . join( ', ', sort { lc $a cmp lc $b } keys %{$maps} ) . ', and each of them reversed with "_r"'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$name // "undef"
MC/DC0%0/1
$name // "undef"
$name
Truth table50%1/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2360 | 38 | my @colors = @{ $maps->{$text} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2361 | 38 | ▶ | return $reversed ? reverse @colors : @colors; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2363 | 1219 | ▶ | sub plt { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
plt: called CC=116 SCAR=50.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2364 | 1219 | my $current_sub = ( split( /::/, ( caller(0) )[3] ) )[-1] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2365 | ; # https://stackoverflow.com/questions/2559792/how-can-i-get-the-name-of-the-current-subroutine-in-perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2366 | # Accept BOTH calling conventions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2367 | # new style: plt( key => value, ... ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2368 | # back-compatible: plt({ key => value, ... }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2369 | 1219 | my $args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2370 | 1219 | ▶ | if ( ( scalar @_ == 1 ) && ( ref $_[0] eq 'HASH' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
scalar @_ == 1 and ref $_[0] eq "HASH"
MC/DC50%1/2
scalar @_ == 1 and ref $_[0] eq "HASH"
scalar @_ == 1
ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2371 | 848 | $args = $_[0]; # plt({ ... }) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2372 | } elsif ( ( scalar @_ % 2 ) == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2373 | 371 | $args = { @_ }; # plt( ... ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2374 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2375 | 0 | die "$current_sub: odd number of arguments; call as $current_sub( key => value, ... ) or $current_sub({ key => value, ... })"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2377 | 1219 | $args = copy_plot_hashes($args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2378 | 1219 | refuse_dotted_keywords( $args, $current_sub ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2379 | # Checked before anything multiplies them or compares them with a count of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2380 | # plots: "ncols => 'two'" died as "Argument \"two\" isn't numeric in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2381 | # multiplication", from a check further down that came too late to run. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2382 | 1212 | ▶ | my @bad_grid = grep { ( defined $args->{$_} ) && ( ( ref $args->{$_} ) || ( $args->{$_} !~ m/^\s*\d+\s*$/ ) || ( $args->{$_} == 0 ) ) } ('ncol', 'ncols', 'nrow', 'nrows'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition77%7/9
defined $args->{$_} && (ref $args->{$_} || !($args->{$_} =~ /^\s*\d+\s*$/) || $args->{$_} == 0)
ref $args->{$_} or not $args->{$_} =~ /^\s*\d+\s*$/ or $args->{$_} == 0
ref $args->{$_} or not $args->{$_} =~ /^\s*\d+\s*$/
MC/DC50%2/4
defined $args->{$_} && (ref $args->{$_} || !($args->{$_} =~ /^\s*\d+\s*$/) || $args->{$_} == 0)
defined $args->{$_}
ref $args->{$_}
not $args->{$_} =~ /^\s*\d+\s*$/
$args->{$_} == 0
Truth table60%3/5
A && B or not(C) or D
A= defined $args->{$_}B= ref $args->{$_}C= not $args->{$_} =~ /^\s*\d+\s*$/D= $args->{$_} == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2383 | 1212 | ▶ | if ( scalar @bad_grid > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2384 | 2 | die "$current_sub: " . join( ', ', map { "\"$_\" = \"$args->{$_}\"" } @bad_grid ) . ' must be a whole number of at least 1'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2386 | # As numbers: they are written into plt.subplots() as they stand, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2387 | # "ncols => '02'" passed the check above and was a SyntaxError there. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2388 | 1210 | $args->{$_} = 0 + $args->{$_} foreach grep { defined $args->{$_} } ( 'ncol', 'ncols', 'nrow', 'nrows' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2389 | # An alias and its name both given, and different: normalise_p sized the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2390 | # grid by "nrows" and plt then replaced it with "nrow", so that "nrows => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2391 | # 2, nrow => 1" with three plots made a grid too small for them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2392 | 1210 | foreach my $pair ( [ 'nrow', 'nrows' ], [ 'ncol', 'ncols' ] ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2393 | 2419 | my ( $alias, $name ) = @{$pair}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2394 | 2419 | ▶ | next unless ( defined $args->{$alias} ) && ( defined $args->{$name} ) && ( $args->{$alias} != $args->{$name} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $args->{$alias} and defined $args->{$name} and $args->{$alias} != $args->{$name}
defined $args->{$alias} and defined $args->{$name}
MC/DC100%3/3
defined $args->{$alias} and defined $args->{$name} and $args->{$alias} != $args->{$name}
defined $args->{$alias}
defined $args->{$name}
$args->{$alias} != $args->{$name}
Truth table100%4/4
A and B and C
A= defined $args->{$alias}B= defined $args->{$name}C= $args->{$alias} != $args->{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2395 | 2 | die "$current_sub: \"$alias\" is another name for \"$name\", and they disagree: \"$alias\" = $args->{$alias}, \"$name\" = $args->{$name}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2397 | # fold the "p" interface into the engine's internal plot model | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2398 | 1208 | ▶ | normalise_p( $args, $current_sub ) if defined $args->{p}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2399 | # and every "df" into the "data" of its plot_type, before anything checks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2400 | # "data" or the keywords | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2401 | 1199 | frames_to_data( $args, $current_sub ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2402 | 1190 | refuse_subplot_choices( $args, $current_sub ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2403 | # Read as a Python bool, as every other switch is: tested for Perl truth, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2404 | # "show => 'False'" wrote plt.show() and let the figure go without an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2405 | # "output_file". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2406 | 1175 | ▶ | $args->{show} = bool_option( $args->{show}, 'show', $current_sub ) if defined $args->{show}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2407 | 1174 | ▶ | my @reqd_args = $args->{show} ? () : ('output_file'); # e.g. "my_image.svg"; optional if "show" is set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2408 | 1174 | my $single_example = 'plt({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2409 | \'output_file\' => \'/tmp/gospel.word.counts.svg\', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2410 | \'plot_type\' => \'bar\', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2411 | data => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2412 | \'Matthew\' => 18345, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2413 | \'Mark\' => 11304, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2414 | \'Luke\' => 19482, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2415 | \'John\' => 15635, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2417 | });'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2418 | 1174 | my $multi_example = 'plt({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2419 | \'output_file\' => \'svg/pie.svg\', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2420 | plots => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2421 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2422 | data => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2423 | Russian => 106_000_000, # Primarily European Russia | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2424 | German => 95_000_000, # Germany, Austria, Switzerland, etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2425 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2426 | \'plot_type\' => \'pie\', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2427 | title => \'Top Languages in Europe\', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2428 | suptitle => \'Pie in subplots\', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2429 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2430 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2431 | data => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2432 | Russian => 106_000_000, # Primarily European Russia | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2433 | German => 95_000_000, # Germany, Austria, Switzerland, etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2434 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2435 | \'plot_type\' => \'pie\', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2436 | title => \'Top Languages in Europe\', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2437 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2438 | ncols => 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2439 | });'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2440 | 1174 | ▶ | if (ref $args->{output_file} ne '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2441 | 0 | p $args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2442 | 0 | die '"output_file" must be a SCALAR or string, but was given a ' . ref $args->{output_file}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2443 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2444 | # A single plot is validated against the keywords of the type it asked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2445 | # for, so that a mistyped keyword is reported against "bar"'s keywords | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2446 | # rather than the union of every type's -- which would suggest "notch" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2447 | # to someone drawing a bar chart. This rejects nothing new: the helper | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2448 | # this plot dispatches to checks the same hash against the same list. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2449 | # "plots" and "p" carry one type per subplot and none here, so for those | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2450 | # the union stands and each subplot is checked by its own helper. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2451 | 1174 | my $type_opt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2452 | 1174 | ▶ | if ( not defined $args->{plots} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2453 | 1082 | ▶ | check_plot_type({ type => $args->{plot_type} }) if defined $args->{plot_type}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2454 | 1070 | ▶ | $type_opt = $opt_key_of_type{ $args->{plot_type} // '' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{"plot_type"} // ""
MC/DC100%1/1
$args->{"plot_type"} // ""
$args->{"plot_type"}
Truth table100%2/2
A
A= $args->{"plot_type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2455 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2456 | my @defined_args = (@reqd_args, @ax_methods, @fig_methods, @plt_methods, @arg, @plt_arg, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2457 | 1162 | ▶ | defined $type_opt ? @{ $opt{$type_opt} } : @all_opt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2458 | 1162 | my %defined_arg = map { $_ => 1 } @defined_args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2459 | 1162 | my @bad_args = grep { not $defined_arg{$_} } keys %{$args}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2460 | 1162 | ▶ | if ( scalar @bad_args > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2461 | bad_keyword_error({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2462 | bad => \@bad_args, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2463 | accepted => \@defined_args, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2464 | preferred => defined $type_opt ? $opt{$type_opt} : \@all_opt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2465 | type => defined $type_opt ? $args->{plot_type} : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2466 | 54 | ▶ | sub => $current_sub | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2467 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2468 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2469 | # What is missing is reported only now that every keyword given is known to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2470 | # be one: "shoxw => 1" died as 'either "show" or "output_file" must be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2471 | # defined', which did not say that "show" had been given, mistyped, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2472 | # "plot_typ" as 'either "plot_type" or "plots"' likewise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2473 | # "output_file" is any name at all, so it is tested for being given rather | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2474 | # than for Perl truth, which refused a file called "0" as missing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2475 | 1108 | ▶ | if ( ( not ( ( defined $args->{output_file} ) && ( length $args->{output_file} ) ) ) && ( not $args->{show} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $args->{"output_file"} and length $args->{"output_file"} or $args->{"show"}
defined $args->{"output_file"} and length $args->{"output_file"}
MC/DC66%2/3
defined $args->{"output_file"} and length $args->{"output_file"} or $args->{"show"}
defined $args->{"output_file"}
length $args->{"output_file"}
$args->{"show"}
Truth table60%3/5
A and B or C
A= defined $args->{"output_file"}B= length $args->{"output_file"}C= $args->{"show"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2476 | 2 | p $args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2477 | 2 | die 'either "show" or "output_file" must be defined'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2478 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2479 | 1106 | ▶ | if ( ( not defined $args->{plot_type} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $args->{"plot_type"} or defined $args->{"plots"}
MC/DC100%2/2
defined $args->{"plot_type"} or defined $args->{"plots"}
defined $args->{"plot_type"}
defined $args->{"plots"}
Truth table100%3/3
A or B
A= defined $args->{"plot_type"}B= defined $args->{"plots"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2480 | && ( not defined $args->{plots} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2481 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2482 | 1 | p $args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2483 | 1 | die 'either "plot_type" or "plots" must be defined, but neither were'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2485 | 1105 | ▶ | $args->{nrows} = $args->{nrow} if defined $args->{nrow}; # allow synonyms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2486 | 1105 | ▶ | $args->{ncols} = $args->{ncol} if defined $args->{ncol}; # allow synonyms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2487 | 1105 | ▶ | $args->{nrows} = $args->{nrows} // 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{"nrows"} // 1
MC/DC100%1/1
$args->{"nrows"} // 1
$args->{"nrows"}
Truth table100%2/2
A
A= $args->{"nrows"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2488 | 1105 | ▶ | $args->{ncols} = $args->{ncols} // 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{"ncols"} // 1
MC/DC100%1/1
$args->{"ncols"} // 1
$args->{"ncols"}
Truth table100%2/2
A
A= $args->{"ncols"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2489 | 1105 | my $single_plot = 0; # false | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2490 | 1105 | ▶ | if ( ( defined $args->{plot_type} ) && ( defined $args->{data} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $args->{"plot_type"} and defined $args->{"data"}
MC/DC100%2/2
defined $args->{"plot_type"} and defined $args->{"data"}
defined $args->{"plot_type"}
defined $args->{"data"}
Truth table100%3/3
A and B
A= defined $args->{"plot_type"}B= defined $args->{"data"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2491 | 1013 | $single_plot = 1; # true | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2492 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2493 | # A single plot and "plots" both given, or half of a single plot beside | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2494 | # "plots". The single plot was drawn on ax0 and then the first subplot drawn | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2495 | # on top of it, and with two subplots the script named an "ax1" that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2496 | # plt.subplots(1,1) had not made; half of one was ignored. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2497 | 1105 | ▶ | if ( defined $args->{plots} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2498 | 92 | my @single = grep { defined $args->{$_} } ( 'plot_type', 'data' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2499 | 92 | ▶ | if ( scalar @single > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2500 | 2 | ▶ | die "$current_sub: " . join( ' and ', map { "\"$_\"" } @single ) . ' belong' . ( scalar @single == 1 ? 's' : '' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2501 | . ' to a single plot, and cannot be given with "plots": put ' . ( scalar @single == 1 ? 'it' : 'them' ) . ' in the hash of a subplot'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2502 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2503 | 90 | refuse_figure_keywords( $args, $current_sub ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2504 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2505 | 1096 | ▶ | if (($single_plot == 1) && (not defined $args->{plot_type})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$single_plot == 1 and not defined $args->{"plot_type"}
MC/DC0%0/2
$single_plot == 1 and not defined $args->{"plot_type"}
$single_plot == 1
not defined $args->{"plot_type"}
Truth table66%2/3
A and not(B)
A= $single_plot == 1B= not defined $args->{"plot_type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2506 | 0 | p $args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2507 | 0 | say STDERR $single_example; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2508 | 0 | die "\"plot_type\" was not defined for a single plot in $current_sub"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2509 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2510 | 1096 | ▶ | if ( ( $single_plot == 0 ) && (not defined $args->{plots} )) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$single_plot == 0 and not defined $args->{"plots"}
MC/DC100%2/2
$single_plot == 0 and not defined $args->{"plots"}
$single_plot == 0
not defined $args->{"plots"}
Truth table100%3/3
A and not(B)
A= $single_plot == 0B= not defined $args->{"plots"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2511 | 1 | say STDERR $multi_example; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2512 | 1 | die "$current_sub: single plots need \"data\" and \"plot_type\", see example above"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2513 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2514 | 1095 | ▶ | if ( ( $single_plot == 0 ) && ( ref $args->{plots} ne 'ARRAY' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$single_plot == 0 and ref $args->{"plots"} ne "ARRAY"
MC/DC0%0/2
$single_plot == 0 and ref $args->{"plots"} ne "ARRAY"
$single_plot == 0
ref $args->{"plots"} ne "ARRAY"
Truth table66%2/3
A and B
A= $single_plot == 0B= ref $args->{"plots"} ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2515 | 0 | p $args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2516 | 0 | die "$current_sub \"plots\" must have an array entered into it"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2517 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2518 | 1095 | ▶ | if ( ( $single_plot == 0 ) && ( scalar @{ $args->{plots} } == 0 ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$single_plot == 0 and scalar @{$args->{"plots"};} == 0
MC/DC0%0/2
$single_plot == 0 and scalar @{$args->{"plots"};} == 0
$single_plot == 0
scalar @{$args->{"plots"};} == 0
Truth table66%2/3
A and B
A= $single_plot == 0B= scalar @{$args->{"plots"};} == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2519 | 0 | p $args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2520 | 0 | die "$current_sub \"plots\" has 0 plots entered."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2521 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2522 | # Each subplot is read as a hash from here on, so anything else died as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2523 | # "Not a HASH reference" at whichever line first looked inside it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2524 | 1095 | ▶ | if ( $single_plot == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2525 | 83 | my @not_hash = grep { ref $args->{plots}[$_] ne 'HASH' } 0 .. $#{ $args->{plots} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2526 | 83 | ▶ | if ( scalar @not_hash > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2527 | 1 | die "$current_sub: \"plots\" holds one HASH reference per subplot, but index " . join( ', ', @not_hash ) . ' is not one'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2528 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2529 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2530 | 1094 | ▶ | if ($single_plot == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2531 | 1012 | ▶ | foreach my $arg (grep {defined $args->{$_} && $args->{$_} > 1} ('ncols', 'nrows')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $args->{$_} && $args->{$_} > 1
MC/DC0%0/2
defined $args->{$_} && $args->{$_} > 1
defined $args->{$_}
$args->{$_} > 1
Truth table33%1/3
A && B
A= defined $args->{$_}B= $args->{$_} > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2532 | 0 | warn "\"$arg\" is set to >1, but there is only 1 plot: resetting $arg to 1."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2533 | 0 | $args->{$arg} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2534 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2535 | # Sharing an axis needs a second subplot to share it with. These are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2536 | # axes methods too, so a single plot wrote "ax0.sharex(1)", which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2537 | # matplotlib refused: "'other' must be an instance of ... _AxesBase". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2538 | 1012 | foreach my $arg ( grep { defined $args->{$_} } ( 'sharex', 'sharey' ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2539 | 1 | warn "\"$arg\" shares an axis between subplots, but there is only 1 plot: ignoring it."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2540 | 1 | delete $args->{$arg}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2541 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2542 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2543 | 1094 | ▶ | if ( ( $single_plot == 0 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$single_plot == 0 and $args->{"nrows"} * $args->{"ncols"} < scalar @{$args->{"plots"};}
MC/DC0%0/2
$single_plot == 0 and $args->{"nrows"} * $args->{"ncols"} < scalar @{$args->{"plots"};}
$single_plot == 0
$args->{"nrows"} * $args->{"ncols"} < scalar @{$args->{"plots"};}
Truth table66%2/3
A and B
A= $single_plot == 0B= $args->{"nrows"} * $args->{"ncols"} < scalar @{$args->{"plots"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2544 | 82 | && ( ( $args->{nrows} * $args->{ncols} ) < scalar @{ $args->{plots} } ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2545 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2546 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2547 | 0 | p $args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2548 | 0 | my $n_plots = scalar @{ $args->{plots} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2549 | 0 | say STDERR | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2550 | "ncols = $args->{ncols}; nrows = $args->{nrows}, but there are $n_plots plots.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2551 | 0 | die 'There are not enough subplots for the data'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2552 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2553 | 1094 | ▶ | if ($single_plot == 0) { # multiple plots | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2554 | 82 | my $max_i = scalar @{ $args->{plots} } - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2555 | 82 | my @hash_ref_i = grep { ref $args->{plots}[$_]{data} eq 'HASH' } 0..$max_i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2556 | 82 | @bad_args = grep { scalar keys %{ $args->{plots}[$_]{data} } == 0} @hash_ref_i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2557 | 82 | ▶ | if (scalar @bad_args > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2558 | 0 | foreach my $i (@bad_args) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2559 | 0 | say STDERR "plot index $i:"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2560 | 0 | p $args->{plots}[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2561 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2562 | 0 | die "the above hash ref indices have empty data hashes for $current_sub"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2563 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2564 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2565 | 1094 | ▶ | if (($single_plot == 1) && (ref $args->{data} eq 'HASH') && (scalar keys %{ $args->{data}} == 0 )) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$single_plot == 1 and ref $args->{"data"} eq "HASH" and scalar keys %{$$args{"data"};} == 0
$single_plot == 1 and ref $args->{"data"} eq "HASH"
MC/DC0%0/3
$single_plot == 1 and ref $args->{"data"} eq "HASH" and scalar keys %{$$args{"data"};} == 0
$single_plot == 1
ref $args->{"data"} eq "HASH"
scalar keys %{$$args{"data"};} == 0
Truth table75%3/4
A and B and C
A= $single_plot == 1B= ref $args->{"data"} eq "HASH"C= scalar keys %{$$args{"data"};} == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2566 | 0 | p $args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2567 | 0 | die '"data" is an empty hash'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2568 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2569 | 1094 | ▶ | @bad_args = grep {defined $args->{$_} && (not looks_like_number($args->{$_}))} ('cbpad', 'scale', 'scalex', 'scaley'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $args->{$_} && !&looks_like_number($args->{$_})
MC/DC0%0/2
defined $args->{$_} && !&looks_like_number($args->{$_})
defined $args->{$_}
!&looks_like_number($args->{$_})
Truth table66%2/3
A && not(B)
A= defined $args->{$_}B= !&looks_like_number($args->{$_})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2570 | 1094 | ▶ | if (scalar @bad_args > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2571 | 0 | p $args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2572 | 0 | p @bad_args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2573 | 0 | die 'the above args must be numeric'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2574 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2575 | # A figure infinitely large, or NaN wide, cannot be drawn; each was written | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2576 | # into the script as given, as a bare "inf" or "nan". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2577 | 1094 | foreach my $scale ( grep { defined $args->{$_} } ( 'scale', 'scalex', 'scaley' ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2578 | 10 | ▶ | die "\"$scale\" must be a finite number above 0, not \"$args->{$scale}\"" unless ( is_finite( $args->{$scale} ) ) && ( $args->{$scale} > 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
is_finite($args->{$scale}) and $args->{$scale} > 0
MC/DC50%1/2
is_finite($args->{$scale}) and $args->{$scale} > 0
is_finite($args->{$scale})
$args->{$scale} > 0
Truth table66%2/3
A and B
A= is_finite($args->{$scale})B= $args->{$scale} > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2579 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2580 | # "dpi" is written into savefig as it stands, so it is a number here, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2581 | # one a file can be drawn at. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2582 | 1093 | ▶ | if ( defined $args->{dpi} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2583 | 22 | my $dpi = $args->{dpi}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2584 | 22 | ▶ | if ( ( ref $dpi ) || ( not looks_like_number($dpi) ) || ( not is_finite($dpi) ) || ( $dpi <= 0 ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
ref $dpi or not &looks_like_number($dpi) or not is_finite($dpi) or $dpi <= 0
ref $dpi or not &looks_like_number($dpi) or not is_finite($dpi)
ref $dpi or not &looks_like_number($dpi)
MC/DC100%4/4
ref $dpi or not &looks_like_number($dpi) or not is_finite($dpi) or $dpi <= 0
ref $dpi
not &looks_like_number($dpi)
not is_finite($dpi)
$dpi <= 0
Truth table100%5/5
A or not(B) or not(C) or D
A= ref $dpiB= not &looks_like_number($dpi)C= not is_finite($dpi)D= $dpi <= 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2585 | 8 | ▶ | die "\"dpi\" must be a finite number above 0, the dots per inch \"output_file\" is saved at, not " . ( ref $dpi ? ( ref $dpi ) . ' reference' : "\"$dpi\"" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2586 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2587 | 14 | $args->{dpi} = 0 + $dpi; # "0300" and " 300" are numbers to perl and not to python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2588 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2589 | # One file is saved at one resolution, so "dpi" in a subplot or an "add" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2590 | # graph has nothing of its own to set. Asked here, by name: left to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2591 | # helper it was "isn't defined for plot_type", with "set_dpi" suggested. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2592 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2593 | 1085 | ▶ | my @plots = ( $single_plot == 1 ) ? ( [ $args, '' ] ) : map { [ $args->{plots}[$_], " at subplot $_" ] } 0 .. $#{ ( ref $args->{plots} eq 'ARRAY' ) ? $args->{plots} : [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2594 | 1085 | foreach my $drawn (@plots) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2595 | 1161 | my ( $plot, $where ) = @{$drawn}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2596 | 1161 | ▶ | next unless ref $plot eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2597 | 1161 | ▶ | if ( ( $single_plot == 0 ) && ( exists $plot->{dpi} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$single_plot == 0 and exists $plot->{"dpi"}
MC/DC100%2/2
$single_plot == 0 and exists $plot->{"dpi"}
$single_plot == 0
exists $plot->{"dpi"}
Truth table100%3/3
A and B
A= $single_plot == 0B= exists $plot->{"dpi"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2598 | 1 | die "$current_sub: \"dpi\"$where: one file is saved at one resolution, so give \"dpi\" once, beside \"plots\" or \"p\""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2599 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2600 | 1160 | ▶ | if ( ( ref $plot->{add} eq 'ARRAY' ) && ( grep { ( ref $_ eq 'HASH' ) && ( exists $_->{dpi} ) } @{ $plot->{add} } ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
ref $plot->{"add"} eq "ARRAY" and grep {ref $_ eq "HASH" and exists $_->{"dpi"};} @{$$plot{"add"};}
ref $_ eq 'HASH' && exists $_->{'dpi'}
MC/DC100%2/2
ref $plot->{"add"} eq "ARRAY" and grep {ref $_ eq "HASH" and exists $_->{"dpi"};} @{$$plot{"add"};}
ref $plot->{"add"} eq "ARRAY"
grep {ref $_ eq "HASH" and exists $_->{"dpi"};} @{$$plot{"add"};}
MC/DC100%2/2
ref $_ eq 'HASH' && exists $_->{'dpi'}
ref $_ eq 'HASH'
exists $_->{'dpi'}
Truth table100%3/3
A and B
A= ref $plot->{"add"} eq "ARRAY"B= grep {ref $_ eq "HASH" and exists $_->{"dpi"};} @{$$plot{"add"};}
Truth table100%3/3
A && B
A= ref $_ eq 'HASH'B= exists $_->{'dpi'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2601 | 2 | die "$current_sub: \"dpi\" in an \"add\" graph$where: one file is saved at one resolution, so give \"dpi\" once, at the top level"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2602 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2603 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2604 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2605 | 1082 | ▶ | if ((defined $args->{shared_colorbar}) && ($single_plot == 1)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $args->{"shared_colorbar"} and $single_plot == 1
MC/DC100%2/2
defined $args->{"shared_colorbar"} and $single_plot == 1
defined $args->{"shared_colorbar"}
$single_plot == 1
Truth table100%3/3
A and B
A= defined $args->{"shared_colorbar"}B= $single_plot == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2606 | 1 | warn 'There is only 1 plot/subplot, shared colorbars make no sense... deleting'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2607 | 1 | delete $args->{shared_colorbar}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2608 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2609 | 1082 | ▶ | if (defined $args->{shared_colorbar}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2610 | 14 | my $ref = ref $args->{shared_colorbar}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2611 | 14 | ▶ | if ($ref ne 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2612 | 0 | p $args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2613 | 0 | die '"shared_colorbar" must be an array reference'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2614 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2615 | 14 | ▶ | if ( scalar @{ $args->{shared_colorbar} } == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2616 | 1 | die '"shared_colorbar" is an empty array: it takes the 0-based indices of the subplots that share the colorbar, e.g. [0,1]'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2617 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2618 | 13 | ▶ | my @bad_idx = grep { ( not defined $_ ) || ( $_ !~ m/^\d+$/ ) } @{ $args->{shared_colorbar} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $_ && $_ =~ /^\d+$/
MC/DC50%1/2
defined $_ && $_ =~ /^\d+$/
defined $_
$_ =~ /^\d+$/
Truth table66%2/3
A && B
A= defined $_B= $_ =~ /^\d+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2619 | 13 | ▶ | if ( scalar @bad_idx > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2620 | 1 | p @bad_idx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2621 | 1 | die 'the above "shared_colorbar" entries are not 0-based subplot indices'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2622 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2623 | # Against the plots, not the cells of the grid: an index naming an empty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2624 | # cell passed, the subplots before it had their colorbars turned off, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2625 | # the one meant to draw the shared colorbar did not exist, so none was | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2626 | # drawn and nothing was said. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2627 | 12 | my $max_subplot_idx = max(@{ $args->{shared_colorbar} }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2628 | 12 | my $max_plot_idx = scalar @{ $args->{plots} } - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2629 | 12 | ▶ | if ($max_subplot_idx > $max_plot_idx) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2630 | 1 | p $args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2631 | 1 | die "the max \"shared_colorbar\" index $max_subplot_idx > than the max index of plots, $max_plot_idx"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2632 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2633 | # plt tells each of these subplots whether to draw the colorbar, so each | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2634 | # has to be of a type that draws one. Any other died, from its own helper, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2635 | # about a "colorbar_on" or "cbpad" the caller had never passed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2636 | 11 | my %draws_colorbar = map { $_ => 1 } qw(colored_table hexbin hist2d imshow scatter); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2637 | my @no_colorbar = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2638 | 22 | ▶ | ( ref $args->{plots}[$_] eq 'HASH' ) && ( not $draws_colorbar{ $args->{plots}[$_]{plot_type} // '' } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition60%3/5
ref $args->{'plots'}[$_] eq 'HASH' && !$draws_colorbar{$args->{'plots'}[$_]{'plot_type'} // ''}
$args->{"plots"}[$_]{"plot_type"} // ""
MC/DC50%1/2
ref $args->{'plots'}[$_] eq 'HASH' && !$draws_colorbar{$args->{'plots'}[$_]{'plot_type'} // ''}
ref $args->{'plots'}[$_] eq 'HASH'
!$draws_colorbar{$args->{'plots'}[$_]{'plot_type'} // ''}
MC/DC0%0/1
$args->{"plots"}[$_]{"plot_type"} // ""
$args->{"plots"}[$_]{"plot_type"}
Truth table66%2/3
A && not(B)
A= ref $args->{'plots'}[$_] eq 'HASH'B= !$draws_colorbar{$args->{'plots'}[$_]{'plot_type'} // ''}
Truth table50%1/2
A
A= $args->{"plots"}[$_]{"plot_type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2639 | 11 | } @{ $args->{shared_colorbar} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2640 | 11 | ▶ | if ( scalar @no_colorbar > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2641 | 1 | ▶ | die '"shared_colorbar" lists subplot ' . join( ', ', map { "$_ (\"" . ( $args->{plots}[$_]{plot_type} // 'undef' ) . '")' } @no_colorbar ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{"plots"}[$_]{"plot_type"} // "undef"
MC/DC0%0/1
$args->{"plots"}[$_]{"plot_type"} // "undef"
$args->{"plots"}[$_]{"plot_type"}
Truth table50%1/2
A
A= $args->{"plots"}[$_]{"plot_type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2642 | . ', but only these plot types draw a colorbar: ' . join( ', ', sort keys %draws_colorbar ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2643 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2644 | 10 | shared_table_range( $args, $current_sub ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2645 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2646 | 1078 | check_add( $args->{add}, '' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2647 | 1073 | ▶ | if ( $single_plot == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2648 | 76 | check_add( $args->{plots}[$_]{add}, " at subplot $_" ) foreach 0 .. $#{ $args->{plots} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2649 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2650 | # Before the figure is written, as the types are checked: every plot and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2651 | # every "add" graph, which takes its plot's type when it has none. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2652 | 1069 | ▶ | my @drawn = ( $single_plot == 1 ) ? ( [ $args, '' ] ) : map { [ $args->{plots}[$_], " at subplot $_" ] } 0 .. $#{ $args->{plots} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2653 | 1069 | foreach my $drawn (@drawn) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2654 | 1138 | my ( $plot, $at ) = @{$drawn}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2655 | 1138 | ▶ | check_data_shape( $plot, $plot->{plot_type}, $at, $current_sub ) if defined $plot->{data}; # a plot with no "data" is refused by name where it is drawn | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2656 | 1123 | ▶ | foreach my $graph ( @{ $plot->{add} // [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$plot->{"add"} // []
MC/DC100%1/1
$plot->{"add"} // []
$plot->{"add"}
Truth table100%2/2
A
A= $plot->{"add"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2657 | 34 | ▶ | check_data_shape( $graph, $graph->{plot_type} // $plot->{plot_type}, " for an \"add\" graph$at", $current_sub ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$graph->{"plot_type"} // $plot->{"plot_type"}
MC/DC0%0/2
$graph->{"plot_type"} // $plot->{"plot_type"}
$graph->{"plot_type"}
$plot->{"plot_type"}
Truth table66%2/3
A // B
A= $graph->{"plot_type"}B= $plot->{"plot_type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2658 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2659 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2660 | 1051 | ▶ | if ( defined $args->{plots} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2661 | 70 | my @undef_plot_types; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2662 | 70 | my $j = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2663 | 70 | foreach my $plot (@{ $args->{plots} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2664 | 138 | ▶ | push @undef_plot_types, $j unless defined $plot->{plot_type}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2665 | 138 | $j++; # every subplot, not only the ones missing a type: $j is the index reported | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2666 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2667 | 70 | ▶ | if ( scalar @undef_plot_types > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2668 | 0 | p $args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2669 | 0 | p @undef_plot_types; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2670 | 0 | die 'The above subplot indices are missing "plot_type"'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2671 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2672 | # Each subplot's type is checked here, before the figure is written, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2673 | # rather than at the dispatch below: a bad type at the last subplot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2674 | # would otherwise be found only after every earlier subplot had been | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2675 | # written to the script. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2676 | 70 | $j = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2677 | 70 | foreach my $plot (@{ $args->{plots} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2678 | 138 | check_plot_type({ type => $plot->{plot_type}, where => "at subplot $j" }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2679 | 137 | foreach my $graph (@{ $plot->{add} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2680 | 16 | ▶ | next unless defined $graph->{plot_type}; # an "add" graph without one inherits the subplot's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2681 | 9 | check_plot_type({ type => $graph->{plot_type}, where => "for an \"add\" graph at subplot $j" }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2682 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2683 | 136 | $j++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2684 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2685 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2686 | # Each subplot has its "data" and its "plot_type". Here rather than where | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2687 | # each is drawn, as the types above are, so that every engine is handed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2688 | # plots it can read without checking again. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2689 | 1049 | ▶ | foreach my $i ( 0 .. $#{ $args->{plots} // [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{"plots"} // []
MC/DC100%1/1
$args->{"plots"} // []
$args->{"plots"}
Truth table100%2/2
A
A= $args->{"plots"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2690 | 134 | my $plot = $args->{plots}[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2691 | 134 | my @undef_keys = grep { !defined $plot->{$_} } ( 'data', 'plot_type' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2692 | 134 | ▶ | if ( scalar @undef_keys > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2693 | 0 | p $plot; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2694 | 0 | p @undef_keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2695 | 0 | die "Above args are necessary, but were not defined for plot $i."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2696 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2697 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2698 | # An "add" graph without a type is drawn as its plot's type, which is what | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2699 | # an engine reads it as from here on. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2700 | 1049 | foreach my $drawn (@drawn) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2701 | 1115 | my ( $plot, $at ) = @{$drawn}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2702 | 1115 | ▶ | foreach my $graph ( @{ $plot->{add} // [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$plot->{"add"} // []
MC/DC100%1/1
$plot->{"add"} // []
$plot->{"add"}
Truth table100%2/2
A
A= $plot->{"add"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2703 | 30 | ▶ | $graph->{plot_type} = $graph->{plot_type} // $plot->{plot_type}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$graph->{"plot_type"} // $plot->{"plot_type"}
MC/DC0%0/2
$graph->{"plot_type"} // $plot->{"plot_type"}
$graph->{"plot_type"}
$plot->{"plot_type"}
Truth table66%2/3
A // B
A= $graph->{"plot_type"}B= $plot->{"plot_type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2704 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2705 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2706 | # As a Python bool, as the other switches are: compared with "==", "execute | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2707 | # => 'yes'" died as 'Argument "yes" isn't numeric'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2708 | 1049 | ▶ | $args->{execute} = bool_option( $args->{execute} // 1, 'execute', $current_sub ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{"execute"} // 1
MC/DC100%1/1
$args->{"execute"} // 1
$args->{"execute"}
Truth table100%2/2
A
A= $args->{"execute"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2709 | 1048 | my $engine = engine_name( $args, $current_sub ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2710 | 1046 | my $style = style_name( $args, $current_sub ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2711 | 1044 | check_engine( $engine, $args, $single_plot, $current_sub ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2712 | # Taken out after check_engine has seen it, so that an engine that does not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2713 | # list "dpi" refuses it by name, and before render, so that the helper a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2714 | # single plot's hash is handed to does not meet a keyword that is the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2715 | # figure's and not its own. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2716 | 1017 | my $dpi = delete $args->{dpi}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2717 | 1017 | return $engine_module{$engine}->can('render')->( $args, { sub => $current_sub, single_plot => $single_plot, style => $style, dpi => $dpi } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2718 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2719 | # Generate wrappers dynamically | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2720 | 24 | my @wrappers = qw(bar barh boxplot colored_table hexbin hist hist2d imshow pie plot scatter venn_proportional_area violin violinplot wide); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2721 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2722 | 24 | foreach my $sub_name (@wrappers) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2723 | 24 | ▶ | no strict 'refs'; # Gemini helped | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2724 | 29 | ▶ | *$sub_name = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=27.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2725 | # accept both bar({ ... }) and bar( ... ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2726 | 29 | my $args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2727 | 29 | ▶ | if ( ( scalar @_ == 1 ) && ( ref $_[0] eq 'HASH' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
scalar @_ == 1 and ref $_[0] eq "HASH"
MC/DC0%0/2
scalar @_ == 1 and ref $_[0] eq "HASH"
scalar @_ == 1
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2728 | 0 | $args = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2729 | } elsif ( ( scalar @_ % 2 ) == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2730 | 29 | $args = { @_ }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2731 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2732 | 0 | die "$sub_name: odd number of arguments; call as $sub_name( key => value, ... ) or $sub_name({ key => value, ... })"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2733 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2734 | # Check for conflicts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2735 | 29 | ▶ | if ((defined $args->{plot_type}) && ($args->{plot_type} ne $sub_name)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $args->{"plot_type"} and $args->{"plot_type"} ne $sub_name
MC/DC0%0/2
defined $args->{"plot_type"} and $args->{"plot_type"} ne $sub_name
defined $args->{"plot_type"}
$args->{"plot_type"} ne $sub_name
Truth table33%1/3
A and B
A= defined $args->{"plot_type"}B= $args->{"plot_type"} ne $sub_name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2736 | 0 | warn "$args->{plot_type} will be ignored for $sub_name"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2737 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2738 | 29 | ▶ | if (defined $args->{plots}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2739 | 0 | die "\"plots\" is meant for the subroutine \"plt\"; $sub_name is single-only"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2740 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2741 | 29 | ▶ | if (defined $args->{p}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2742 | 0 | die "\"p\" is meant for the subroutine \"plt\"; $sub_name is single-only"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2743 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2744 | # Call plt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2745 | 29 | plt({ %{ $args }, plot_type => $sub_name }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2746 | 360 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2747 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2748 | # The default engine, loaded with the module rather than on the first figure, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2749 | # so that its subs -- python_command, which the tests call -- can be called by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2750 | # name as soon as Matplotlib::Simple is loaded. Last, because it aliases subs of this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2751 | # package, which have to be compiled first. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2752 | 24 | require Matplotlib::Simple::Matplotlib; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2753 | 24 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2754 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||