Code Monkey home page Code Monkey logo

wavedrompy's Introduction

WaveDromPy

This is a python module and command line fully compatible with WaveDrom, which is originally implemented in JavaScript. It is useful if you want to generate wavedrom diagrams from a python environment or simply don't want to install the Node.js environment just to use WaveDrom as simple command line.

WaveDromPy is for example used in sphinxcontrib-wavedrom to render wavedrom for Sphinx documentation. While the original project renders the diagrams in JavaScript in the browser, WaveDromPy renders them to SVG files.

This tool is a direct translation of original Javascript file WaveDrom.js to Python. No extra feature added. We seek to have it fully compatible.

The tool WaveDromPy directly converts WaveDrom compatible JSON files into SVG format.

Build Status PyPI version

Installation

It is most easy to just install wavedrom via pip/pypi:

pip install wavedrom

Alternatively you can install the latest version from this repository:

pip install git+https://github.com/wallento/wavedrompy

or from your local copy:

pip install .

Usage

You can either use the tool from Python:

import wavedrom
svg = wavedrom.render("""
{ "signal": [
 { "name": "CK",   "wave": "P.......",                                              "period": 2  },
 { "name": "CMD",  "wave": "x.3x=x4x=x=x=x=x", "data": "RAS NOP CAS NOP NOP NOP NOP", "phase": 0.5 },
 { "name": "ADDR", "wave": "x.=x..=x........", "data": "ROW COL",                     "phase": 0.5 },
 { "name": "DQS",  "wave": "z.......0.1010z." },
 { "name": "DQ",   "wave": "z.........5555z.", "data": "D0 D1 D2 D3" }
]}""")
svg.saveas("demo1.svg")

This will render a waveform as:

Example 1

You can find more examples in the WaveDrom tutorial.

A second feature is that WaveDrom can render logic circuit diagrams:

import wavedrom
svg = wavedrom.render("""
{ "assign":[
  ["out",
    ["|",
      ["&", ["~", "a"], "b"],
      ["&", ["~", "b"], "a"]
    ]
  ]
]}""")
svg.saveas("demo2.svg")

This will render a as:

Example 2

You can find more examples in the WaveDrom tutorial2.

Finally, wavedrom can draw registers as bitfields:

import wavedrom
svg = wavedrom.render("""
{"reg": [
  { "name": "IPO",   "bits": 8, "attr": "RO" },
  {                  "bits": 7 },
  { "name": "<o>B</o><b>R<i>K</i></b>",   "bits": 5, "attr": "RW", "type": 4 },
  { "name": "CPK",   "bits": 1 },
  { "name": "Clear", "bits": 3 },
  { "bits": 8 }
  ]
]}""")
svg.saveas("demo3.svg")

This will render as:

Example 3

This mode is documented as part of the bit-field JavaScript package.

Alternatively, WaveDromPy can be called from the command line:

wavedrompy --input input.json --svg output.svg

Important notice

The command line uses Python's JSON interpreter that is more restrictive (coherent with the JSOC spec), while the JavaScript json is more relaxed:

  • All strings have to be written between quotes (""),
  • Extra comma (,) not supported at end of lists or dictionaries

AsciiDoctor example

An AsciiDoctor example is provided to directly generate timing diagrams from AsciiDoctor formatted documents.

wavedrompy's People

Contributors

astro avatar breizhgeek avatar crozzers avatar huleiak47 avatar idoka avatar joshuascheid avatar k4zuki avatar ktsiligkiris avatar mutantplatypus avatar wallento avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wavedrompy's Issues

Copyright year incorrect

My last commit message says I corrected the copyright year, but I actually didn't. It still says 2018.

JSON restrictions can be easily solved

FYI, you can easily fix JSON's input format limitation (double quotes and last comma) with the following code. It loads the problematic JSON contents (already in a string) using yaml (json and yaml are compatible) and dumps it back to another string using json module. The new string has double quotes everywhere and eliminates the exceeding comma.

The function below fixes the problem.

import yaml
import json

def fixQuotes(inputString):
# fix double quotes in the input file. opening with yaml and dumping with json fix the issues.
yamlCode = yaml.load(inputString, Loader=yaml.FullLoader)
fixedString = json.dumps(yamlCode, indent=4)
return fixedString

