@visactor/vrender-core 1.1.11-alpha.1 → 1.1.11

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.
Files changed (42) hide show
  1. package/cjs/common/area-cache.d.ts +11 -0
  2. package/cjs/common/area-cache.js +115 -0
  3. package/cjs/common/area-cache.js.map +1 -0
  4. package/cjs/common/bezier-utils.js +1 -2
  5. package/cjs/common/bounds-context.js +2 -1
  6. package/cjs/common/path-svg.js +1 -2
  7. package/cjs/common/performance-raf.js +2 -1
  8. package/cjs/common/render-curve.d.ts +3 -0
  9. package/cjs/common/render-curve.js +16 -17
  10. package/cjs/common/render-curve.js.map +1 -1
  11. package/cjs/common/seg-context.js +1 -1
  12. package/cjs/graphic/area.js +3 -3
  13. package/cjs/graphic/area.js.map +1 -1
  14. package/cjs/graphic/line.js +4 -4
  15. package/cjs/graphic/line.js.map +1 -1
  16. package/cjs/render/contributions/render/area-render.js +18 -92
  17. package/cjs/render/contributions/render/area-render.js.map +1 -1
  18. package/cjs/render/contributions/render/incremental-area-render.d.ts +5 -1
  19. package/cjs/render/contributions/render/incremental-area-render.js +29 -7
  20. package/cjs/render/contributions/render/incremental-area-render.js.map +1 -1
  21. package/dist/index.es.js +213 -149
  22. package/es/common/area-cache.d.ts +11 -0
  23. package/es/common/area-cache.js +113 -0
  24. package/es/common/area-cache.js.map +1 -0
  25. package/es/common/bezier-utils.js +1 -2
  26. package/es/common/bounds-context.js +2 -1
  27. package/es/common/path-svg.js +1 -2
  28. package/es/common/performance-raf.js +2 -1
  29. package/es/common/render-curve.d.ts +3 -0
  30. package/es/common/render-curve.js +15 -16
  31. package/es/common/render-curve.js.map +1 -1
  32. package/es/common/seg-context.js +1 -1
  33. package/es/graphic/area.js +3 -3
  34. package/es/graphic/area.js.map +1 -1
  35. package/es/graphic/line.js +4 -4
  36. package/es/graphic/line.js.map +1 -1
  37. package/es/render/contributions/render/area-render.js +18 -92
  38. package/es/render/contributions/render/area-render.js.map +1 -1
  39. package/es/render/contributions/render/incremental-area-render.d.ts +5 -1
  40. package/es/render/contributions/render/incremental-area-render.js +28 -6
  41. package/es/render/contributions/render/incremental-area-render.js.map +1 -1
  42. package/package.json +4 -3
package/dist/index.es.js CHANGED
@@ -13538,21 +13538,21 @@ let Line$1 = class Line extends Graphic {
13538
13538
  return aabbBounds;
13539
13539
  }
