Functions | |
| resolve_ref (ref) | |
| calculate_bit_length (details) | |
| draw_bit_field (x, y, bit_length, prop_name, bit_position, is_array=False) | |
Variables | |
| parser = argparse.ArgumentParser(description='Draw bit field diagram from JSON schema.') | |
| type | |
| str | |
| help | |
| default | |
| args = parser.parse_args() | |
| schema = json.load(f) | |
| properties = schema['definitions'][args.version]['properties'] | |
| int | bit_width = 10 |
| int | bit_height = 20 |
| int | margin = 0. |
| int | total_bits = 0 |
| tuple | rows = (total_bits + 63) // 64 |
| int | fig_width = bit_width * 64 + margin * 2 |
| tuple | fig_height = (rows + 1) * bit_height + margin * 2 |
| fig | |
| ax | |
| figsize | |
| int | x = margin |
| tuple | y = fig_height - margin - bit_height |
| int | bit_position = 0 |
| rect = patches.Rectangle((x, y), bit_width, bit_height, linewidth=1, edgecolor='black', facecolor='none') | |
| text = str(63 - i) | |
| int | fontsize = min(bit_width, bit_height) * 3 |
| ha | |
| va | |
| details = resolve_ref(details['$ref']) | |
| items_ref = details['items'].get('$ref') | |
| ref_details = resolve_ref(items_ref) | |
| bit_length = ref_details['bitLength'] | |
| prop | |
| is_array | |
| output_md_dir = args.output_dir | |
| str | output_pdf_dir = output_md_dir + '/pdf' |
| str | output_png_dir = output_md_dir + '/png' |
| str | output_svg_dir = output_md_dir + '/svg' |
| exist_ok | |
| str | base_filename = os.path.splitext(os.path.basename(args.input_file))[0] + f'-{args.version}' |
| output_pdf_file = os.path.join(output_pdf_dir, base_filename + '.pdf') | |
| output_svg_file = os.path.join(output_svg_dir, base_filename + '.svg') | |
| output_png_file = os.path.join(output_png_dir, base_filename + '.png') | |
| output_small_png_file = os.path.join(output_png_dir, base_filename + '-s.png') | |
| output_md_file = os.path.join(output_md_dir, base_filename + '.md') | |
| title = schema.get('title', 'No Title') | |
| description = schema.get('description', 'No Description') | |
| relative_png_path = os.path.relpath(output_png_file, start=os.path.dirname(output_md_file)) | |
| relative_pdf_path = os.path.relpath(output_pdf_file, start=os.path.dirname(output_md_file)) | |
| relative_svg_path = os.path.relpath(output_svg_file, start=os.path.dirname(output_md_file)) | |
| format | |
@file draw_bit_field.py
@brief Draws a bit field diagram from a JSON schema and outputs it in various formats.
This script reads a JSON schema file and generates a visual representation of the bit fields defined in the schema.
It supports resolving internal and external JSON references and can handle different schema versions.
The output includes a bit field diagram in PDF, PNG, and SVG formats, as well as a Markdown file with property details.
@section usage Usage
@code{.sh}
python draw_bit_field.py <input_file> [--output_dir <output_dir>] [--version <version>]
@endcode
@param input_file Path to the input JSON schema file.
@param output_dir Path to the output directory (default: 'readme-header').
@param version Schema version to use (e.g., v0, v1) (optional).
@section dependencies Dependencies
- json
- matplotlib
- os
- argparse
@section author Author
Shinsuke OTA <ota@rcnp.osaka-u.ac.jp>
@section date Date
2023-10-06
| draw_bit_field.calculate_bit_length | ( | details | ) |
Definition at line 85 of file draw_bit_field.py.
| draw_bit_field.draw_bit_field | ( | x, | |
| y, | |||
| bit_length, | |||
| prop_name, | |||
| bit_position, | |||
| is_array = False ) |
Definition at line 142 of file draw_bit_field.py.
| draw_bit_field.resolve_ref | ( | ref | ) |
Resolves a JSON reference to its corresponding property.
This function handles both internal references (starting with '#') and external references
(containing a file path and a reference path separated by '#').
Args:
ref (str): The JSON reference to resolve. It can be an internal reference (e.g., '#/definitions/Property')
or an external reference (e.g., 'file.json#/definitions/Property').
Returns:
dict: The resolved property from the JSON schema.
Raises:
KeyError: If the reference path does not exist in the properties.
FileNotFoundError: If the external reference file does not exist.
json.JSONDecodeError: If the external reference file is not a valid JSON.
Definition at line 53 of file draw_bit_field.py.
| draw_bit_field.args = parser.parse_args() |
Definition at line 38 of file draw_bit_field.py.
| draw_bit_field.ax |
Definition at line 119 of file draw_bit_field.py.
| draw_bit_field.base_filename = os.path.splitext(os.path.basename(args.input_file))[0] + f'-{args.version}' |
Definition at line 201 of file draw_bit_field.py.
| int draw_bit_field.bit_height = 20 |
Definition at line 103 of file draw_bit_field.py.
| draw_bit_field.bit_length = ref_details['bitLength'] |
Definition at line 178 of file draw_bit_field.py.
| draw_bit_field.bit_position = 0 |
Definition at line 127 of file draw_bit_field.py.
| int draw_bit_field.bit_width = 10 |
Definition at line 102 of file draw_bit_field.py.
| draw_bit_field.default |
Definition at line 34 of file draw_bit_field.py.
| draw_bit_field.description = schema.get('description', 'No Description') |
Definition at line 216 of file draw_bit_field.py.
| draw_bit_field.details = resolve_ref(details['$ref']) |
Definition at line 171 of file draw_bit_field.py.
| draw_bit_field.exist_ok |
Definition at line 195 of file draw_bit_field.py.
| draw_bit_field.fig |
Definition at line 119 of file draw_bit_field.py.
| tuple draw_bit_field.fig_height = (rows + 1) * bit_height + margin * 2 |
Definition at line 116 of file draw_bit_field.py.
| int draw_bit_field.fig_width = bit_width * 64 + margin * 2 |
Definition at line 115 of file draw_bit_field.py.
| draw_bit_field.figsize |
Definition at line 119 of file draw_bit_field.py.
| draw_bit_field.fontsize = min(bit_width, bit_height) * 3 |
Definition at line 134 of file draw_bit_field.py.
| draw_bit_field.format |
Definition at line 239 of file draw_bit_field.py.
| draw_bit_field.ha |
Definition at line 135 of file draw_bit_field.py.
| draw_bit_field.help |
Definition at line 33 of file draw_bit_field.py.
| draw_bit_field.is_array |
Definition at line 179 of file draw_bit_field.py.
| draw_bit_field.items_ref = details['items'].get('$ref') |
Definition at line 175 of file draw_bit_field.py.
| int draw_bit_field.margin = 0. |
Definition at line 104 of file draw_bit_field.py.
| draw_bit_field.output_md_dir = args.output_dir |
Definition at line 191 of file draw_bit_field.py.
| draw_bit_field.output_md_file = os.path.join(output_md_dir, base_filename + '.md') |
Definition at line 209 of file draw_bit_field.py.
| draw_bit_field.output_pdf_dir = output_md_dir + '/pdf' |
Definition at line 192 of file draw_bit_field.py.
| draw_bit_field.output_pdf_file = os.path.join(output_pdf_dir, base_filename + '.pdf') |
Definition at line 205 of file draw_bit_field.py.
| draw_bit_field.output_png_dir = output_md_dir + '/png' |
Definition at line 193 of file draw_bit_field.py.
| draw_bit_field.output_png_file = os.path.join(output_png_dir, base_filename + '.png') |
Definition at line 207 of file draw_bit_field.py.
| draw_bit_field.output_small_png_file = os.path.join(output_png_dir, base_filename + '-s.png') |
Definition at line 208 of file draw_bit_field.py.
| draw_bit_field.output_svg_dir = output_md_dir + '/svg' |
Definition at line 194 of file draw_bit_field.py.
| draw_bit_field.output_svg_file = os.path.join(output_svg_dir, base_filename + '.svg') |
Definition at line 206 of file draw_bit_field.py.
| draw_bit_field.parser = argparse.ArgumentParser(description='Draw bit field diagram from JSON schema.') |
Definition at line 32 of file draw_bit_field.py.
| draw_bit_field.prop |
Definition at line 179 of file draw_bit_field.py.
| draw_bit_field.properties = schema['definitions'][args.version]['properties'] |
Definition at line 46 of file draw_bit_field.py.
| draw_bit_field.rect = patches.Rectangle((x, y), bit_width, bit_height, linewidth=1, edgecolor='black', facecolor='none') |
Definition at line 131 of file draw_bit_field.py.
| draw_bit_field.ref_details = resolve_ref(items_ref) |
Definition at line 177 of file draw_bit_field.py.
| draw_bit_field.relative_pdf_path = os.path.relpath(output_pdf_file, start=os.path.dirname(output_md_file)) |
Definition at line 232 of file draw_bit_field.py.
| draw_bit_field.relative_png_path = os.path.relpath(output_png_file, start=os.path.dirname(output_md_file)) |
Definition at line 231 of file draw_bit_field.py.
| draw_bit_field.relative_svg_path = os.path.relpath(output_svg_file, start=os.path.dirname(output_md_file)) |
Definition at line 233 of file draw_bit_field.py.
| tuple draw_bit_field.rows = (total_bits + 63) // 64 |
Definition at line 112 of file draw_bit_field.py.
| draw_bit_field.schema = json.load(f) |
Definition at line 42 of file draw_bit_field.py.
| draw_bit_field.str |
Definition at line 33 of file draw_bit_field.py.
| draw_bit_field.text = str(63 - i) |
Definition at line 133 of file draw_bit_field.py.
| str draw_bit_field.title = schema.get('title', 'No Title') |
Definition at line 213 of file draw_bit_field.py.
| int draw_bit_field.total_bits = 0 |
Definition at line 107 of file draw_bit_field.py.
| draw_bit_field.type |
Definition at line 33 of file draw_bit_field.py.
| draw_bit_field.va |
Definition at line 135 of file draw_bit_field.py.
| int draw_bit_field.x = margin |
Definition at line 125 of file draw_bit_field.py.
| draw_bit_field.y = fig_height - margin - bit_height |
Definition at line 126 of file draw_bit_field.py.