wavedrompy fails to work on files generated by wavedrom

I'm not sure if this is a duplicate issue (certainly issue #34 seems to cover the same ground, but doesn't actually state the issue).

If I run wavedrompy -i test-file.json -s test-file.svg on a file generated using the wavedrom editor I get the following error message:

json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

I understand that the underlying issue is that the wavedrom file format (an example is shown below):

{signal: [
  {name: 'e', wave: '0.30.30..', data: ['τ', 'τ+1']},
  {name: 'x', wave: 'x.=x.=x..', data: ['x₀', 'x₁']},
  {name: 'δₑx', wave: 'x..=..=..', data: ['x₀', 'x₁']},
  {name: 'δe', wave: '0..30.30.', data: ['τ', 'τ+1']},
]}

is in what is referred to as "relaxed JSON", or really Javascript, which is a dialect the Python JSON decoder doesn't appear to understand.

Fix generating fields color to proper rendering svg->pdf for asciidoc flow

The both, wavedrom and wavedrompy use hsl representation of colors for bitfield functionaluty.
It seems asciidoctor flow doesn't support hsl in svg well.

The svg files from wavedrom and wavedrompy rendering in Chrome:

Screenshot from 2022-04-07 21-56-39
Screenshot from 2022-04-07 21-56-30

The same svg from wavedrom and wavedrompy build in asciidoc and finally rendered as PDF:

Screenshot from 2022-04-07 21-55-47

I tried to make tiny fix to convert HSL->RGB:

Screenshot from 2022-04-08 16-08-30

iDoka@90dffcd

Issue with empty string as name

Given the following json.

{ "signal":[
  {"name": "", "wave": "13.========4.1", "data": ["StartBit", "b7", "b6", "b5", "b4", "b3", "b2", "b1", "b0", "StopBit"]},
  {"name": "Frame format", "wave": "1=.==....|=3=..1", "data": ["Break", "ID", "DATA", "CRC", "ACK", "End of frame"]}
]}

One signal has an empty string as name, which causes the signal to not get generated. It only takes up some vertical space:

image

If that were the only signal, only a vertical dashed line would get generated by wavedrompy.
wavedrom allows an empty string as name. I think it would be nice if wavedrompy would support this as well.

When data Is A String, Repeated Whitespace Is Parsed As One Separator

I'm not sure how significant this is, as there's an easy workaround.

Given the JSON:

{ "signal": [
  { "name": "trig", "wave": "lh...............", "node": ".t................"},
  { "name": "0",    "wave": "l..====4=0.......", "node": "...a..............", "data": "       b[0] b[1] b[2] b[3] ... b[n]",            "phase":0},
  { "name": "1",    "wave": "l..====4=0.......", "node": "...b..............", "data": "       b[0] b[1] b[2] b[3] ... b[n]",            "phase":-1},
  { "name": "2",    "wave": "x.3====4==30.....", "node": "...c..............", "data": "SoT    b[0] b[1] b[2] b[3] ... b[n]    CRC EoT", "phase":-1.5},
  { "name": "3",    "wave": "x35====4=5=30....", "node": "...d..............", "data": "SoT PH b[0] b[1] b[2] b[3] ... b[n] PF CRC EoT", "phase":-5}
  ],
  "edge": [
    "t~>a",
    "a~>b",
    "b~>c",
    "c~>d"
  ]
}

wavedrompy seems to collapse repeated whitespace as single delimiter:
image

WaveDrom parses repeated whitespace as empty strings:
image

A workaround appears to be to just use the undocumented feature of feeding data strings as an array instead of one large string. The below renders the same in both WaveDrom and wavedrompy (that is, the below renders the same as above only in wavedrompy):

{ "signal": [
  { "name": "trig", "wave": "lh...............", "node": ".t................"},
  { "name": "0",    "wave": "l..====4=0.......", "node": "...a..............", "data": [             "b[0]", "b[1]", "b[2]", "b[3]", "...", "b[n]"],                     "phase":0},
  { "name": "1",    "wave": "l..====4=0.......", "node": "...b..............", "data": [             "b[0]", "b[1]", "b[2]", "b[3]", "...", "b[n]"],                     "phase":-1},
  { "name": "2",    "wave": "x.3====4==30.....", "node": "...c..............", "data": ["SoT",       "b[0]", "b[1]", "b[2]", "b[3]", "...", "b[n]",       "CRC", "EoT"], "phase":-1.5},
  { "name": "3",    "wave": "x35====4=5=30....", "node": "...d..............", "data": ["SoT", "PH", "b[0]", "b[1]", "b[2]", "b[3]", "...", "b[n]", "PF", "CRC", "EoT"], "phase":-5}
  ],
  "edge": [
    "t~>a",
    "a~>b",
    "b~>c",
    "c~>d"
  ]
}