13540
13540
  updateLineAABBBoundsByPoints(attribute, lineTheme, aabbBounds, graphic) {
13541
- const { points = lineTheme.points, connectedType } = attribute;
13541
+ const { points = lineTheme.points } = attribute;
13542
13542
  const b = aabbBounds;
13543
13543
  points.forEach(p => {
13544
- if (p.defined !== false || connectedType === 'connect') {
13544
+ if (p.defined !== false) {
13545
13545
  b.add(p.x, p.y);
13546
13546
  }
13547
13547
  });
13548
13548
  return b;
13549
13549
  }
13550
13550
  updateLineAABBBoundsBySegments(attribute, lineTheme, aabbBounds, graphic) {
13551
- const { segments = lineTheme.segments, connectedType } = attribute;
13551
+ const { segments = lineTheme.segments } = attribute;
13552
13552
  const b = aabbBounds;
13553
13553
  segments.forEach(s => {
13554
13554
  s.points.forEach(p => {
13555
- if (p.defined !== false || connectedType === 'connect') {
13555
+ if (p.defined !== false) {
13556
13556
  b.add(p.x, p.y);
13557
13557
  }
13558
13558
  });
@@ -15905,7 +15905,14 @@ function createPath(attributes) {
15905
15905
  return new Path(attributes);
15906
15906
  }
15907
15907
 
15908
- const AREA_UPDATE_TAG_KEY = ['segments', 'points', 'curveType', 'curveTension', ...GRAPHIC_UPDATE_TAG_KEY];
15908
+ const AREA_UPDATE_TAG_KEY = [
15909
+ 'segments',
15910
+ 'points',
15911
+ 'curveType',
15912
+ 'curveTension',
15913
+ 'connectedType',
15914
+ ...GRAPHIC_UPDATE_TAG_KEY
15915
+ ];
15909
15916
  class Area extends Graphic {
15910
15917
  constructor(params) {
15911
15918
  super(params);
@@ -15954,6 +15961,9 @@ class Area extends Graphic {
15954
15961
  const b = aabbBounds;
15955
15962
  points.forEach(p => {
15956
15963
  var _a, _b;
15964
+ if (p.defined === false) {
15965
+ return;
15966
+ }
15957
15967
  b.add(p.x, p.y);
15958
15968
  b.add((_a = p.x1) !== null && _a !== void 0 ? _a : p.x, (_b = p.y1) !== null && _b !== void 0 ? _b : p.y);
15959
15969
  });
@@ -15965,6 +15975,9 @@ class Area extends Graphic {
15965
15975
  segments.forEach(s => {
15966
15976
  s.points.forEach(p => {
15967
15977
  var _a, _b;
15978
+ if (p.defined === false) {
15979
+ return;
15980
+ }
15968
15981
  b.add(p.x, p.y);
15969
15982
  b.add((_a = p.x1) !== null && _a !== void 0 ? _a : p.x, (_b = p.y1) !== null && _b !== void 0 ? _b : p.y);
15970
15983
  });
@@ -24877,6 +24890,142 @@ function drawSegItem(ctx, curve, endPercent, params) {
24877
24890
  }
24878
24891
  }
24879
24892
 
24893
+ function getAreaPointRuns(points, connectedType, startPoint) {
24894
+ const runs = [];
24895
+ if (!points.some(p => p.defined === false)) {
24896
+ const run = startPoint ? [startPoint, ...points] : points;
24897
+ if (run.length) {
24898
+ runs.push(run);
24899
+ }
24900
+ return { runs, tail: run[run.length - 1] };
24901
+ }
24902
+ let run = startPoint ? [startPoint] : [];
24903
+ for (let i = 0; i < points.length; i++) {
24904
+ const point = points[i];
24905
+ if (point.defined !== false) {
24906
+ run.push(point);
24907
+ }
24908
+ else if (connectedType !== 'connect') {
24909
+ if (run.length) {
24910
+ runs.push(run);
24911
+ }
24912
+ run = [];
24913
+ }
24914
+ }
24915
+ if (run.length) {
24916
+ runs.push(run);
24917
+ }
24918
+ return { runs, tail: run[run.length - 1] };
24919
+ }
24920
+ function joinAreaPaths(paths) {
24921
+ var _a;
24922
+ if (paths.length === 1) {
24923
+ return paths[0];
24924
+ }
24925
+ const curves = [];
24926
+ for (let i = 0; i < paths.length; i++) {
24927
+ const next = paths[i].curves;
24928
+ if (curves.length) {
24929
+ const previous = curves[curves.length - 1];
24930
+ const gap = new LineCurve((_a = previous.p3) !== null && _a !== void 0 ? _a : previous.p1, next[0].p0);
24931
+ gap.defined = false;
24932
+ gap.originP1 = previous.originP2;
24933
+ gap.originP2 = next[0].originP1;
24934
+ curves.push(gap);
24935
+ }
24936
+ for (let j = 0; j < next.length; j++) {
24937
+ curves.push(next[j]);
24938
+ }
24939
+ }
24940
+ const path = paths[paths.length - 1];
24941
+ path.curves = curves;
24942
+ path.length = NaN;
24943
+ return path;
24944
+ }
24945
+ function compileAreaRuns(runs, curveType, curveTension, sourceSegmentIndex, topStart, bottomStart) {
24946
+ var _a, _b, _c, _d;
24947
+ const tops = [];
24948
+ const bottoms = [];
24949
+ const bottomType = curveType === 'stepBefore' ? 'stepAfter' : curveType === 'stepAfter' ? 'stepBefore' : curveType;
24950
+ for (let i = 0; i < runs.length; i++) {
24951
+ const points = runs[i];
24952
+ const startPoint = i === 0 ? topStart : undefined;
24953
+ if (points.length < 2 - Number(!!startPoint)) {
24954
+ continue;
24955
+ }
24956
+ const bottomPoints = [];
24957
+ for (let j = points.length - 1; j >= 0; j--) {
24958
+ const p = points[j];
24959
+ bottomPoints.push({ x: (_a = p.x1) !== null && _a !== void 0 ? _a : p.x, y: (_b = p.y1) !== null && _b !== void 0 ? _b : p.y });
24960
+ }
24961
+ if (i === 0 && bottomStart) {
24962
+ bottomPoints.push({ x: (_c = bottomStart.x1) !== null && _c !== void 0 ? _c : bottomStart.x, y: (_d = bottomStart.y1) !== null && _d !== void 0 ? _d : bottomStart.y });
24963
+ }
24964
+ const top = calcLineCache(points, curveType, { startPoint, curveTension });
24965
+ const bottom = calcLineCache(bottomPoints, bottomType, { curveTension });
24966
+ if ((top === null || top === void 0 ? void 0 : top.curves.length) && (bottom === null || bottom === void 0 ? void 0 : bottom.curves.length)) {
24967
+ tops.push(top);
24968
+ bottoms.push(bottom);
24969
+ }
24970
+ }
24971
+ if (!tops.length) {
24972
+ return null;
24973
+ }
24974
+ return {
24975
+ top: joinAreaPaths(tops),
24976
+ bottom: joinAreaPaths(bottoms.reverse()),
24977
+ sourceSegmentIndex,
24978
+ direction: Direction.ROW
24979
+ };
24980
+ }
24981
+ function calcAreaCache(points, segments, curveType, connectedType, curveTension) {
24982
+ var _a;
24983
+ const caches = [];
24984
+ let tail;
24985
+ let topTail;
24986
+ let first;
24987
+ let last;
24988
+ const count = segments ? segments.length : 1;
24989
+ for (let i = 0; i < count; i++) {
24990
+ const segmentPoints = segments ? segments[i].points : points !== null && points !== void 0 ? points : [];
24991
+ const result = getAreaPointRuns(segmentPoints, connectedType);
24992
+ const canContinue = connectedType === 'connect' || ((_a = segmentPoints[0]) === null || _a === void 0 ? void 0 : _a.defined) !== false;
24993
+ if (result.runs.length) {
24994
+ first = first !== null && first !== void 0 ? first : result.runs[0][0];
24995
+ const lastRun = result.runs[result.runs.length - 1];
24996
+ last = lastRun[lastRun.length - 1];
24997
+ }
24998
+ const cache = compileAreaRuns(result.runs, curveType, curveTension, i, canContinue ? topTail : undefined, canContinue ? tail : undefined);
24999
+ if (cache) {
25000
+ caches.push(cache);
25001
+ }
25002
+ if (result.tail) {
25003
+ tail = result.tail;
25004
+ const lastRun = result.runs[result.runs.length - 1];
25005
+ topTail =
25006
+ cache && (result.runs.length === 1 || lastRun.length > 1) ? { x: cache.top.endX, y: cache.top.endY } : tail;
25007
+ }
25008
+ else if (connectedType !== 'connect' && segmentPoints.length) {
25009
+ tail = topTail = undefined;
25010
+ }
25011
+ }
25012
+ if (!caches.length) {
25013
+ return null;
25014
+ }
25015
+ let direction = Direction.ROW;
25016
+ if (last.x1 != null) {
25017
+ const dx = abs(last.x - first.x);
25018
+ const dy = abs(last.y - first.y);
25019
+ if (last.y1 == null || (Number.isFinite(dx + dy) && dy >= dx)) {
25020
+ direction = Direction.COLUMN;
25021
+ }
25022
+ }
25023
+ for (let i = 0; i < caches.length; i++) {
25024
+ caches[i].direction = direction;
25025
+ }
25026
+ return segments ? caches : caches[0];
25027
+ }
25028
+
24880
25029
  function drawEachCurve(path, curve, lastCurve, defined0, offsetX, offsetY, offsetZ) {
24881
25030
  var _a;
24882
25031
  let p0 = curve.p0;
@@ -25012,31 +25161,27 @@ function drawIncrementalSegments(path, lastSeg, segments, params) {
25012
25161
  });
25013
25162
  }
25014
25163
  function drawIncrementalAreaSegments(path, lastSeg, segments, params) {
25015
- const { offsetX = 0, offsetY = 0 } = params || {};
25016
- const { points } = segments;
25017
- const definedPointsList = [];
25018
- for (let i = 0; i < points.length; i++) {
25019
- if (points[i].defined === false) ;
25020
- }
25021
- definedPointsList.push(points);
25022
- definedPointsList.forEach((points, i) => {
25023
- var _a, _b, _c, _d;
25024
- const startP = lastSeg && i === 0 ? lastSeg.points[lastSeg.points.length - 1] : points[0];
25025
- path.moveTo(startP.x + offsetX, startP.y + offsetY);
25026
- points.forEach(p => {
25027
- if (p.defined === false) {
25028
- path.moveTo(p.x + offsetX, p.y + offsetY);
25029
- return;
25030
- }
25031
- path.lineTo(p.x + offsetX, p.y + offsetY);
25032
- });
25033
- for (let i = points.length - 1; i >= 0; i--) {
25034
- const p = points[i];
25164
+ var _a, _b;
25165
+ const { offsetX = 0, offsetY = 0, connectedType = 'none' } = params || {};
25166
+ const startPoint = params && 'startPoint' in params
25167
+ ? params.startPoint
25168
+ : lastSeg && getAreaPointRuns(lastSeg.points, connectedType).tail;
25169
+ const { runs } = getAreaPointRuns(segments.points, connectedType, startPoint);
25170
+ for (let i = 0; i < runs.length; i++) {
25171
+ const points = runs[i];
25172
+ if (points.length < 2) {
25173
+ continue;
25174
+ }
25175
+ path.moveTo(points[0].x + offsetX, points[0].y + offsetY);
25176
+ for (let j = 1; j < points.length; j++) {
25177
+ path.lineTo(points[j].x + offsetX, points[j].y + offsetY);
25178
+ }
25179
+ for (let j = points.length - 1; j >= 0; j--) {
25180
+ const p = points[j];
25035
25181
  path.lineTo((_a = p.x1) !== null && _a !== void 0 ? _a : p.x, (_b = p.y1) !== null && _b !== void 0 ? _b : p.y);
25036
25182
  }
25037
- path.lineTo((_c = startP.x1) !== null && _c !== void 0 ? _c : startP.x, (_d = startP.y1) !== null && _d !== void 0 ? _d : startP.y);
25038
25183
  path.closePath();
25039
- });
25184
+ }
25040
25185
  }
25041
25186
 
25042
25187
  class DefaultCanvasLineRender extends BaseRender {
@@ -25465,7 +25610,6 @@ class DefaultCanvasAreaRender extends BaseRender {
25465
25610
  _runStroke();
25466
25611
  }
25467
25612
  drawShape(area, context, x, y, drawContext, params, fillCb, strokeCb) {
25468
- var _a, _b, _c, _d, _e, _f;
25469
25613
  const areaAttribute = getTheme(area, params === null || params === void 0 ? void 0 : params.theme).area;
25470
25614
  const { fill = areaAttribute.fill, stroke = areaAttribute.stroke, fillOpacity = areaAttribute.fillOpacity, z = areaAttribute.z, strokeOpacity = areaAttribute.strokeOpacity, curveTension = areaAttribute.curveTension, connectedType = areaAttribute.connectedType } = area.attribute;
25471
25615
  const data = this.valid(area, areaAttribute, fillCb, strokeCb);
@@ -25479,104 +25623,24 @@ class DefaultCanvasAreaRender extends BaseRender {
25479
25623
  if (closePath && curveType === 'linear') {
25480
25624
  curveType = 'linearClosed';
25481
25625
  }
25482
- function parsePoint(points, connectedType) {
25483
- if (connectedType !== 'connect') {
25484
- return points;
25485
- }
25486
- return points.filter(p => p.defined !== false);
25487
- }
25488
25626
  if (clipRange === 1 && !segments && !points.some(p => p.defined === false) && curveType === 'linear') {
25489
25627
  return this.drawLinearAreaHighPerformance(area, context, !!fill, doStroke, fillOpacity, strokeOpacity, x, y, areaAttribute, drawContext, params, fillCb, strokeCb);
25490
25628
  }
25491
25629
  if (area.shouldUpdateShape()) {
25492
- if (segments && segments.length) {
25493
- let startPoint;
25494
- let lastTopSeg;
25495
- const topCaches = segments
25496
- .map((seg, index) => {
25497
- if (seg.points.length <= 1) {
25498
- if (index === 0) {
25499
- seg.points[0] && (lastTopSeg = { endX: seg.points[0].x, endY: seg.points[0].y });
25500
- return null;
25501
- }
25502
- }
25503
- if (index === 1) {
25504
- startPoint = { x: lastTopSeg.endX, y: lastTopSeg.endY };
25505
- }
25506
- else if (index > 1) {
25507
- startPoint.x = lastTopSeg.endX;
25508
- startPoint.y = lastTopSeg.endY;
25509
- }
25510
- const data = calcLineCache(parsePoint(seg.points, connectedType), curveType, {
25511
- startPoint,
25512
- curveTension
25513
- });
25514
- lastTopSeg = data;
25515
- return data;
25516
- })
25517
- .filter(item => !!item);
25518
- let lastBottomSeg;
25519
- const bottomCaches = [];
25520
- for (let i = segments.length - 1; i >= 0; i--) {
25521
- const points = segments[i].points;
25522
- const bottomPoints = [];
25523
- for (let i = points.length - 1; i >= 0; i--) {
25524
- bottomPoints.push({
25525
- x: (_a = points[i].x1) !== null && _a !== void 0 ? _a : points[i].x,
25526
- y: (_b = points[i].y1) !== null && _b !== void 0 ? _b : points[i].y
25527
- });
25528
- }
25529
- if (i !== 0) {
25530
- const lastSegmentPoints = segments[i - 1].points;
25531
- const endPoint = lastSegmentPoints[lastSegmentPoints.length - 1];
25532
- endPoint &&
25533
- bottomPoints.push({
25534
- x: (_c = endPoint.x1) !== null && _c !== void 0 ? _c : endPoint.x,
25535
- y: (_d = endPoint.y1) !== null && _d !== void 0 ? _d : endPoint.y
25536
- });
25537
- }
25538
- if (bottomPoints.length > 1) {
25539
- lastBottomSeg = calcLineCache(parsePoint(bottomPoints, connectedType), curveType === 'stepBefore' ? 'stepAfter' : curveType === 'stepAfter' ? 'stepBefore' : curveType, { curveTension });
25540
- bottomCaches.unshift(lastBottomSeg);
25541
- }
25542
- }
25543
- area.cacheArea = bottomCaches.map((item, index) => ({
25544
- top: topCaches[index],
25545
- bottom: item
25546
- }));
25547
- }
25548
- else if (points && points.length) {
25549
- const topPoints = parsePoint(points, connectedType);
25550
- const bottomPoints = [];
25551
- for (let i = topPoints.length - 1; i >= 0; i--) {
25552
- bottomPoints.push({
25553
- x: (_e = topPoints[i].x1) !== null && _e !== void 0 ? _e : topPoints[i].x,
25554
- y: (_f = topPoints[i].y1) !== null && _f !== void 0 ? _f : topPoints[i].y
25555
- });
25556
- }
25557
- const topCache = calcLineCache(topPoints, curveType, { curveTension });
25558
- const bottomCache = calcLineCache(bottomPoints, curveType === 'stepBefore' ? 'stepAfter' : curveType === 'stepAfter' ? 'stepBefore' : curveType, { curveTension });
25559
- area.cacheArea = { top: topCache, bottom: bottomCache };
25560
- }
25561
- else {
25562
- area.cacheArea = null;
25563
- area.clearUpdateShapeTag();
25564
- return;
25565
- }
25630
+ area.cacheArea = calcAreaCache(points, segments, curveType, connectedType, curveTension);
25566
25631
  area.clearUpdateShapeTag();
25567
25632
  }
25633
+ if (!area.cacheArea) {
25634
+ return;
25635
+ }
25568
25636
  if (Array.isArray(area.cacheArea)) {
25569
- const segments = area.attribute.segments.filter(item => item.points.length);
25570
- if (segments[0].points.length === 1) {
25571
- segments.shift();
25572
- }
25573
25637
  if (clipRange === 1) {
25574
25638
  let skip = false;
25575
- area.cacheArea.forEach((cache, index) => {
25639
+ area.cacheArea.forEach(cache => {
25576
25640
  if (skip) {
25577
25641
  return;
25578
25642
  }
25579
- skip = this.drawSegmentItem(context, cache, doFill, fillOpacity, doStroke, strokeOpacity, segments[index], [areaAttribute, area.attribute], clipRange, x, y, z, area, drawContext, fillCb, strokeCb);
25643
+ skip = this.drawSegmentItem(context, cache, doFill, fillOpacity, doStroke, strokeOpacity, segments[cache.sourceSegmentIndex], [areaAttribute, area.attribute], clipRange, x, y, z, area, drawContext, fillCb, strokeCb);
25580
25644
  });
25581
25645
  }
25582
25646
  else {
@@ -25584,7 +25648,7 @@ class DefaultCanvasAreaRender extends BaseRender {
25584
25648
  const totalDrawLength = clipRange * totalLength;
25585
25649
  let drawedLengthUntilLast = 0;
25586
25650
  let skip = false;
25587
- area.cacheArea.forEach((cache, index) => {
25651
+ area.cacheArea.forEach(cache => {
25588
25652
  if (skip) {
25589
25653
  return;
25590
25654
  }
@@ -25592,7 +25656,7 @@ class DefaultCanvasAreaRender extends BaseRender {
25592
25656
  const _cr = (totalDrawLength - drawedLengthUntilLast) / curSegLength;
25593
25657
  drawedLengthUntilLast += curSegLength;
25594
25658
  if (_cr > 0) {
25595
- skip = this.drawSegmentItem(context, cache, doFill, fillOpacity, doStroke, strokeOpacity, segments[index], [areaAttribute, area.attribute], min(_cr, 1), x, y, z, area, drawContext, fillCb, strokeCb);
25659
+ skip = this.drawSegmentItem(context, cache, doFill, fillOpacity, doStroke, strokeOpacity, segments[cache.sourceSegmentIndex], [areaAttribute, area.attribute], min(_cr, 1), x, y, z, area, drawContext, fillCb, strokeCb);
25596
25660
  }
25597
25661
  });
25598
25662
  }
@@ -25609,6 +25673,7 @@ class DefaultCanvasAreaRender extends BaseRender {
25609
25673
  return this._drawSegmentItem(context, cache, fill, fillOpacity, stroke, strokeOpacity, attribute, defaultAttribute, clipRange, offsetX, offsetY, offsetZ, area, drawContext, fillCb, strokeCb);
25610
25674
  }
25611
25675
  _drawSegmentItem(context, cache, fill, fillOpacity, stroke, strokeOpacity, attribute, defaultAttribute, clipRange, offsetX, offsetY, offsetZ, area, drawContext, fillCb, strokeCb) {
25676
+ var _a;
25612
25677
  if (!(cache &&
25613
25678
  cache.top &&
25614
25679
  cache.bottom &&
@@ -25620,34 +25685,7 @@ class DefaultCanvasAreaRender extends BaseRender {
25620
25685
  }
25621
25686
  context.beginPath();
25622
25687
  const ret = false;
25623
- const { points, segments } = area.attribute;
25624
- let direction = Direction.ROW;
25625
- let endP;
25626
- let startP;
25627
- if (segments) {
25628
- const endSeg = segments[segments.length - 1];
25629
- const startSeg = segments[0];
25630
- startP = startSeg.points[0];
25631
- endP = endSeg.points[endSeg.points.length - 1];
25632
- }
25633
- else {
25634
- startP = points[0];
25635
- endP = points[points.length - 1];
25636
- }
25637
- const xTotalLength = abs(endP.x - startP.x);
25638
- const yTotalLength = abs(endP.y - startP.y);
25639
- if (endP.x1 == null) {
25640
- direction = Direction.ROW;
25641
- }
25642
- else if (endP.y1 == null) {
25643
- direction = Direction.COLUMN;
25644
- }
25645
- else if (!Number.isFinite(xTotalLength + yTotalLength)) {
25646
- direction = Direction.ROW;
25647
- }
25648
- else {
25649
- direction = xTotalLength > yTotalLength ? Direction.ROW : Direction.COLUMN;
25650
- }
25688
+ const direction = (_a = cache.direction) !== null && _a !== void 0 ? _a : cache.top.direction;
25651
25689
  drawAreaSegments(context, cache, clipRange, {
25652
25690
  offsetX,
25653
25691
  offsetY,
@@ -27288,6 +27326,21 @@ function createMiniappApp(options = {}) {
27288
27326
  return new MiniappEntry(options);
27289
27327
  }
27290
27328
 
27329
+ function previousPoint(segments, index, connectedType) {
27330
+ for (let i = index - 1; i >= 0; i--) {
27331
+ const points = segments[i].points;
27332
+ for (let j = points.length - 1; j >= 0; j--) {
27333
+ const point = points[j];
27334
+ if (point.defined !== false) {
27335
+ return point;
27336
+ }
27337
+ if (connectedType !== 'connect') {
27338
+ return undefined;
27339
+ }
27340
+ }
27341
+ }
27342
+ return undefined;
27343
+ }
27291
27344
  class DefaultIncrementalCanvasAreaRender extends DefaultCanvasAreaRender {
27292
27345
  constructor() {
27293
27346
  super(...arguments);
@@ -27301,7 +27354,7 @@ class DefaultIncrementalCanvasAreaRender extends DefaultCanvasAreaRender {
27301
27354
  return;
27302
27355
  }
27303
27356
  const areaAttribute = getTheme(area).area;
27304
- const { fill = areaAttribute.fill, fillOpacity = areaAttribute.fillOpacity, opacity = areaAttribute.opacity, visible = areaAttribute.visible } = area.attribute;
27357
+ const { fill = areaAttribute.fill, fillOpacity = areaAttribute.fillOpacity, opacity = areaAttribute.opacity, visible = areaAttribute.visible, connectedType = areaAttribute.connectedType } = area.attribute;
27305
27358
  const fVisible = fillVisible(opacity, fillOpacity, fill);
27306
27359
  const doFill = runFill(fill);
27307
27360
  if (!(area.valid && visible)) {
@@ -27313,22 +27366,33 @@ class DefaultIncrementalCanvasAreaRender extends DefaultCanvasAreaRender {
27313
27366
  if (!(fVisible || fillCb)) {
27314
27367
  return;
27315
27368
  }
27316
- for (let i = startAtIdx; i < startAtIdx + length; i++) {
27317
- this.drawIncreaseSegment(area, context, segments[i - 1], segments[i], area.attribute.segments[i], [areaAttribute, area.attribute], x, y);
27369
+ const endIndex = Math.min(startAtIdx + length, segments.length);
27370
+ for (let i = startAtIdx; i < endIndex; i++) {
27371
+ if (!segments[i].points.some(p => p.defined !== false)) {
27372
+ continue;
27373
+ }
27374
+ this.drawIncreaseSegment(area, context, segments[i - 1], segments[i], area.attribute.segments[i], [areaAttribute, area.attribute], x, y, { connectedType, startPoint: previousPoint(segments, i, connectedType) });
27318
27375
  }
27319
27376
  }
27320
27377
  else {
27321
27378
  super.drawShape(area, context, x, y, drawContext, params, fillCb);
27322
27379
  }
27323
27380
  }
27324
- drawIncreaseSegment(area, context, lastSeg, seg, attribute, defaultAttribute, offsetX, offsetY) {
27381
+ drawIncreaseSegment(area, context, lastSeg, seg, attribute, defaultAttribute, offsetX, offsetY, continuity) {
27382
+ var _a, _b;
27325
27383
  if (!seg) {
27326
27384
  return;
27327
27385
  }
27386
+ const connectedType = (_b = (_a = continuity === null || continuity === void 0 ? void 0 : continuity.connectedType) !== null && _a !== void 0 ? _a : area.attribute.connectedType) !== null && _b !== void 0 ? _b : getTheme(area).area.connectedType;
27387
+ const startPoint = continuity
27388
+ ? continuity.startPoint
27389
+ : lastSeg && getAreaPointRuns(lastSeg.points, connectedType).tail;
27328
27390
  context.beginPath();
27329
27391
  drawIncrementalAreaSegments(context.camera ? context : context.nativeContext, lastSeg, seg, {
27330
27392
  offsetX,
27331
- offsetY
27393
+ offsetY,
27394
+ connectedType,
27395
+ startPoint
27332
27396
  });
27333
27397
  context.setShadowBlendStyle && context.setShadowBlendStyle(area, attribute, defaultAttribute);
27334
27398
  context.setCommonStyle(area, attribute, offsetX, offsetY, defaultAttribute);
@@ -0,0 +1,11 @@
1
+ import { type IPointLike } from '@visactor/vutils';
2
+ import type { IAreaCacheItem, IAreaSegment, ICurveType, IDirection } from '../interface';
3
+ export interface AreaRenderCacheItem extends IAreaCacheItem {
4
+ sourceSegmentIndex: number;
5
+ direction: IDirection;
6
+ }
7
+ export declare function getAreaPointRuns(points: IPointLike[], connectedType: 'none' | 'connect', startPoint?: IPointLike): {
8
+ runs: IPointLike[][];
9
+ tail: IPointLike;
10
+ };
11
+ export declare function calcAreaCache(points: IPointLike[] | undefined, segments: IAreaSegment[] | undefined, curveType: ICurveType, connectedType: 'none' | 'connect', curveTension: number): AreaRenderCacheItem | AreaRenderCacheItem[] | null;
@@ -0,0 +1,113 @@
1
+ import { abs } from "@visactor/vutils";
2
+
3
+ import { Direction } from "./enums";
4
+
5
+ import { calcLineCache } from "./segment";
6
+
7
+ import { LineCurve } from "./segment/curve/line";
8
+
9
+ export function getAreaPointRuns(points, connectedType, startPoint) {
10
+ const runs = [];
11
+ if (!points.some((p => !1 === p.defined))) {
12
+ const run = startPoint ? [ startPoint, ...points ] : points;
13
+ return run.length && runs.push(run), {
14
+ runs: runs,
15
+ tail: run[run.length - 1]
16
+ };
17
+ }
18
+ let run = startPoint ? [ startPoint ] : [];
19
+ for (let i = 0; i < points.length; i++) {
20
+ const point = points[i];
21
+ !1 !== point.defined ? run.push(point) : "connect" !== connectedType && (run.length && runs.push(run),
22
+ run = []);
23
+ }
24
+ return run.length && runs.push(run), {
25
+ runs: runs,
26
+ tail: run[run.length - 1]
27
+ };
28
+ }
29
+
30
+ function joinAreaPaths(paths) {
31
+ var _a;
32
+ if (1 === paths.length) return paths[0];
33
+ const curves = [];
34
+ for (let i = 0; i < paths.length; i++) {
35
+ const next = paths[i].curves;
36
+ if (curves.length) {
37
+ const previous = curves[curves.length - 1], gap = new LineCurve(null !== (_a = previous.p3) && void 0 !== _a ? _a : previous.p1, next[0].p0);
38
+ gap.defined = !1, gap.originP1 = previous.originP2, gap.originP2 = next[0].originP1,
39
+ curves.push(gap);
40
+ }
41
+ for (let j = 0; j < next.length; j++) curves.push(next[j]);
42
+ }
43
+ const path = paths[paths.length - 1];
44
+ return path.curves = curves, path.length = NaN, path;
45
+ }
46
+
47
+ function compileAreaRuns(runs, curveType, curveTension, sourceSegmentIndex, topStart, bottomStart) {
48
+ var _a, _b, _c, _d;
49
+ const tops = [], bottoms = [], bottomType = "stepBefore" === curveType ? "stepAfter" : "stepAfter" === curveType ? "stepBefore" : curveType;
50
+ for (let i = 0; i < runs.length; i++) {
51
+ const points = runs[i], startPoint = 0 === i ? topStart : void 0;
52
+ if (points.length < 2 - Number(!!startPoint)) continue;
53
+ const bottomPoints = [];
54
+ for (let j = points.length - 1; j >= 0; j--) {
55
+ const p = points[j];
56
+ bottomPoints.push({
57
+ x: null !== (_a = p.x1) && void 0 !== _a ? _a : p.x,
58
+ y: null !== (_b = p.y1) && void 0 !== _b ? _b : p.y
59
+ });
60
+ }
61
+ 0 === i && bottomStart && bottomPoints.push({
62
+ x: null !== (_c = bottomStart.x1) && void 0 !== _c ? _c : bottomStart.x,
63
+ y: null !== (_d = bottomStart.y1) && void 0 !== _d ? _d : bottomStart.y
64
+ });
65
+ const top = calcLineCache(points, curveType, {
66
+ startPoint: startPoint,
67
+ curveTension: curveTension
68
+ }), bottom = calcLineCache(bottomPoints, bottomType, {
69
+ curveTension: curveTension
70
+ });
71
+ (null == top ? void 0 : top.curves.length) && (null == bottom ? void 0 : bottom.curves.length) && (tops.push(top),
72
+ bottoms.push(bottom));
73
+ }
74
+ return tops.length ? {
75
+ top: joinAreaPaths(tops),
76
+ bottom: joinAreaPaths(bottoms.reverse()),
77
+ sourceSegmentIndex: sourceSegmentIndex,
78
+ direction: Direction.ROW
79
+ } : null;
80
+ }
81
+
82
+ export function calcAreaCache(points, segments, curveType, connectedType, curveTension) {
83
+ var _a;
84
+ const caches = [];
85
+ let tail, topTail, first, last;
86
+ const count = segments ? segments.length : 1;
87
+ for (let i = 0; i < count; i++) {
88
+ const segmentPoints = segments ? segments[i].points : null != points ? points : [], result = getAreaPointRuns(segmentPoints, connectedType), canContinue = "connect" === connectedType || !1 !== (null === (_a = segmentPoints[0]) || void 0 === _a ? void 0 : _a.defined);
89
+ if (result.runs.length) {
90
+ first = null != first ? first : result.runs[0][0];
91
+ const lastRun = result.runs[result.runs.length - 1];
92
+ last = lastRun[lastRun.length - 1];
93
+ }
94
+ const cache = compileAreaRuns(result.runs, curveType, curveTension, i, canContinue ? topTail : void 0, canContinue ? tail : void 0);
95
+ if (cache && caches.push(cache), result.tail) {
96
+ tail = result.tail;
97
+ const lastRun = result.runs[result.runs.length - 1];
98
+ topTail = cache && (1 === result.runs.length || lastRun.length > 1) ? {
99
+ x: cache.top.endX,
100
+ y: cache.top.endY
101
+ } : tail;
102
+ } else "connect" !== connectedType && segmentPoints.length && (tail = topTail = void 0);
103
+ }
104
+ if (!caches.length) return null;
105
+ let direction = Direction.ROW;
106
+ if (null != last.x1) {
107
+ const dx = abs(last.x - first.x), dy = abs(last.y - first.y);
108
+ (null == last.y1 || Number.isFinite(dx + dy) && dy >= dx) && (direction = Direction.COLUMN);
109
+ }
110
+ for (let i = 0; i < caches.length; i++) caches[i].direction = direction;
111
+ return segments ? caches : caches[0];
112
+ }
113
+ //# sourceMappingURL=area-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/common/area-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAmB,MAAM,kBAAkB,CAAC;AAExD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAQjD,MAAM,UAAU,gBAAgB,CAAC,MAAoB,EAAE,aAAiC,EAAE,UAAuB;IAC/G,MAAM,IAAI,GAAmB,EAAE,CAAC;IAChC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,KAAK,CAAC,EAAE;QAC1C,MAAM,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAC1D,IAAI,GAAG,CAAC,MAAM,EAAE;YACd,IAAI,CAAC,IAAI,CAA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I,CAAC,EAAE,IAAI,IAAI,EAAE;QACnB,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACjC,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,IAAI,CAAC,EAAE,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE;YAC7D,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC;SAC9B;KACF;IACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACtC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC;KACjC;IACD,OAAO,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC","file":"area-cache.js","sourcesContent":["import { abs, type IPointLike } from '@visactor/vutils';\nimport type { IAreaCacheItem, IAreaSegment, ICurveType, IDirection, ISegPath2D } from '../interface';\nimport { Direction } from './enums';\nimport { calcLineCache } from './segment';\nimport type { SegContext } from './seg-context';\nimport { LineCurve } from './segment/curve/line';\n\nexport interface AreaRenderCacheItem extends IAreaCacheItem {\n sourceSegmentIndex: number;\n direction: IDirection;\n}\n\n/** Select both boundaries together, before interpolation can read undefined coordinates. */\nexport function getAreaPointRuns(points: IPointLike[], connectedType: 'none' | 'connect', startPoint?: IPointLike) {\n const runs: IPointLike[][] = [];\n if (!points.some(p => p.defined === false)) {\n const run = startPoint ? [startPoint, ...points] : points;\n if (run.length) {\n runs.push(run);\n }\n return { runs, tail: run[run.length - 1] };\n }\n\n let run: IPointLike[] = startPoint ? [startPoint] : [];\n for (let i = 0; i < points.length; i++) {\n const point = points[i];\n if (point.defined !== false) {\n run.push(point);\n } else if (connectedType !== 'connect') {\n if (run.length) {\n runs.push(run);\n }\n run = [];\n }\n }\n if (run.length) {\n runs.push(run);\n }\n return { runs, tail: run[run.length - 1] };\n}\n\n/** Join completed caches without restarting interpolation across a missing-data gap. */\nfunction joinAreaPaths(paths: ISegPath2D[]): ISegPath2D {\n if (paths.length === 1) {\n return paths[0];\n }\n const curves: ISegPath2D['curves'] = [];\n for (let i = 0; i < paths.length; i++) {\n const next = paths[i].curves;\n if (curves.length) {\n const previous = curves[curves.length - 1];\n const gap = new LineCurve(previous.p3 ?? previous.p1, next[0].p0);\n gap.defined = false;\n gap.originP1 = previous.originP2;\n gap.originP2 = next[0].originP1;\n curves.push(gap);\n }\n for (let j = 0; j < next.length; j++) {\n curves.push(next[j]);\n }\n }\n // These are completed, read-only drawing caches. Reuse the final context so its\n // endX/endY still describe the final curve, without copying curve objects.\n const path = paths[paths.length - 1] as SegContext;\n path.curves = curves;\n path.length = NaN;\n return path;\n}\n\nfunction compileAreaRuns(\n runs: IPointLike[][],\n curveType: ICurveType,\n curveTension: number,\n sourceSegmentIndex: number,\n topStart?: IPointLike,\n bottomStart?: IPointLike\n): AreaRenderCacheItem | null {\n const tops: ISegPath2D[] = [];\n const bottoms: ISegPath2D[] = [];\n const bottomType = curveType === 'stepBefore' ? 'stepAfter' : curveType === 'stepAfter' ? 'stepBefore' : curveType;\n for (let i = 0; i < runs.length; i++) {\n const points = runs[i];\n const startPoint = i === 0 ? topStart : undefined;\n if (points.length < 2 - Number(!!startPoint)) {\n continue;\n }\n const bottomPoints: IPointLike[] = [];\n for (let j = points.length - 1; j >= 0; j--) {\n const p = points[j];\n bottomPoints.push({ x: p.x1 ?? p.x, y: p.y1 ?? p.y });\n }\n if (i === 0 && bottomStart) {\n bottomPoints.push({ x: bottomStart.x1 ?? bottomStart.x, y: bottomStart.y1 ?? bottomStart.y });\n }\n // Preserve the curve generators' existing startPoint/closure semantics. In\n // particular, don't prepend a styled segment's startPoint to its input array.\n const top = calcLineCache(points, curveType, { startPoint, curveTension });\n const bottom = calcLineCache(bottomPoints, bottomType, { curveTension });\n if (top?.curves.length && bottom?.curves.length) {\n tops.push(top);\n bottoms.push(bottom);\n }\n }\n if (!tops.length) {\n return null;\n }\n return {\n top: joinAreaPaths(tops),\n bottom: joinAreaPaths(bottoms.reverse()),\n sourceSegmentIndex,\n direction: Direction.ROW\n };\n}\n\nexport function calcAreaCache(\n points: IPointLike[] | undefined,\n segments: IAreaSegment[] | undefined,\n curveType: ICurveType,\n connectedType: 'none' | 'connect',\n curveTension: number\n): AreaRenderCacheItem | AreaRenderCacheItem[] | null {\n const caches: AreaRenderCacheItem[] = [];\n let tail: IPointLike;\n let topTail: IPointLike;\n let first: IPointLike;\n let last: IPointLike;\n const count = segments ? segments.length : 1;\n for (let i = 0; i < count; i++) {\n const segmentPoints = segments ? segments[i].points : points ?? [];\n const result = getAreaPointRuns(segmentPoints, connectedType);\n const canContinue = connectedType === 'connect' || segmentPoints[0]?.defined !== false;\n if (result.runs.length) {\n first = first ?? result.runs[0][0];\n const lastRun = result.runs[result.runs.length - 1];\n last = lastRun[lastRun.length - 1];\n }\n const cache = compileAreaRuns(\n result.runs,\n curveType,\n curveTension,\n i,\n canContinue ? topTail : undefined,\n canContinue ? tail : undefined\n );\n if (cache) {\n caches.push(cache);\n }\n if (result.tail) {\n tail = result.tail;\n const lastRun = result.runs[result.runs.length - 1];\n topTail =\n cache && (result.runs.length === 1 || lastRun.length > 1) ? { x: cache.top.endX, y: cache.top.endY } : tail;\n } else if (connectedType !== 'connect' && segmentPoints.length) {\n tail = topTail = undefined;\n }\n }\n if (!caches.length) {\n return null;\n }\n let direction = Direction.ROW;\n if (last.x1 != null) {\n const dx = abs(last.x - first.x);\n const dy = abs(last.y - first.y);\n if (last.y1 == null || (Number.isFinite(dx + dy) && dy >= dx)) {\n direction = Direction.COLUMN;\n }\n }\n for (let i = 0; i < caches.length; i++) {\n caches[i].direction = direction;\n }\n return segments ? caches : caches[0];\n}\n"]}
@@ -36,5 +36,4 @@ export function quadPointAt(p0, p1, p2, t) {
36
36
 
37
37
  export function quadLength(p0, p1, p2, iterationCount) {
38
38
  return snapLength([ p0.x, p1.x, p2.x ], [ p0.y, p1.y, p2.y ]);
39
- }
40
- //# sourceMappingURL=bezier-utils.js.map
39
+ }