@konce-pt/chart 0.21.0 → 0.22.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/dist/bar.js CHANGED
@@ -28,6 +28,24 @@ function roundedRect(x, y, w, h, r, corners) {
28
28
  .filter(Boolean)
29
29
  .join(' ');
30
30
  }
31
+ /**
32
+ * Czy odcinek serii `s` w kategorii `c` jest zewnętrzny w stosie - ostatni niezerowy w kierunku `up`.
33
+ * W stosie zaokrąglony jest tylko on.
34
+ */
35
+ function isOuterSegment(seriesData, s, c, up) {
36
+ for (let k = seriesData.length - 1; k >= 0; k--) {
37
+ const v = seriesData[k]?.[c] ?? 0;
38
+ if (v !== 0 && v >= 0 === up)
39
+ return k === s;
40
+ }
41
+ return true;
42
+ }
43
+ /** Zaokrąglane rogi słupka: te od strony, w którą rośnie. */
44
+ function barCorners(vertical, grows) {
45
+ if (vertical)
46
+ return grows ? { tl: true, tr: true } : { bl: true, br: true };
47
+ return grows ? { tr: true, br: true } : { tl: true, bl: true };
48
+ }
31
49
  /**
32
50
  * Wylicza słupki dla obszaru `plot`.
33
51
  * @param seriesData wartości[serie][kategorie]
@@ -58,17 +76,7 @@ scaleOverride, options = {}) {
58
76
  // Stos: jedno pasmo na kategorię; obok siebie: pasmo kategorii dzielone między serie.
59
77
  const group = stacked ? bandScale(1, 0, cat.bandwidth, 0) : bandScale(seriesCount, 0, cat.bandwidth, 0.1);
60
78
  const stack = stacked ? stackSeries(seriesData) : null;
61
- // W stosie zaokrąglony jest tylko zewnętrzny odcinek (ostatnia niezerowa seria w danym kierunku).
62
- const outer = (s, c, up) => {
63
- if (!stack)
64
- return true;
65
- for (let k = seriesData.length - 1; k >= 0; k--) {
66
- const v = seriesData[k]?.[c] ?? 0;
67
- if (v !== 0 && v >= 0 === up)
68
- return k === s;
69
- }
70
- return true;
71
- };
79
+ const outer = (s, c, up) => !stack || isOuterSegment(seriesData, s, c, up);
72
80
  seriesData.forEach((values, s) => {
73
81
  for (let c = 0; c < categoryCount; c++) {
74
82
  const v = values[c] ?? 0;
@@ -81,9 +89,7 @@ scaleOverride, options = {}) {
81
89
  const lo = Math.min(from, to);
82
90
  const len = Math.abs(to - from);
83
91
  const rect = vertical ? { x: band, y: lo, width: thick, height: len } : { x: lo, y: band, width: len, height: thick };
84
- const corners = vertical
85
- ? grows ? { tl: true, tr: true } : { bl: true, br: true }
86
- : grows ? { tr: true, br: true } : { tl: true, bl: true };
92
+ const corners = barCorners(vertical, grows);
87
93
  bars.push({
88
94
  rect,
89
95
  path: roundedRect(rect.x, rect.y, rect.width, rect.height, round, corners),
package/dist/engine.d.ts CHANGED
@@ -82,6 +82,14 @@ export declare class KptChartMotion {
82
82
  private retargetAxis;
83
83
  private wake;
84
84
  private readonly tick;
85
+ /** Krok sprężyn wartości; `true`, gdy któryś kanał jeszcze się rusza albo czeka na start fali. */
86
+ private stepChannels;
87
+ /** Krok osi: koniec przytrzymania przestawia cel na skalę końcową, potem sprężyny obu końców. */
88
+ private stepAxis;
89
+ /** Duch znikającej serii żyje do `ghostEnd`, potem znika. */
90
+ private stepGhost;
91
+ /** Krok sprężyny dymka (wolniejszej przy przeciąganiu palcem). */
92
+ private stepTip;
85
93
  private emit;
86
94
  }