Bottom of Group Bracket is Not Rendered

The bottom curve of the bracket for a group is not rendered.

svg = wavedrom.render("""
{ "signal": [
  {   "name": "clk",    "wave": "p..Pp..P"},
  ["Master",
    ["ctrl",
      {"name": "write", "wave": "01.0...."},
      {"name": "read",  "wave": "0...1..0"}
    ],
    {  "name": "addr",  "wave": "x3.x4..x", "data": "A1 A2"},
    {  "name": "wdata", "wave": "x3.x....", "data": "D1"   }
  ],
  {},
  ["Slave",
    ["ctrl",
      {"name": "ack",   "wave": "x01x0.1x"}
    ],
    {  "name": "rdata", "wave": "x.....4x", "data": "Q2"}
  ]
]}
""")

svg.saveas('demo1.svg')

Gives

image

Where WaveDrom Editor renders it ok:
image

Tested on both 1.8.0post4 and 1.8.0.post5.dev4+gc5e792a

First Letter of Header and Footer Text Is Truncated

The first letter of header and footer text is not rendered in the SVG. Adding a header and footer to the example in Readme.md as below reproduces the error.

import wavedrom
svg = wavedrom.render("""
{ "signal": [
 { "name": "CK",   "wave": "P.......",                                              "period": 2  },
 { "name": "CMD",  "wave": "x.3x=x4x=x=x=x=x", "data": "RAS NOP CAS NOP NOP NOP NOP", "phase": 0.5 },
 { "name": "ADDR", "wave": "x.=x..=x........", "data": "ROW COL",                     "phase": 0.5 },
 { "name": "DQS",  "wave": "z.......0.1010z." },
 { "name": "DQ",   "wave": "z.........5555z.", "data": "D0 D1 D2 D3" }
],
"head":{
    "text": "WaveDrom example"
},
"foot":{
    "text": "Figure 100"
}
}""")
svg.saveas("demo1.svg")

Gives

            <text fill="#000" text-anchor="middle" x="320.0" xml:space="preserve" y="-33">
                <tspan>a</tspan>
                <tspan>v</tspan>
                <tspan>e</tspan>
                <tspan>D</tspan>
                <tspan>r</tspan>
                <tspan>o</tspan>
                <tspan>m</tspan>
                <tspan>
                </tspan>
                <tspan>e</tspan>
                <tspan>x</tspan>
                <tspan>a</tspan>
                <tspan>m</tspan>
                <tspan>p</tspan>
                <tspan>l</tspan>
                <tspan>e</tspan>
            </text>

image

demo1.svg generated above attached in full: demo1.zip

Gap Placement With Phase is Different Between wavedrom and wavedrompy

wavedrom handles gap placement differently than wavedrompy:

{ "signal": [
  { "name": "trig", "wave": "lh......|.........", "node": ".t................"},
  { "name": "0",    "wave": "l..====4|=0.......", "node": "...a..............", "data": [             "b[0]", "b[1]", "b[2]", "b[3]", "...", "b[n]"],                     "phase":0},
  { "name": "1",    "wave": "l..====4|=0.......", "node": "...b..............", "data": [             "b[0]", "b[1]", "b[2]", "b[3]", "...", "b[n]"],                     "phase":-1},
  { "name": "2",    "wave": "x.3====4|==30.....", "node": "...c..............", "data": ["SoT",       "b[0]", "b[1]", "b[2]", "b[3]", "...", "b[n]",       "CRC", "EoT"], "phase":-1.5},
  { "name": "3",    "wave": "x35====4|=5=30....", "node": "...d..............", "data": ["SoT", "PH", "b[0]", "b[1]", "b[2]", "b[3]", "...", "b[n]", "PF", "CRC", "EoT"], "phase":-5}
  ],
  "edge": [
    "t~>a",
    "a~>b",
    "b~>c",
    "c~>d"
  ]
}

