Skip to content

🐛 accept decimal period, pulse and offset for timing clock - #2714

Merged
arnaudroques merged 1 commit into
plantuml:masterfrom
IgniparousTempest:add/2711-decimal-clock-period-offset
May 26, 2026
Merged

arnaudroques merged 1 commit into
plantuml:masterfrom
IgniparousTempest:add/2711-decimal-clock-period-offset

Conversation

@IgniparousTempest

Copy link
Copy Markdown
Contributor

#2711

The CommandClock regex only matched integer values for the clock's period, pulse and offset, so

clock "MyClock" as Clk with period 12.5 offset 0.1

failed to parse. The downstream rendering code (PanelsClock, Panels.xOfTime, drawHorizontalBetweenTimes) already operates on doubles, so the values were being constrained needlessly at the parser level.

Allow decimals in the regex and propagate the values as double through PlayerClock, PanelsClock and TimingDiagram.createPlayerClock / getClockValue. BigDecimal.valueOf(double) is used in place of new BigDecimal(double) to avoid binary-precision noise.

Adds a non-regression test reproducing the original bug report.

Closes #2711

@arnaudroques

arnaudroques commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for your PR!

I have two points:

  1. instead of changing code from int to double, could you rather move directly from int to BigDecimal?
	private final BigDecimal period;
	private final BigDecimal pulse;
	private final BigDecimal offset;
  1. About test, it's great that you have provide some of them.

However, we are moving to a better & simplier way.
It's not documented yet, but you'll find an example here:

https://github.com/plantuml/plantuml/blob/master/src/test/resources/vega/mvp/hello-both.puml

You just have to create a new .puml file somewhere in the "vega" tree structure (you can even create folder).
In the YAML header, you write a few lines, with the output format and the expected-description.
Something like:

---
output: svg, debug
expected-description: (Timing Diagram)
---
@startuml
clock "MyClock" as Clk with period 12.5 offset 0.1
binary "State" as B

@0
B is low

@10.5
B is high

@enduml

When you run test for the first time, a .txt or/and .svg file will be created for you.
This will be the expected result for future tests.

Does it sound good to you?

@arnaudroques
arnaudroques force-pushed the master branch 2 times, most recently from d5585b6 to 81081ac Compare May 23, 2026 10:53
@IgniparousTempest
IgniparousTempest force-pushed the add/2711-decimal-clock-period-offset branch from 28c2d73 to cf81563 Compare May 26, 2026 16:08
plantuml#2711

The CommandClock regex only matched integer values for the clock's
period, pulse and offset, so

    clock "MyClock" as Clk with period 12.5 offset 0.1

failed to parse. The downstream rendering code (PanelsClock, Panels.xOfTime,
drawHorizontalBetweenTimes) already operates on doubles, so the values were
being constrained needlessly at the parser level.

Allow decimals in the regex and propagate the values as double through
PlayerClock, PanelsClock and TimingDiagram.createPlayerClock /
getClockValue. BigDecimal.valueOf(double) is used in place of
new BigDecimal(double) to avoid binary-precision noise.

Adds a non-regression test reproducing the original bug report.

Closes plantuml#2711
@IgniparousTempest
IgniparousTempest force-pushed the add/2711-decimal-clock-period-offset branch from cf81563 to 5a55200 Compare May 26, 2026 16:24
@IgniparousTempest

Copy link
Copy Markdown
Contributor Author

Done

@arnaudroques
arnaudroques merged commit b94e49b into plantuml:master May 26, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decimals in clock not working in timing diagram

2 participants