87
95
  /**
package/dist/engine.js CHANGED
@@ -32,49 +32,12 @@ export class KptChartMotion {
32
32
  this.tick = (now) => {
33
33
  const dt = Math.min(1 / 30, Math.max(0, (now - this.last) / 1000));
34
34
  this.last = now;
35
- let busy = false;
36
- for (const row of this.channels) {
37
- for (const c of row) {
38
- // Kanał czekający na swoją kolej w fali to praca w toku - znacznik klatki bywa wcześniejszy niż start.
39
- if (now < c.start) {
40
- busy = true;
41
- continue;
42
- }
43
- const step = springStep(c, c.target, dt, KPT_CHART_MOTION.wave);
44
- c.value = step.value;
45
- c.velocity = step.velocity;
46
- if (!step.settled)
47
- busy = true;
48
- }
49
- }
50
- if (this.axisTarget) {
51
- if (this.holdEnd && now >= this.holdEnd) {
52
- this.holdEnd = 0;
53
- this.retargetAxis(this.finalScale, now);
54
- }
55
- for (const c of [this.axisMin, this.axisMax]) {
56
- const step = springStep(c, c.target, dt, KPT_CHART_MOTION.axis);
57
- c.value = step.value;
58
- c.velocity = step.velocity;
59
- if (!step.settled)
60
- busy = true;
61
- }
62
- if (this.holdEnd)
63
- busy = true;
64
- }
65
- if (this.ghost && now < this.ghostEnd)
66
- busy = true;
67
- else
68
- this.ghost = null;
69
- if (this.tip) {
70
- const opts = this.tip.scrub ? KPT_CHART_MOTION.tipScrub : KPT_CHART_MOTION.tip;
71
- const x = springAdvance(this.tip.x, this.tip.toX, dt, opts);
72
- const y = springAdvance(this.tip.y, this.tip.toY, dt, opts);
73
- this.tip.x = { value: x.value, velocity: x.velocity };
74
- this.tip.y = { value: y.value, velocity: y.velocity };
75
- if (!x.settled || !y.settled)
76
- busy = true;
77
- }
35
+ // Każdy krok musi się wykonać w każdej klatce - stąd osobne stałe zamiast skróconego `||`.
36
+ const channels = this.stepChannels(now, dt);
37
+ const axis = this.stepAxis(now, dt);
38
+ const ghost = this.stepGhost(now);
39
+ const tip = this.stepTip(dt);
40
+ const busy = channels || axis || ghost || tip;
78
41
  if (busy) {
79
42
  this.emit(now, true);
80
43
  this.raf = requestAnimationFrame(this.tick);
@@ -198,6 +161,61 @@ export class KptChartMotion {
198
161
  this.last = performance.now();
199
162
  this.raf = requestAnimationFrame(this.tick);
200
163
  }
164
+ /** Krok sprężyn wartości; `true`, gdy któryś kanał jeszcze się rusza albo czeka na start fali. */
165
+ stepChannels(now, dt) {
166
+ let busy = false;
167
+ for (const row of this.channels) {
168
+ for (const c of row) {
169
+ // Kanał czekający na swoją kolej w fali to praca w toku - znacznik klatki bywa wcześniejszy niż start.
170
+ if (now < c.start) {
171
+ busy = true;
172
+ continue;
173
+ }
174
+ const step = springStep(c, c.target, dt, KPT_CHART_MOTION.wave);
175
+ c.value = step.value;
176
+ c.velocity = step.velocity;
177
+ if (!step.settled)
178
+ busy = true;
179
+ }
180
+ }
181
+ return busy;
182
+ }
183
+ /** Krok osi: koniec przytrzymania przestawia cel na skalę końcową, potem sprężyny obu końców. */
184
+ stepAxis(now, dt) {
185
+ if (!this.axisTarget)
186
+ return false;
187
+ if (this.holdEnd && now >= this.holdEnd) {
188
+ this.holdEnd = 0;
189
+ this.retargetAxis(this.finalScale, now);
190
+ }
191
+ let busy = false;
192
+ for (const c of [this.axisMin, this.axisMax]) {
193
+ const step = springStep(c, c.target, dt, KPT_CHART_MOTION.axis);
194
+ c.value = step.value;
195
+ c.velocity = step.velocity;
196
+ if (!step.settled)
197
+ busy = true;
198
+ }
199
+ return busy || this.holdEnd !== 0;
200
+ }
201
+ /** Duch znikającej serii żyje do `ghostEnd`, potem znika. */
202
+ stepGhost(now) {
203
+ if (this.ghost && now < this.ghostEnd)
204
+ return true;
205
+ this.ghost = null;
206
+ return false;
207
+ }
208
+ /** Krok sprężyny dymka (wolniejszej przy przeciąganiu palcem). */
209
+ stepTip(dt) {
210
+ if (!this.tip)
211
+ return false;
212
+ const opts = this.tip.scrub ? KPT_CHART_MOTION.tipScrub : KPT_CHART_MOTION.tip;
213
+ const x = springAdvance(this.tip.x, this.tip.toX, dt, opts);
214
+ const y = springAdvance(this.tip.y, this.tip.toY, dt, opts);
215
+ this.tip.x = { value: x.value, velocity: x.velocity };
216
+ this.tip.y = { value: y.value, velocity: y.velocity };
217
+ return !x.settled || !y.settled;
218
+ }
201
219
  emit(now, moving) {
202
220
  const sheen = this.withSheen ? sheenFront(now - this.sheenStart, this.sheenCount) : null;
203
221
  this.onFrame({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konce-pt/chart",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "description": "Chart geometry core for Koncept UI - scales, line and area paths, bar layout, pie and radar geometry. Framework-free TypeScript, zero runtime dependencies.",
5
5
  "license": "MIT",
6
6
  "author": "konce.pt",