wavedrom:
wavedrom - Empty Name and Phase Check With Gap

wavedrompy:
wavedrompy - Latency Check With Gap

This is a use case that doesn't make much sense to me, so I'm not sure that this is a high priority bug. I'm not sure which of these implementations is actually favorable: A gap is mostly property of the horizontal axis: It's a break in time. It doesn't really make much sense for a gap to slide with phase.
The fact that a gap ignores phase seems correct.

However, a time skip at the same spot in each wave lane but at different spots in time is exactly what I wanted to convey. The way wavedrom does it is exactly what I wanted, but I've never seen a continuation that wasn't all the way down a timing diagram.

I eventually abandoned the idea of using a gap to communicate this timeskip, as the ellipsis does just fine.

bitfield rotate not working when installing from pypi

I find using the option "rotate: -90 " is useful when representing bitfields that are only 1 bit wide.
This works well when using the web editor, or the offline (windows) editor.

However, when using the renderer included in the pypi package, bitfield names are not rotated.
See below an example.

{ reg: [
{ name: "ADC_BM", bits: 3, attr: "rw", rotate: -90 },
{ name: "", bits: 1, attr: "r", rotate: -90 },
{ name: "ADC_ORDER", bits: 1, attr: "rw", rotate: -90 },
{ name: "DITHER_EN", bits: 1, attr: "rw", rotate: -90 },
{ name: "CHOP_EN", bits: 1, attr: "rw", rotate: -90 },
{ name: "INV_CLK", bits: 1, attr: "rw", rotate: -90 },
], config: { vspace: 200 } }

Cannot install from local source

Hi,

I tried to install the wavedrompy package locally from /wavedrompy-master I downloaded.

I cannot access to the repository online because of restrictions on my machine.

It seems that pip cannot access to the following library :

artifactory/api/pypi/python-pypipythonorg-remote/simple/setuptools-scm/

Here is the following command I tried, following the indication for local install (https://packaging.python.org/en/latest/tutorials/installing-packages/#installing-from-local-archives ) :

$ C:\Users\USER\Downloads\wavedrompy-master\wavedrompy-master> python -m pip install --no-index --find-links C:\Users\USER\Downloads\wavedrompy-master\wavedrompy-master .

The installation starts :

Looking in links: c:\Users\USER\Downloads\wavedrompy-master\wavedrompy-master
Processing c:\users\USER\downloads\wavedrompy-master\wavedrompy-master

and eventually I receive the failed message :

    ERROR: Command errored out with exit status 1:
     command: 'C:\XXXX\python-3.8.5.amd64\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\USER\\AppData\\Local\\Temp\\pip-req-build-2u
mepr8u\\setup.py'"'"'; __file__='"'"'C:\\Users\\USER\\AppData\\Local\\Temp\\pip-req-build-2umepr8u\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'
"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\USER\AppData\Local\Temp\pip-pip-egg-info-i5sq93ww'
         cwd: C:\Users\USER\AppData\Local\Temp\pip-req-build-2umepr8u\
    Complete output (37 lines):
    WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] cert
ificate verify failed: certificate has expired (_ssl.c:1123)'))': /artifactory/api/pypi/python-pypipythonorg-remote/simple/setuptools-scm/
    WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] cert
ificate verify failed: certificate has expired (_ssl.c:1123)'))': /artifactory/api/pypi/python-pypipythonorg-remote/simple/setuptools-scm/
    WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] cert
ificate verify failed: certificate has expired (_ssl.c:1123)'))': /artifactory/api/pypi/python-pypipythonorg-remote/simple/setuptools-scm/
    WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] cert
ificate verify failed: certificate has expired (_ssl.c:1123)'))': /artifactory/api/pypi/python-pypipythonorg-remote/simple/setuptools-scm/
    WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] cert
