anubicharts 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DERIVAZIONE.md +33 -0
- package/LICENSE +201 -0
- package/NOTICE +21 -0
- package/README.md +119 -2
- package/package.json +35 -4
- package/src/bars.js +197 -0
- package/src/gl.js +361 -0
- package/src/glprim.js +340 -0
- package/src/glx.js +308 -0
- package/src/lod.js +342 -0
- package/src/logo.js +25 -0
- package/src/lw-data.js +271 -0
- package/src/lw.js +1844 -0
- package/src/pricescale.js +183 -0
- package/src/timescale.js +97 -0
- package/src/timeticks.js +229 -0
package/DERIVAZIONE.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Derivation from Lightweight Charts, function by function (2026-11-10)
|
|
2
|
+
|
|
3
|
+
(The file name is kept from the original Italian version; the content below is the English translation.)
|
|
4
|
+
|
|
5
|
+
This file lists, for each part of the engine, whether it is original, was rewritten from pixel measurements of Lightweight Charts (LW), or
|
|
6
|
+
is still treated as a derived work of Lightweight Charts (Apache-2.0). Sources: the maintainers' internal measurement notes and two
|
|
7
|
+
reviews done by AI (Claude) sessions. "Status" is the verdict of the second review, updated after the fixes that followed it.
|
|
8
|
+
|
|
9
|
+
| Part | File | Declared status |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| Public interface (createChart, series, scales, panes, primitives, markers) | `lw.js` | **Follows the LW API** for compatibility (a documented interface) |
|
|
12
|
+
| `candleWidth`, `bodyShare` | `bars.js` | `bodyShare` is a table of 81 measured thresholds with interpolation (no formula); the case structure of `candleWidth` (fixed zone, parity) is similar to the original: **inspired** |
|
|
13
|
+
| `candleParts`, `candleRects` | `bars.js` | **Derived/inspired**: same order of passes, same wick and border rule (measured on pixels, but they coincide with the original's structure); text rewritten |
|
|
14
|
+
| `barWidth`, `barParts`, `barRects` | `bars.js` | Width re-expressed from measurements; tick threshold and ticks inside the stem equal to the original: **inspired** |
|
|
15
|
+
| `histGap`, `histColumns` | `bars.js` | **Derived/inspired**: gap, narrowing below 4 px and side choice coincide with the original |
|
|
16
|
+
| Histogram heights | `lw.js` `drawHistogram` | **Derived** (a few lines of arithmetic equal to the original) |
|
|
17
|
+
| `pointMarker` | `bars.js` | Radius and centre measured over 36 combinations; half-pixel correction in the odd case: **inspired** |
|
|
18
|
+
| `priceAxisWidth`, `timeAxisHeight`, `crossPriceLabel`, `crossTimeLabel`, `timeTickMinDist` | `lw.js` | Lines and formulas fitted to measurements (fixtures): **measured** |
|
|
19
|
+
| `measureAxis` | `lw.js` | Rewritten from measurements after the second review (all grid labels, no constants from the original source): **measured** |
|
|
20
|
+
| `niceStep`, `priceTicks`, `minMove` rule | `pricescale.js` | Table of steps measured, different algorithm; steps with `minMove` derived from 190 pixel comparisons: **measured** |
|
|
21
|
+
| `weightOf`, `TickIndex.pick`, time filling | `timeticks.js`, `lw.js` | Year, month, day, hour scheme common to every time axis; single level and filling measured with `tickMarkFormatter`: **measured/inspired** |
|
|
22
|
+
| `updateBase` (last-bar rule) | `lw.js` | Behaviour documented by the API (`shiftVisibleRangeOnNewBar`), threshold measured (rightOffset greater than -1): **measured** |
|
|
23
|
+
| Long press at 240 ms | `lw.js` `onDown` | Same value as LW, measured with synthetic events: **measured** |
|
|
24
|
+
| `dashPhases`, `dashOrigin` | `glx.js`, `lw.js` | Dash phase observed and verified over 72 combinations: **measured** |
|
|
25
|
+
| LOD (pyramid), GPU packets, WebGL (`gl*.js`, `glprim.js`), script primitives, interaction | various | Original work by AnubiAI |
|
|
26
|
+
|
|
27
|
+
All parts marked "derived/inspired" must be treated as derived works of Lightweight Charts (Apache-2.0): they keep the copyright and
|
|
28
|
+
license notice and the attribution note (see `NOTICE`).
|
|
29
|
+
|
|
30
|
+
The measurement fixtures used by the tests are in `test/fixtures/`: they contain numbers measured on LW's rendered output (pixel positions
|
|
31
|
+
and sizes), not LW source code.
|
|
32
|
+
|
|
33
|
+
This is **not** a clean-room implementation and no clean-room claim is made.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2023 TradingView, Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
AnubiCharts, the AnubiQuant chart engine
|
|
2
|
+
Copyright (c) 2026 AnubiAI (anubiai.com)
|
|
3
|
+
|
|
4
|
+
This product contains parts derived from, or inspired by, TradingView Lightweight Charts(TM)
|
|
5
|
+
Copyright (c) 2025 TradingView, Inc. (https://www.tradingview.com/), distributed under the Apache License 2.0.
|
|
6
|
+
The text of the license is in the LICENSE file of this directory.
|
|
7
|
+
|
|
8
|
+
The public interface (createChart, addSeries, timeScale, priceScale, panes, primitives, markers, names and default values of the
|
|
9
|
+
documented options) follows the Lightweight Charts v5 API for compatibility.
|
|
10
|
+
|
|
11
|
+
The geometry and behaviour parts (candle and bar widths, histogram columns, ticks, point markers, crosshair labels, last-bar rule,
|
|
12
|
+
choice of time labels, grid steps, scale widths) were rewritten by looking at the pixels produced by Lightweight Charts rather than by
|
|
13
|
+
copying its code, but a strict clean room is NOT claimed: the people who wrote them already knew the algorithms, and a second
|
|
14
|
+
independent review (see DERIVAZIONE.md) judged some of them derived. The function-by-function list is in DERIVAZIONE.md.
|
|
15
|
+
|
|
16
|
+
As requested by Lightweight Charts, whoever shows a chart built with this library must display, in a visible place (for example an
|
|
17
|
+
"About and credits" page), the attribution notice to TradingView with a link to https://www.tradingview.com/.
|
|
18
|
+
|
|
19
|
+
Lightweight Charts is a trademark of TradingView, Inc. This project is not affiliated with or endorsed by TradingView, Inc.
|
|
20
|
+
|
|
21
|
+
The rest of the code (level of detail, data pyramid, WebGL drawing, script primitives, interaction) is original work by AnubiAI.
|
package/README.md
CHANGED
|
@@ -1,3 +1,120 @@
|
|
|
1
|
-
#
|
|
1
|
+
# AnubiCharts
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A WebGL2 chart renderer for financial time series (candles, bars, lines, areas, histograms, multiple panes) with an API
|
|
4
|
+
**compatible with TradingView Lightweight Charts v5** (`createChart`, `addSeries`, `timeScale`, `priceScale`, `panes`, primitives, markers).
|
|
5
|
+
Made by [AnubiAI](https://anubiai.com); it is the chart engine of our trading platform, AnubiQuant. License: **Apache-2.0**.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
> Status: early (0.1.0). It is not a full replacement for Lightweight Charts: see *Known limits*.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
npm install anubicharts
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Plain ES modules, no dependencies, no build step of its own; use it with a bundler (Vite, webpack, esbuild…) or any setup that resolves
|
|
18
|
+
bare imports. It needs a browser with **WebGL2** (available in current Chrome, Edge, Firefox and Safari); there is no Canvas fallback. So far it has been tested in Chrome only.
|
|
19
|
+
|
|
20
|
+
## Quick start
|
|
21
|
+
|
|
22
|
+
```html
|
|
23
|
+
<div id="chart" style="width:800px;height:400px"></div>
|
|
24
|
+
<script type="module">
|
|
25
|
+
import { createChart, CandlestickSeries } from anubicharts;
|
|
26
|
+
const chart = createChart(document.getElementById('chart'), { autoSize: true });
|
|
27
|
+
const series = chart.addSeries(CandlestickSeries, {});
|
|
28
|
+
series.setData([{ time: 1700000000, open: 1, high: 2, low: 0.5, close: 1.5 } /* ... */]);
|
|
29
|
+
</script>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
To try it from a clone instead, import `./src/lw.js` as the examples do, and serve the folder with any static server (ES modules do not
|
|
33
|
+
load from `file://`), for example `python -m http.server`:
|
|
34
|
+
|
|
35
|
+
- `examples/basic.html`: 20,000 candles with volume.
|
|
36
|
+
- `examples/benchmark.html`: pan and zoom tests for each engine (see *Performance*).
|
|
37
|
+
- `examples/solo.html`: one engine per page with a live frame counter (`?engine=aq|lw`, `?mode=zoom`, `?vis=3000`, `?w=940`).
|
|
38
|
+
- `examples/compare.html`: the two engines side by side, panned in the same animation frame.
|
|
39
|
+
|
|
40
|
+
The Anubi mark is shown at the bottom-left of the first pane, like the logo of Lightweight Charts; turn it off with `layout: { attributionLogo: false }`.
|
|
41
|
+
|
|
42
|
+
## Coming from Lightweight Charts
|
|
43
|
+
|
|
44
|
+
Change the import and keep the rest:
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
// before
|
|
48
|
+
import { createChart, CandlestickSeries } from 'lightweight-charts';
|
|
49
|
+
// after
|
|
50
|
+
import { createChart, CandlestickSeries } from 'anubicharts';
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Provided: `createChart`; the series `CandlestickSeries`, `BarSeries`, `LineSeries`, `AreaSeries`, `BaselineSeries`, `HistogramSeries`;
|
|
54
|
+
`createSeriesMarkers`; `timeScale()`, `priceScale()`, `panes()`, primitives, price lines, crosshair and `takeScreenshot`; the enums
|
|
55
|
+
`LineStyle`, `LineType`, `CrosshairMode`, `PriceScaleMode`, `ColorType`, `LastPriceAnimationMode`, `PriceLineSource`, `TickMarkType`,
|
|
56
|
+
`MismatchDirection`, `TrackingModeExitMode`; and `isBusinessDay` / `isUTCTimestamp`. Not provided: custom series and the other chart types
|
|
57
|
+
(`createChartEx`, yield curve, options charts) and the watermark plugins. A few visual details differ, see *Known limits*.
|
|
58
|
+
|
|
59
|
+
## How it works
|
|
60
|
+
|
|
61
|
+
Series data is stored in columns with a level-of-detail pyramid (min/max of any range in O(log n)). Candles and lines are uploaded to
|
|
62
|
+
the GPU once, and panning and zooming are done with uniforms, so scrolling does not rewrite buffers. One WebGL canvas serves all panes.
|
|
63
|
+
|
|
64
|
+
## Performance
|
|
65
|
+
|
|
66
|
+
Measured against the **stock** Lightweight Charts 5.2.1, one engine per page (`examples/solo.html`), 20,000 candles + 37 moving averages,
|
|
67
|
+
Chrome on Windows, the integrated Intel UHD 630 (the GPU the browser used on this machine):
|
|
68
|
+
|
|
69
|
+
| Display / chart width / visible bars | AnubiCharts | Lightweight Charts 5.2.1 |
|
|
70
|
+
|---|---|---|
|
|
71
|
+
| 144 Hz, 940 px, 3000 bars: pan | 6.9 ms/frame (145 fps) | 27.8 ms/frame (36 fps) |
|
|
72
|
+
| 144 Hz, 940 px, 3000 bars: zoom 600-3000 | 6.9 ms/frame (145 fps) | 27.7 ms/frame (36 fps) |
|
|
73
|
+
| 144 Hz, 470 px, 3000 bars: pan or zoom | 6.9 ms/frame (145 fps) | 13.9 ms/frame (72 fps) |
|
|
74
|
+
| 144 Hz, full-width page, 600 bars: pan (`benchmark.html`) | 6.9 ms/frame | 13.9 ms/frame (p95 20.8 ms) |
|
|
75
|
+
| **60 Hz**, 761 px, 3000 bars: pan | 16.7 ms/frame (60 fps, no frame over 20 ms) | 33.4 ms/frame (30 fps, p95 50.2 ms) |
|
|
76
|
+
|
|
77
|
+
Numbers are medians of the interval between animation frames, i.e. what the browser produces. AnubiCharts sits at the refresh period of the
|
|
78
|
+
display, so it cannot show less than that. The advantage depends on how much there is to draw (width, visible bars, number of series).
|
|
79
|
+
This is **one machine and one scenario**. On a phone with a 144 Hz display AnubiCharts ran at 144 fps (informal check, not measured with
|
|
80
|
+
the benchmark page).
|
|
81
|
+
|
|
82
|
+
The videos replay the 144 Hz timings of each engine in slow motion (x0.25); they are rebuilt from the measured frame timings, not screen
|
|
83
|
+
recordings (MP4 versions: `docs/compare-fps.mp4`, `docs/compare-zoom.mp4`).
|
|
84
|
+
|
|
85
|
+

|
|
86
|
+
|
|
87
|
+

|
|
88
|
+
|
|
89
|
+
**Measure it yourself.** Open `examples/benchmark.html` over HTTP and run the pan and zoom tests for each engine. The page loads
|
|
90
|
+
**unmodified** Lightweight Charts 5.2.1 from a CDN, uses the same deterministic data for both, and reports the median, 95th percentile and
|
|
91
|
+
maximum frame interval plus your GPU and browser. Run each engine several times and ignore the first run. With monitors of different
|
|
92
|
+
refresh rates, set the one you test on as the primary display: on a 60 Hz monitor next to a 144 Hz one, Chrome on Windows kept reporting
|
|
93
|
+
about 143 frames per second while the screen showed 60. We would love numbers from other GPUs and from real phones (open an issue).
|
|
94
|
+
|
|
95
|
+
## Tests
|
|
96
|
+
|
|
97
|
+
`npm test` runs 28 tests (Node 18+, no dependencies) on the pure parts: candle, bar and histogram geometry against measurements of
|
|
98
|
+
Lightweight Charts' rendered output (`test/fixtures/`), price and time scales, tick selection, the data pyramid and the dash phase.
|
|
99
|
+
WebGL rendering itself is not covered by automated tests yet.
|
|
100
|
+
|
|
101
|
+
## Known limits
|
|
102
|
+
|
|
103
|
+
- Tested in Chrome (on Windows) only; Firefox and Safari are untested.
|
|
104
|
+
- Phone testing is informal so far (one phone with a 144 Hz display, no benchmark numbers); a crash seen on one phone earlier has not been reproduced in emulation.
|
|
105
|
+
- Fractional device pixel ratios were checked only with an emulated test bench.
|
|
106
|
+
- Axis time labels differ from Lightweight Charts in some timeframes.
|
|
107
|
+
- The last-value label on the price scale (last visible bar, as in Lightweight Charts) was matched in 39 measured cases, not exhaustively.
|
|
108
|
+
- No custom series; Pine-style plots are not native series.
|
|
109
|
+
- Below 1 px per bar the engine aggregates bars (by design).
|
|
110
|
+
|
|
111
|
+
## Relation to Lightweight Charts
|
|
112
|
+
|
|
113
|
+
The public API follows Lightweight Charts v5 for compatibility. Several geometry details (candle and bar widths, histogram columns, ticks)
|
|
114
|
+
were reproduced by measuring Lightweight Charts' pixel output; some parts are still treated as derived works and are declared in
|
|
115
|
+
`DERIVAZIONE.md` and `NOTICE`, with attribution to TradingView, Inc. (Apache-2.0). This is **not** a clean-room implementation.
|
|
116
|
+
Lightweight Charts is a trademark of TradingView, Inc.; this project is not affiliated with or endorsed by TradingView.
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
Apache-2.0, see `LICENSE` and `NOTICE`. Copyright (c) 2026 AnubiAI (anubiai.com).
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anubicharts",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "WebGL2 chart renderer with a Lightweight Charts v5-compatible API",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/lw.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/lw.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"LICENSE",
|
|
13
|
+
"NOTICE",
|
|
14
|
+
"DERIVAZIONE.md",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"author": "AnubiAI (anubiai.com)",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/anubiai/anubicharts.git"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/anubiai/anubicharts#readme",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/anubiai/anubicharts/issues"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"charts",
|
|
29
|
+
"webgl",
|
|
30
|
+
"candlestick",
|
|
31
|
+
"financial",
|
|
32
|
+
"lightweight-charts"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"test": "node --test test/*.test.js"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/bars.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AnubiCharts, the AnubiQuant chart engine. Copyright (c) 2026 AnubiAI (anubiai.com).
|
|
3
|
+
* Licensed under the Apache License, Version 2.0; see LICENSE. Parts are derived from, or inspired by, TradingView Lightweight Charts(TM),
|
|
4
|
+
* Copyright (c) 2025 TradingView, Inc. (Apache-2.0); see NOTICE and DERIVAZIONE.md. Not affiliated with TradingView, Inc.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Device-pixel geometry of candles, OHLC bars and histograms (pure functions, no access to the canvas or the GPU).
|
|
8
|
+
* Written from a specification obtained by MEASURING the pixels that Lightweight Charts produces in Chrome (tables in
|
|
9
|
+
* test/fixtures/lw-measures-*.json; the measurement bench is not published). Provenance stated honestly: the person who wrote the
|
|
10
|
+
* code already knew, in general terms, the algorithms of that library and the previous code of this engine; this is not a clean
|
|
11
|
+
* room in the strict legal sense, but a rewrite guided by measurements with a proof of equivalence (see DERIVAZIONE.md).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Width of a candle body, in CSS pixels: s(sp) = sp · share, with share 1 for close bars (spacing ≤ 4) and then decreasing towards
|
|
16
|
+
* 0.8. It is NOT a formula: it is a table of measured thresholds (test/fixtures/lw-measures-bodyshare.json: for each spacing at
|
|
17
|
+
* which the width in device pixels moves to the next value, at DPR 1, 2, 3, 4 and a few more, bisection to 1e-4) and its deviation
|
|
18
|
+
* d(sp) = s − 0.8·sp, interpolated with a local monotone cubic (non-uniform Catmull-Rom). A rational function fitted to those
|
|
19
|
+
* points was wrong by up to 0.009 px of spacing, and at every threshold there was a window in which aq and LW gave different
|
|
20
|
+
* widths (423 cases out of 63,600).
|
|
21
|
+
*/
|
|
22
|
+
const SHARE_TAB = [[4,0.8],[4.30528,0.69863],[4.42801,0.65759],[4.69769,0.57518],[4.87451,0.52896],[4.99999,0.50001],[5.16746,0.46603],[5.34997,0.43431],[5.77901,0.37679],[6.47969,0.31625],[6.7055,0.30227],[7.15018,0.27986],[7.58844,0.26258],[7.80581,0.25535],[8.45279,0.23777],[9.09443,0.22446],[9.30749,0.22067],[9.73248,0.21402],[10.1564,0.20821],[10.36797,0.20562],[11.00161,0.19871],[11.63382,0.19294],[11.84433,0.1912],[12.26494,0.18805],[12.68521,0.18516],[12.89521,0.18383],[13.52481,0.18015],[14.15386,0.17691],[14.36345,0.17591],[14.78242,0.17406],[15.20127,0.17232],[15.41063,0.1715],[16.03842,0.16926],[16.66604,0.16717],[16.87517,0.16653],[17.29334,0.16533],[17.71147,0.16416],[17.92048,0.16362],[18.54742,0.16206],[19.17419,0.16065],[19.38307,0.16021],[19.80082,0.15934],[20.21851,0.15853],[20.42731,0.15815],[21.05375,0.157],[21.68007,0.15594],[21.88879,0.15564],[22.30625,0.155],[22.72367,0.1544],[22.9324,0.15408],[23.55847,0.15322],[24.18447,0.15242],[24.39314,0.15216],[24.81041,0.15167],[25.22765,0.15121],[25.43629,0.15097],[26.06211,0.15031],[26.68789,0.14969],[26.89649,0.14947],[27.31368,0.14906],[27.73079,0.1487],[27.93937,0.1485],[28.56503,0.14798],[29.19064,0.14749],[29.39919,0.14731],[29.81629,0.14697],[30.23331,0.14668],[30.44184,0.14653],[31.06743,0.14606],[31.69293,0.14566],[31.90144,0.14551],[32.31846,0.14523],[32.73541,0.145],[32.94391,0.14487],[33.5694,0.14448],[34.19481,0.14415],[34.4033,0.14403],[34.82026,0.14379],[35.23722,0.14356],[35.44564,0.14349],[36.07105,0.14316],[36.69645,0.14284]];
|
|
23
|
+
const SHARE_M = SHARE_TAB.map((p, i, a) => { const l = a[Math.max(0, i - 1)], r = a[Math.min(a.length - 1, i + 1)]; return (r[1] - l[1]) / (r[0] - l[0]); });
|
|
24
|
+
function bodyExtent(sp) {
|
|
25
|
+
const n = SHARE_TAB.length;
|
|
26
|
+
if (sp >= SHARE_TAB[n - 1][0]) { const [x, y] = SHARE_TAB[n - 1]; return 0.8 * sp + y + Math.min(0, SHARE_M[n - 1]) * (sp - x); } // beyond the last measurement: slope of the deviation, never rising
|
|
27
|
+
let lo = 0, hi = n - 1; while (hi - lo > 1) { const m = (lo + hi) >> 1; if (SHARE_TAB[m][0] <= sp) lo = m; else hi = m; }
|
|
28
|
+
const [x0, y0] = SHARE_TAB[lo], [x1, y1] = SHARE_TAB[lo + 1], h = x1 - x0, t = (sp - x0) / h, t2 = t * t, t3 = t2 * t;
|
|
29
|
+
const d = (2 * t3 - 3 * t2 + 1) * y0 + (t3 - 2 * t2 + t) * h * SHARE_M[lo] + (-2 * t3 + 3 * t2) * y1 + (t3 - t2) * h * SHARE_M[lo + 1];
|
|
30
|
+
return 0.8 * sp + d;
|
|
31
|
+
}
|
|
32
|
+
export function bodyShare(spacing) {
|
|
33
|
+
if (spacing <= 4) return 1;
|
|
34
|
+
return bodyExtent(spacing) / spacing;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Width (device pixels) of a candle's outline, borders included, for a spacing in CSS pixels and a horizontal pixel ratio `hpr`.
|
|
39
|
+
* It always has the same parity as the wick (so the wick falls at the centre of the body).
|
|
40
|
+
*/
|
|
41
|
+
export function candleWidth(spacing, hpr) {
|
|
42
|
+
const unit = Math.max(1, Math.floor(hpr)), full = Math.floor(spacing * hpr);
|
|
43
|
+
const fixed = spacing >= 2.5 && spacing <= 4; // intermediate zone: three fixed CSS pixels, even beyond the spacing (candles overlap: measured)
|
|
44
|
+
let w = fixed ? Math.floor(3 * hpr) : Math.floor(spacing * hpr * bodyShare(spacing));
|
|
45
|
+
w = Math.max(unit, fixed ? w : Math.min(w, full));
|
|
46
|
+
if (w >= 2 && w % 2 !== unit % 2) w--;
|
|
47
|
+
return w;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Wick and border widths for a body `body` pixels wide. */
|
|
51
|
+
export function candleParts(body, hpr, spacing) {
|
|
52
|
+
const unit = Math.max(1, Math.floor(hpr));
|
|
53
|
+
const wick = Math.max(unit, Math.min(Math.min(unit, Math.floor(spacing * hpr)), body));
|
|
54
|
+
let border = unit;
|
|
55
|
+
if (body <= 2 * border) border = Math.max(unit, Math.floor((body - 1) / 2));
|
|
56
|
+
return { wick, border, hollow: body <= 2 * border };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Rectangles of a series of candles. `bars`: { n, x[] (centre in device pixels, integer), o[], h[], l[], c[] (y in device pixels,
|
|
61
|
+
* with decimals), body[], border[], wick[] (packed colours) }. Returns the rectangles [x0, y0, x1, y1, colour] in `out`
|
|
62
|
+
* (Float32Array in groups of 5, with `outU` a Uint32 view of the same buffer) starting at `at`; returns how many. Three passes:
|
|
63
|
+
* wicks, borders, bodies (order matters with transparent colours). Wicks and borders do not enter the previous candle.
|
|
64
|
+
*/
|
|
65
|
+
export function candleRects(bars, geom, flags, out, outU, y0) {
|
|
66
|
+
const { n, x, o, h, l, c } = bars;
|
|
67
|
+
const { width, wick, border, hollow } = geom;
|
|
68
|
+
const half = Math.floor(width / 2), wickHalf = Math.floor(wick / 2);
|
|
69
|
+
let k = 0;
|
|
70
|
+
const put = (xa, ya, w, hh, col) => {
|
|
71
|
+
if (w <= 0 || hh <= 0) return;
|
|
72
|
+
const q = k * 5;
|
|
73
|
+
out[q] = xa; out[q + 1] = y0 + ya; out[q + 2] = xa + w; out[q + 3] = y0 + ya + hh; outU[q + 4] = col; k++;
|
|
74
|
+
};
|
|
75
|
+
const top = (j) => Math.round(Math.min(o[j], c[j])), bot = (j) => Math.round(Math.max(o[j], c[j]));
|
|
76
|
+
if (flags.wick) {
|
|
77
|
+
let edge = -Infinity; // last column occupied by the previous candle
|
|
78
|
+
for (let j = 0; j < n; j++) {
|
|
79
|
+
let a = x[j] - wickHalf; const b = a + wick - 1;
|
|
80
|
+
if (a <= edge) a = edge + 1;
|
|
81
|
+
const t = top(j), bt = bot(j), hi = Math.round(h[j]), lo = Math.round(l[j]);
|
|
82
|
+
if (b >= a) { put(a, hi, b - a + 1, t - hi, bars.wick[j]); put(a, bt + 1, b - a + 1, lo - bt, bars.wick[j]); }
|
|
83
|
+
edge = x[j] - half + width - 1;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (flags.border) {
|
|
87
|
+
let edge = -Infinity;
|
|
88
|
+
for (let j = 0; j < n; j++) {
|
|
89
|
+
let a = x[j] - half; const b = a + width - 1;
|
|
90
|
+
if (a <= edge) a = edge + 1;
|
|
91
|
+
const t = top(j), bt = bot(j), col = bars.border[j];
|
|
92
|
+
if (hollow) put(a, t, b - a + 1, bt - t + 1, col);
|
|
93
|
+
else {
|
|
94
|
+
put(a, t, border, bt - t + 1, col);
|
|
95
|
+
put(b - border + 1, t, border, bt - t + 1, col);
|
|
96
|
+
put(a + border, t, b - a + 1 - 2 * border, border, col);
|
|
97
|
+
put(a + border, bt - border + 1, b - a + 1 - 2 * border, border, col);
|
|
98
|
+
}
|
|
99
|
+
edge = b;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (!flags.border || !hollow) {
|
|
103
|
+
const bd = flags.border ? border : 0;
|
|
104
|
+
for (let j = 0; j < n; j++) {
|
|
105
|
+
const a = x[j] - half + bd, b = x[j] - half + width - 1 - bd, t = top(j) + bd, bt = bot(j) - bd;
|
|
106
|
+
if (bt >= t) put(a, t, b - a + 1, bt - t + 1, bars.body[j]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return k;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* OHLC bars: total width (stem + ticks, device pixels), measured on LW at DPR 1, 1.5, 2, 2.5, 3, 4. With `u = max(1, floor(hpr))`
|
|
114
|
+
* odd (odd stem) it is 6n - 1, with u even 6n + 1, where n grows by one every 20/3 device pixels of spacing (n = floor(0.15 · sp ·
|
|
115
|
+
* hpr + 0.5) for odd u, floor(0.15 · sp · hpr) for even u), at least 1.
|
|
116
|
+
*/
|
|
117
|
+
export function barWidth(spacing, hpr) {
|
|
118
|
+
const unit = Math.max(1, Math.floor(hpr)), dev = spacing * hpr;
|
|
119
|
+
if (unit % 2) return 6 * Math.max(1, Math.floor((3 * dev) / 20 + 0.5)) - 1;
|
|
120
|
+
return 6 * Math.max(1, Math.floor((3 * dev) / 20)) + 1;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Stem and ticks of an OHLC bar: the stem is `u` wide (thin bars) or a third of the total width (rounded down, with the same
|
|
125
|
+
* parity as `u` by construction); the ticks share the rest, the left one takes the pixel less.
|
|
126
|
+
*/
|
|
127
|
+
export function barParts(spacing, hpr, thin) {
|
|
128
|
+
const unit = Math.max(1, Math.floor(hpr)), width = barWidth(spacing, hpr);
|
|
129
|
+
const stem = thin ? unit : Math.max(unit, Math.floor(width / 3));
|
|
130
|
+
// with spacing below floor(1.5 · hpr) CSS pixels (1 at DPR 1, 3 at DPR 2, 6 at DPR 4: measured) only the stems remain
|
|
131
|
+
if (spacing < Math.floor(1.5 * hpr)) return { stem, left: 0, right: 0 };
|
|
132
|
+
const rest = Math.max(0, width - stem), left = Math.floor(rest / 2);
|
|
133
|
+
return { stem, left, right: rest - left };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Rectangles of a series of OHLC bars. `bars`: as for candleRects (integer centre x, o[], h[], l[], c[] in device pixels with
|
|
138
|
+
* decimals, body[] = colour). `geom`: { stem, left, right } (widths in pixels). Per bar: stem from round(high) to round(low),
|
|
139
|
+
* extended by floor(stem/2) at each end; left tick at the open and right tick at the close, as tall as the stem and centred on
|
|
140
|
+
* round(value), but pushed inside the stem. The stem starts at x - floor(stem/2). Returns how many rectangles.
|
|
141
|
+
*/
|
|
142
|
+
export function barRects(bars, geom, out, outU, y0) {
|
|
143
|
+
const { n, x, o, h, l, c } = bars, { stem, left, right } = geom, half = Math.floor(stem / 2);
|
|
144
|
+
let k = 0;
|
|
145
|
+
const put = (xa, ya, xb, yb, col) => { const q = k * 5; out[q] = xa; out[q + 1] = y0 + ya; out[q + 2] = xb; out[q + 3] = y0 + yb; outU[q + 4] = col; k++; };
|
|
146
|
+
for (let j = 0; j < n; j++) {
|
|
147
|
+
const a = x[j] - half, col = bars.body[j], top = Math.round(h[j]) - half, bot = Math.max(Math.round(l[j]) + half, top + 1);
|
|
148
|
+
// the ticks stay inside the stem (measured: with the close on the low the tick moves up one row)
|
|
149
|
+
const tick = (v) => Math.max(top, Math.min(Math.round(v) - half, bot - stem));
|
|
150
|
+
put(a, top, a + stem, bot, col);
|
|
151
|
+
if (left > 0) { const yo = tick(o[j]); put(a - left, yo, a, yo + stem, col); }
|
|
152
|
+
if (right > 0) { const yc = tick(c[j]); put(a + stem, yc, a + stem + right, yc + stem, col); }
|
|
153
|
+
}
|
|
154
|
+
return k;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Gap in device pixels between two histogram columns (none with bars narrower than one pixel). */
|
|
158
|
+
export const histGap = (pitch, hpr) => (Math.ceil(pitch) <= 1 ? 0 : Math.max(1, Math.floor(hpr)));
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Columns of a histogram. cx[]: centres in device pixels (with decimals); adj[]: consecutiveness (two bars are adjacent if their
|
|
162
|
+
* values differ by 1); pitch: spacing in device pixels; gapPx: gap between two columns. Writes left[] and right[]. Measured
|
|
163
|
+
* specification: column round(pitch) - gap wide, centred on the rounded centre; between two adjacent bars the gap becomes exactly
|
|
164
|
+
* gapPx: too large, the next column is widened to the left; too small, the previous one is shortened.
|
|
165
|
+
*/
|
|
166
|
+
export function histColumns(n, cx, adj, pitch, gapPx, left, right) {
|
|
167
|
+
const w0 = Math.round(pitch) - gapPx, half = Math.floor(w0 / 2);
|
|
168
|
+
for (let j = 0; j < n; j++) { const r = Math.round(cx[j]); left[j] = r - half; right[j] = left[j] + w0 - 1; }
|
|
169
|
+
for (let j = 1; j < n; j++) {
|
|
170
|
+
if (adj[j] !== adj[j - 1] + 1) continue;
|
|
171
|
+
const gap = left[j] - right[j - 1] - 1;
|
|
172
|
+
if (gap > gapPx) left[j] -= gap - gapPx;
|
|
173
|
+
else if (gap < gapPx) right[j - 1] -= gapPx - gap;
|
|
174
|
+
}
|
|
175
|
+
let narrow = Infinity;
|
|
176
|
+
for (let j = 0; j < n; j++) { if (right[j] < left[j]) right[j] = left[j]; narrow = Math.min(narrow, right[j] - left[j] + 1); }
|
|
177
|
+
// narrow columns (less than 4 pixels): all like the narrowest; the extra pixel is taken from the side towards which the rounding
|
|
178
|
+
// of the centre moved the column
|
|
179
|
+
if (gapPx > 0 && narrow < 4) {
|
|
180
|
+
for (let j = 0; j < n; j++) {
|
|
181
|
+
const extra = right[j] - left[j] + 1 - narrow;
|
|
182
|
+
if (extra <= 0) continue;
|
|
183
|
+
if (Math.round(cx[j]) > cx[j]) right[j] -= extra; else left[j] += extra;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Point markers (pointMarkersVisible): CSS radius = pointMarkersRadius or lineWidth/2 + 2. Measured on LW (36 combinations, DPR
|
|
190
|
+
* 1-4): the centroid is at the exact y and at round(x·dpr) + 0.5 when floor(dpr) is odd (0 if even); the covered area matches a
|
|
191
|
+
* circle of radius cssRadius·dpr, plus 0.4 px in the odd case (within 9%: with the smallest radii, 2.5 px, the soft edge matters
|
|
192
|
+
* more).
|
|
193
|
+
*/
|
|
194
|
+
export function pointMarker(dpr, lineWidth, radiusCss) {
|
|
195
|
+
const corr = (Math.max(1, Math.floor(dpr)) % 2) / 2, r = radiusCss || lineWidth / 2 + 2;
|
|
196
|
+
return { radius: r * dpr + (corr ? 0.4 : 0), xCorr: corr };
|
|
197
|
+
}
|