ificate verify failed: certificate has expired (_ssl.c:1123)'))': /artifactory/api/pypi/python-pypipythonorg-remote/simple/setuptools-scm/
    ERROR: Could not find a version that satisfies the requirement setuptools_scm (from versions: none)
    ERROR: No matching distribution found for setuptools_scm
    Traceback (most recent call last):
      File "C:\XXXX\python-3.8.5.amd64\lib\site-packages\setuptools\installer.py", line 128, in fetch_build_egg
        subprocess.check_call(cmd)
      File "C:\XXXX\python-3.8.5.amd64\lib\subprocess.py", line 364, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['C:\\XXXX\\python-3.8.5.amd64\\python.exe', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 'C:\\Us
ers\\USER\\AppData\\Local\\Temp\\tmphs9yb8ho', '--quiet', 'setuptools_scm']' returned non-zero exit status 1.
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\USER\AppData\Local\Temp\pip-req-build-2umepr8u\setup.py", line 28, in <module>
        setup(
      File "C:\XXXX\python-3.8.5.amd64\lib\site-packages\setuptools\__init__.py", line 162, in setup
        _install_setup_requires(attrs)
      File "C:\XXXX\python-3.8.5.amd64\lib\site-packages\setuptools\__init__.py", line 157, in _install_setup_requires
        dist.fetch_build_eggs(dist.setup_requires)
      File "C:\XXXX\python-3.8.5.amd64\lib\site-packages\setuptools\dist.py", line 699, in fetch_build_eggs
        resolved_dists = pkg_resources.working_set.resolve(
      File "C:\XXXX\python-3.8.5.amd64\lib\site-packages\pkg_resources\__init__.py", line 779, in resolve
        dist = best[req.key] = env.best_match(
      File "C:\XXXX\python-3.8.5.amd64\lib\site-packages\pkg_resources\__init__.py", line 1064, in best_match
        return self.obtain(req, installer)
      File "C:\XXXX\python-3.8.5.amd64\lib\site-packages\pkg_resources\__init__.py", line 1076, in obtain
        return installer(requirement)
      File "C:\XXXX\python-3.8.5.amd64\lib\site-packages\setuptools\dist.py", line 758, in fetch_build_egg
        return fetch_build_egg(self, req)
      File "C:\XXXX\python-3.8.5.amd64\lib\site-packages\setuptools\installer.py", line 130, in fetch_build_egg
        raise DistutilsError(str(e)) from e
    distutils.errors.DistutilsError: Command '['C:\\XXXX\\python-3.8.5.amd64\\python.exe', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 'C:\\
Users\\USER\\AppData\\Local\\Temp\\tmphs9yb8ho', '--quiet', 'setuptools_scm']' returned non-zero exit status 1.
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

I am quite new to dealing with packages and dependencies... Do you have any indication to provide me in order to make an environnement self-content and install the package ?

Thank you very much,

Gautier

Issue with period=0.5

Given the following json

{
    "signal": [
            {"name": "sig", "wave": "x=...=...................=.....", "data": ["clock", "byte 0", "byte 1"]},
            {"name": "bit", "wave": "================", "data": ["","","","start",0,1,2,3,4,5,6,7,"stop", "start",0,1], "period": 2, "phase": 1},
            {"name": "bus", "wave": "h.nh.nh.l..hlx.hlx.hlx.hlx.hlx.hlx.hlx.hlx.hnh.l..hlx.hlx.h", "period": 0.5},
            {"name": "Data Link Layer", "wave": "0..............................................50.............", "period": 0.5}
        ],
        "foot": {
            "tock": 0
        },
        "config": { "hscale": 1 }
}

wavedrom produces this result:
wavedrom

But wavedrompy produces this:
wavedrompy

Could this have something to do with the fact that period is a decimal number?

Ticks Not Rendered Correctly

I was trying to create a test step where the SVGs from wavedrom and wavedrompy are rasterized and compared and noticed a difference: the tick marks come out very slightly wrong. It's almost like the alpha for edges and the alpha for the fill of data regions are not the same between wavedrom and wavedrompy, or alphas are same and drawing order is different. When rasterized, the differences are only in the RGB channels, though The alpha channels match.

The differences in the below images have been enhanced (via PIL.ImageOps.autocontrast)

issue_14.json differences:
issue_14_noAlphaDiff
Original overlayed on difference:
issue_14_differenceAndOriginalComposed

tutorial_1.json differences:
tutorial_1_noAlphaDiff
Original overlayed on differences:
tutorial_1_differenceAndOriginalComposed

I'll generate the rest of these images and push them to the scratch branch of my fork tomorrow evening.

Piecewise signal support

Hi wavedrompy team,
I am trying to compile code with the recently added "pw" (piecewise) keyword used for signals but I get this error:

TypeError: unhashable type: 'dict'

The code piece is the following:

import wavedrom
svg = wavedrom.render("""
{"signal": [
  {"name": "clock",    "wave": "p......."},
  {"name": "sawtooth", "wave": ["pw", {"d": ["m",1,0, "l",2,1, "v",-1, "l",2,1, "v",-1]}]},
  {"name": "triangle", "wave": ["pw", {"d": "m,0,0  l,2,1  l,2,-1  l,2,1  l,2,-1"}]},
  {"name": "RC", "wave": ["pw", {"d": "m,0,0 q,.5,1,1,1 h,1 q,.5,-1,1,-1 h,1 q,.5,1,1,1 h,1"}]},
  {"name": "sin", "wave": ["pw", {"d": "m,0,.5 q,.25,1,.5,0 t,.5,0,.5,0,.5,0,.5,0,.5,0,.5,0,.5,0,.5,0,.5,0,.5,0,.5,0,.5,0,.5,0,.5,0,.5,0"}]}
]}
""")
svg.saveas("demo_pw.svg")

Are you planning to release a new update soon with this feature and probably other recent features like "label" for registers?
Thanks in advance!

Use Conda for Test Environments

I just submitted pull request #23 to use tox for testing. I would like to build on that and use tox-conda. It would make it much easier to test across operating systems and allow new contributors to run tests locally with ease. It would also fully contain the node, npm, and git tools used in testing: It would not rely on the system installations. It also allows cairosvg to work with Windows. Tests would still be run by pytest, but conda would do all the dependency management for the test environment.

The test command would be similar to the pull request: just tox-conda instead of tox' . I would just add the nodejs and git packages to the conda dependencies.

The only downside I see is this would make miniconda a dependency for mutli-environment testing. venv and plain tox testing should still work without conda.

Edit: I got it working sooner than I expected. See PR #25.

deprecated attrdict and PyPi version

Hello,

I'm using wavedrompy in my mkdocs project, in a very satisfactory way, thanks for the nice work 🙏.

However, I started to have a crash recently, that is due to the combination of python3.10 upgrade and the attrdict dependency. With this error : cannot import name 'Mapping' from 'collections'

I saw here that the issue has been address with some workaround in 05b1220. However, it is not updated on PyPi yet.

I quickly tested the master branch, and seems to work fine. Is there any plan to release a new version on PyPi ? Is there anything preventing the said release ?

Incorrect behavior for bold title and invalid SVG output

The JSON below doesn't produce the same output as wavedrom tool. When converting the SVG to PDF format with cairosvg in GitLab CI using a docker image the following Exception is raised and a blank canvas in PDF is generated:

wavedrompy: screenshot 15
wavedrom: screenshot 16

{
    "signal": [
        {
            "wave": "|nh....nh.nhn.xnhnh..|."
        },
        {
            "wave": "x=.....=..=..x|=.=...=.",
            "data": [
                "Calib.",
                "Stat./Comm.",
                "N data nibbles",
                "CRC",
                "Pause",
                "Calib."
            ]
        },
        {
            "node": "...................1.2."
        }
    ],
    "edge": [
        "1<->2 Interrupt"
    ],
    "head": {
        "text": [
            "tspan",
            [
                "tspan",
                {
                    "font-weight": "bold"
                },
                "SENT message signal timing diagram"
            ]
        ]
    }
}
Exception occurred:
  File "/usr/local/lib/python3.7/dist-packages/cairosvg/parser.py", line 419, in __init__
    'No tag with id="{}" found.'.format(element_id))
TypeError: No tag with id="|||" found.

When the cariosvg Exception is not raised (during a local build in docer), I end up with the following conversion to PDF:
invalid_diagram

To me this looks related to bavovanachte/sphinx-wavedrom#13. Can I expect a fix soon or should I resort to other means for the time being?

bitfield which covers three or more lanes does not work in mid-lanes.

"config":{ "bits":32 },
"reg": [ {"name":"FIELD_1","bits":8}, {"bits":24} ] }

The bit 23:16 have to be gray but remains in white color.

The labelArr function need to be modified as below

        if floor(e["lsb"] / self.mod) < self.index and \
            floor(e["msb"] / self.mod) > self.index:
            lsb = self.index*self.mod
            msb = (self.index + 1)*self.mod - 1
        elif floor(e["lsb"] / self.mod) == self.index:
            lsbm = e["lsbm"]
            lsb = e["lsb"]
            if floor(e["msb"] / self.mod) == self.index:
                msb = e["msb"]
                msbm = e["msbm"]
        elif floor(e["msb"] / self.mod) == self.index:
            msb = e["msb"]
            msbm = e["msbm"]
        else:
            continue

Lanes for Regs Discrepancy between Editor and Py version

Dear Stefan,
I see some differences between editor and python version. Do you have any clue where this could come from ?
Here a very simple register definition I used and the pictures generated are different, I noticed also that in the editor code 0 and 1 give a gray color where only code 1 gives gray for Py.

svg = wavedrom.render("""{"reg":[{"name":"rsv","attr":["RSV"],"bits":7,"type":1},{"name":"FDMA_EN","bits":1}],"config":{"bits":8,"lanes":1}}""")

Editor rendering:
wave_editor
Py rendering:
wave_python
Scaling might also be an issue in Py.
Best regards,
Dan

Support newer bitfield options from upstream WaveDrom (vflip, hflip, compact)

I see in the wavedrompy code that there is the bigendian option, but looking at wavedrom issue 22 they instead implemented vflip hflip to change the order of bits. I am using this package along with sphinxcontrib-wavedrom to try and document some network protocols, but am unable to get good renders like I get with the wavedrom editor.

Also the compact option makes for much better looking network packet illustrations 😄

“<” triggers IndexError: deque index out of range

Consider the following source code:

{"signal": [
    {"name": "clk_i",   "wave": "P.......", "phase": 1.0 },
    {"name": "reset_i", "wave": "1.0...1" },
    {"name": "in_i",    "wave": "=....==<", "phase": 0.5, "data": "0 1 0" },
    {"name": "state_p", "wave": "=.=====", "data": "00 01 10 11 10|00 00" },
    {"name": "state_n", "wave": "=.=====", "data": "01 10 11 00|10 00|01 01"},
    {"name": "out_o",   "wave": "=.=====", "data": "11 10 00 10 00|11 11"}
  ],
  "config": { "hscale": 1 },
  "head": { "tick": 0 }
}

This works just fine in the editor. Now, let us try the same source code in wavedrompy:

Traceback (most recent call last):
  File "/usr/local/bin/wavedrompy", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/wavedrom/__init__.py", line 63, in main
    render_write(args.input, args.svg, False)
  File "/usr/local/lib/python3.8/dist-packages/wavedrom/__init__.py", line 47, in render_write
    out = render(jinput, strict_js_features=strict_js_features)
  File "/usr/local/lib/python3.8/dist-packages/wavedrom/__init__.py", line 38, in render
    return WaveDrom().render_waveform(0, source, output, strict_js_features)
  File "/usr/local/lib/python3.8/dist-packages/wavedrom/waveform.py", line 793, in render_waveform
    content = self.parse_wave_lanes(ret.lanes)
  File "/usr/local/lib/python3.8/dist-packages/wavedrom/waveform.py", line 196, in parse_wave_lanes
    sub_content.append(self.parse_wave_lane(sigx["wave"], self.lane.period * self.lane.hscale - 1))
  File "/usr/local/lib/python3.8/dist-packages/wavedrom/waveform.py", line 160, in parse_wave_lane
    if Stack[0] in ['.', '|']:
IndexError: deque index out of range

As far as I can see, this is related to the “<” character.

Labels Only Placed At Whole and Half Phases

Edge labels are placed where an edge would be for a whole and half phase, instead of being placed where the edge actually is after phase shifting.

For the below JSON only labels "a", "f", and "k" are placed correctly:

{ "signal": [
  { "name": "0",   "wave": "lh", "node": ".a", "phase":0},
  { "name": "0.1", "wave": "lh", "node": ".b", "phase":-0.1},
  { "name": "0.2", "wave": "lh", "node": ".c", "phase":-0.2},
  { "name": "0.3", "wave": "lh", "node": ".d", "phase":-0.3},
  { "name": "0.4", "wave": "lh", "node": ".e", "phase":-0.4},
  { "name": "0.5", "wave": "lh", "node": ".f", "phase":-0.5},
  { "name": "0.6", "wave": "lh", "node": ".g", "phase":-0.6},
  { "name": "0.7", "wave": "lh", "node": ".h", "phase":-0.7},
  { "name": "0.8", "wave": "lh", "node": ".i", "phase":-0.8},
  { "name": "0.9", "wave": "lh", "node": ".j", "phase":-0.9},
  { "name": "1",   "wave": "lh", "node": ".k", "phase":-1}
  ],
  "edge": [
    "a-b",
    "b-c",
    "c-d",
    "d-e",
    "e-f",
    "f-g",
    "g-h",
    "h-i",
    "i-j",
    "j-k"
  ]
}

WaveDromPy:
image

WaveDrom:
image

Data Labels Misaligned, Depending on Maximum Phase of signal

With d570c47, data labels are all shifted a little bit based on the most extreme phase shift. This wasn't an issue before, so I'll roll back through the commits to see which introduced this.

{ "signal": [
  { "name": "0",   "wave": "lh===...........", "node": "..a", "data": ["abcd", "1234"], "phase":0},
  { "name": "0.1", "wave": "lh===...........", "node": "..b", "data": ["abcd", "1234"], "phase":-0.1},
  { "name": "0.2", "wave": "lh===...........", "node": "..c", "data": ["abcd", "1234"], "phase":-0.2},
  { "name": "0.3", "wave": "lh===...........", "node": "..d", "data": ["abcd", "1234"], "phase":-0.3},
  { "name": "0.4", "wave": "lh===...........", "node": "..e", "data": ["abcd", "1234"], "phase":-0.4},
  { "name": "0.5", "wave": "lh===...........", "node": "..f", "data": ["abcd", "1234"], "phase":-0.5},
  { "name": "0.6", "wave": "lh===...........", "node": "..g", "data": ["abcd", "1234"], "phase":-0.6},
  { "name": "0.7", "wave": "lh===...........", "node": "..h", "data": ["abcd", "1234"], "phase":-0.7},
  { "name": "0.8", "wave": "lh===...........", "node": "..i", "data": ["abcd", "1234"], "phase":-0.8},
  { "name": "0.9", "wave": "lh===...........", "node": "..j", "data": ["abcd", "1234"], "phase":-0.9},
  { "name": "10",  "wave": "lh===...........", "node": "..k", "data": ["abcd", "1234"], "phase":-10}
  ],
  "edge": [
    "a-b",
    "b-c",
    "c-d",
    "d-e",
    "e-f",
    "f-g",
    "g-h",
    "h-i",
    "i-j",
    "j-k"
  ]
}

Renders as:
image

To show the dependency on the phase:
demo+5
demo-0
demo-5
demo-10

I used the below as a template to render the tests:

import cairosvg, wavedrom

svg = wavedrom.render("""
{ "signal": [
  { "name": "+5",  "wave": "l.....h===...........", "node": "........k", "data": ["abcd", "1234"], "phase":5}
  ]
}
""")

svg.saveas('demo+5.svg')

cairosvg.svg2png(svg.tostring(), write_to='.\demo+5.png', output_width=920, output_height=30)

Register rendering options data format

Hi there!

Just to document the options:

import wavedrom

data = """
{"reg":
  [
    { "name":"IO_MODE",         "bits":7, "attr": "RW"},
    { "name":"NS_ACCESS_GPIO",  "bits":1, "attr": "RW"},
    { "name":"PULL_CTRL",       "bits":2, "attr": "RW"},
    { "name":"LPF",             "bits":1, "attr": "RW"},
    {                           "bits":1              },
    { "name":"DRIVE",           "bits":2, "attr": "RW"},
    {                           "bits":18             }
  ],
 "config": {"fontsize":6}
}
"""

svg = wavedrom.render(data)

svg.saveas("demo3.svg")

The available parameters are defined in the bitfield.Options constructor:

class Options:
    def __init__(self, vspace=80, hspace=800, lanes=1, bits=32, fontsize=14, bigendian=False, fontfamily='sans-serif',
                 fontweight='normal'):

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.