@antv/g-webgpu 1.7.1 → 1.7.2

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/index.umd.js CHANGED
@@ -10110,9 +10110,10 @@
10110
10110
  _proto.shouldMerge = function shouldMerge(object, index) {
10111
10111
  if (!this.instance) {
10112
10112
  return true;
10113
- }
10113
+ } // Path / Polyline could be rendered as Line
10114
+
10114
10115
 
10115
- if (this.instance.nodeName !== object.nodeName) {
10116
+ if (this.instance.nodeName !== object.nodeName && this.instance.nodeName !== object.renderable.proxyNodeName && this.instance.renderable.proxyNodeName !== object.nodeName && this.instance.renderable.proxyNodeName !== object.renderable.proxyNodeName) {
10116
10117
  return false;
10117
10118
  } // can't be merged when using clipPath
10118
10119
 
@@ -11133,26 +11134,123 @@
11133
11134
  var indices = [];
11134
11135
  var offset = 0;
11135
11136
  objects.forEach(function (object) {
11136
- var line = object;
11137
- var _line$parsedStyle = line.parsedStyle,
11138
- x1 = _line$parsedStyle.x1,
11139
- y1 = _line$parsedStyle.y1,
11140
- x2 = _line$parsedStyle.x2,
11141
- y2 = _line$parsedStyle.y2,
11142
- z1 = _line$parsedStyle.z1,
11143
- z2 = _line$parsedStyle.z2,
11144
- defX = _line$parsedStyle.defX,
11145
- defY = _line$parsedStyle.defY,
11146
- lineCap = _line$parsedStyle.lineCap,
11147
- isBillboard = _line$parsedStyle.isBillboard;
11148
-
11149
- var _this$calcOffset = _this.calcOffset(object),
11137
+ var parsedLineStyleProps;
11138
+ var totalLength;
11139
+
11140
+ if (object.nodeName === g.Shape.LINE) {
11141
+ parsedLineStyleProps = object.parsedStyle;
11142
+ totalLength = object.getTotalLength();
11143
+ } else if (object.nodeName === g.Shape.POLYLINE) {
11144
+ var _object$parsedStyle = object.parsedStyle,
11145
+ points = _object$parsedStyle.points.points,
11146
+ _defX = _object$parsedStyle.defX,
11147
+ _defY = _object$parsedStyle.defY,
11148
+ _lineCap = _object$parsedStyle.lineCap,
11149
+ markerStart = _object$parsedStyle.markerStart,
11150
+ markerEnd = _object$parsedStyle.markerEnd,
11151
+ markerStartOffset = _object$parsedStyle.markerStartOffset,
11152
+ markerEndOffset = _object$parsedStyle.markerEndOffset;
11153
+ parsedLineStyleProps = {
11154
+ // @ts-ignore
11155
+ x1: {
11156
+ value: points[0][0]
11157
+ },
11158
+ // @ts-ignore
11159
+ y1: {
11160
+ value: points[0][1]
11161
+ },
11162
+ // @ts-ignore
11163
+ x2: {
11164
+ value: points[points.length - 1][0]
11165
+ },
11166
+ // @ts-ignore
11167
+ y2: {
11168
+ value: points[points.length - 1][1]
11169
+ },
11170
+ // @ts-ignore
11171
+ z1: {
11172
+ value: 0
11173
+ },
11174
+ // @ts-ignore
11175
+ z2: {
11176
+ value: 0
11177
+ },
11178
+ defX: _defX,
11179
+ defY: _defY,
11180
+ lineCap: _lineCap,
11181
+ isBillboard: true,
11182
+ markerStart: markerStart,
11183
+ markerEnd: markerEnd,
11184
+ markerStartOffset: markerStartOffset,
11185
+ markerEndOffset: markerEndOffset
11186
+ };
11187
+ totalLength = object.getTotalLength();
11188
+ } else if (object.nodeName === g.Shape.PATH) {
11189
+ var _object$parsedStyle2 = object.parsedStyle,
11190
+ curve = _object$parsedStyle2.path.curve,
11191
+ _defX2 = _object$parsedStyle2.defX,
11192
+ _defY2 = _object$parsedStyle2.defY,
11193
+ _lineCap2 = _object$parsedStyle2.lineCap,
11194
+ _markerStart = _object$parsedStyle2.markerStart,
11195
+ _markerEnd = _object$parsedStyle2.markerEnd,
11196
+ _markerStartOffset = _object$parsedStyle2.markerStartOffset,
11197
+ _markerEndOffset = _object$parsedStyle2.markerEndOffset;
11198
+ parsedLineStyleProps = {
11199
+ // @ts-ignore
11200
+ x1: {
11201
+ value: curve[0][1]
11202
+ },
11203
+ // @ts-ignore
11204
+ y1: {
11205
+ value: curve[0][2]
11206
+ },
11207
+ // @ts-ignore
11208
+ x2: {
11209
+ value: curve[1][5]
11210
+ },
11211
+ // @ts-ignore
11212
+ y2: {
11213
+ value: curve[1][6]
11214
+ },
11215
+ // @ts-ignore
11216
+ z1: {
11217
+ value: 0
11218
+ },
11219
+ // @ts-ignore
11220
+ z2: {
11221
+ value: 0
11222
+ },
11223
+ defX: _defX2,
11224
+ defY: _defY2,
11225
+ lineCap: _lineCap2,
11226
+ isBillboard: true,
11227
+ markerStart: _markerStart,
11228
+ markerEnd: _markerEnd,
11229
+ markerStartOffset: _markerStartOffset,
11230
+ markerEndOffset: _markerEndOffset
11231
+ };
11232
+ totalLength = object.getTotalLength();
11233
+ }
11234
+
11235
+ var _parsedLineStyleProps = parsedLineStyleProps,
11236
+ x1 = _parsedLineStyleProps.x1,
11237
+ y1 = _parsedLineStyleProps.y1,
11238
+ x2 = _parsedLineStyleProps.x2,
11239
+ y2 = _parsedLineStyleProps.y2,
11240
+ z1 = _parsedLineStyleProps.z1,
11241
+ z2 = _parsedLineStyleProps.z2,
11242
+ defX = _parsedLineStyleProps.defX,
11243
+ defY = _parsedLineStyleProps.defY,
11244
+ lineCap = _parsedLineStyleProps.lineCap,
11245
+ isBillboard = _parsedLineStyleProps.isBillboard;
11246
+
11247
+ var _this$calcOffset = _this.calcOffset(parsedLineStyleProps),
11150
11248
  startOffsetX = _this$calcOffset.startOffsetX,
11151
11249
  startOffsetY = _this$calcOffset.startOffsetY,
11152
11250
  endOffsetX = _this$calcOffset.endOffsetX,
11153
11251
  endOffsetY = _this$calcOffset.endOffsetY;
11154
11252
 
11155
- var _this$calcDash = _this.calcDash(object),
11253
+ var _this$calcDash = _this.calcDash(parsedLineStyleProps, totalLength),
11156
11254
  dashOffset = _this$calcDash.dashOffset,
11157
11255
  dashSegmentPercent = _this$calcDash.dashSegmentPercent,
11158
11256
  dashRatioInEachSegment = _this$calcDash.dashRatioInEachSegment;
@@ -11234,20 +11332,114 @@
11234
11332
 
11235
11333
  this.updateBatchedAttribute(objects, startIndex, name, value);
11236
11334
 
11237
- if (name === 'x1' || name === 'y1' || name === 'x2' || name === 'y2' || name === 'z1' || name === 'z2' || name === 'markerStartOffset' || name === 'markerEndOffset' || name === 'markerStart' || name === 'markerEnd') {
11335
+ if (name === 'x1' || name === 'y1' || name === 'x2' || name === 'y2' || name === 'z1' || name === 'z2' || name === 'markerStartOffset' || name === 'markerEndOffset' || name === 'markerStart' || name === 'markerEnd' || name === 'points' || name === 'path') {
11238
11336
  var packed = [];
11239
11337
  objects.forEach(function (object) {
11240
- var _object$parsedStyle = object.parsedStyle,
11241
- x1 = _object$parsedStyle.x1,
11242
- y1 = _object$parsedStyle.y1,
11243
- x2 = _object$parsedStyle.x2,
11244
- y2 = _object$parsedStyle.y2,
11245
- z1 = _object$parsedStyle.z1,
11246
- z2 = _object$parsedStyle.z2,
11247
- defX = _object$parsedStyle.defX,
11248
- defY = _object$parsedStyle.defY;
11249
-
11250
- var _this2$calcOffset = _this2.calcOffset(object),
11338
+ var parsedLineStyleProps;
11339
+
11340
+ if (object.nodeName === g.Shape.LINE) {
11341
+ parsedLineStyleProps = object.parsedStyle;
11342
+ } else if (object.nodeName === g.Shape.POLYLINE && object.renderable.proxyNodeName === g.Shape.LINE) {
11343
+ var _object$parsedStyle3 = object.parsedStyle,
11344
+ points = _object$parsedStyle3.points.points,
11345
+ _defX3 = _object$parsedStyle3.defX,
11346
+ _defY3 = _object$parsedStyle3.defY,
11347
+ lineCap = _object$parsedStyle3.lineCap,
11348
+ markerStart = _object$parsedStyle3.markerStart,
11349
+ markerEnd = _object$parsedStyle3.markerEnd,
11350
+ markerStartOffset = _object$parsedStyle3.markerStartOffset,
11351
+ markerEndOffset = _object$parsedStyle3.markerEndOffset;
11352
+ parsedLineStyleProps = {
11353
+ // @ts-ignore
11354
+ x1: {
11355
+ value: points[0][0]
11356
+ },
11357
+ // @ts-ignore
11358
+ y1: {
11359
+ value: points[0][1]
11360
+ },
11361
+ // @ts-ignore
11362
+ x2: {
11363
+ value: points[points.length - 1][0]
11364
+ },
11365
+ // @ts-ignore
11366
+ y2: {
11367
+ value: points[points.length - 1][1]
11368
+ },
11369
+ // @ts-ignore
11370
+ z1: {
11371
+ value: 0
11372
+ },
11373
+ // @ts-ignore
11374
+ z2: {
11375
+ value: 0
11376
+ },
11377
+ defX: _defX3,
11378
+ defY: _defY3,
11379
+ lineCap: lineCap,
11380
+ isBillboard: true,
11381
+ markerStart: markerStart,
11382
+ markerEnd: markerEnd,
11383
+ markerStartOffset: markerStartOffset,
11384
+ markerEndOffset: markerEndOffset
11385
+ };
11386
+ } else if (object.nodeName === g.Shape.PATH && object.renderable.proxyNodeName === g.Shape.LINE) {
11387
+ var _object$parsedStyle4 = object.parsedStyle,
11388
+ curve = _object$parsedStyle4.path.curve,
11389
+ _defX4 = _object$parsedStyle4.defX,
11390
+ _defY4 = _object$parsedStyle4.defY,
11391
+ _lineCap3 = _object$parsedStyle4.lineCap,
11392
+ _markerStart2 = _object$parsedStyle4.markerStart,
11393
+ _markerEnd2 = _object$parsedStyle4.markerEnd,
11394
+ _markerStartOffset2 = _object$parsedStyle4.markerStartOffset,
11395
+ _markerEndOffset2 = _object$parsedStyle4.markerEndOffset;
11396
+ parsedLineStyleProps = {
11397
+ // @ts-ignore
11398
+ x1: {
11399
+ value: curve[0][1]
11400
+ },
11401
+ // @ts-ignore
11402
+ y1: {
11403
+ value: curve[0][2]
11404
+ },
11405
+ // @ts-ignore
11406
+ x2: {
11407
+ value: curve[1][5]
11408
+ },
11409
+ // @ts-ignore
11410
+ y2: {
11411
+ value: curve[1][6]
11412
+ },
11413
+ // @ts-ignore
11414
+ z1: {
11415
+ value: 0
11416
+ },
11417
+ // @ts-ignore
11418
+ z2: {
11419
+ value: 0
11420
+ },
11421
+ defX: _defX4,
11422
+ defY: _defY4,
11423
+ lineCap: _lineCap3,
11424
+ isBillboard: true,
11425
+ markerStart: _markerStart2,
11426
+ markerEnd: _markerEnd2,
11427
+ markerStartOffset: _markerStartOffset2,
11428
+ markerEndOffset: _markerEndOffset2
11429
+ };
11430
+ }
11431
+
11432
+ var _parsedLineStyleProps2 = parsedLineStyleProps,
11433
+ x1 = _parsedLineStyleProps2.x1,
11434
+ y1 = _parsedLineStyleProps2.y1,
11435
+ x2 = _parsedLineStyleProps2.x2,
11436
+ y2 = _parsedLineStyleProps2.y2,
11437
+ z1 = _parsedLineStyleProps2.z1,
11438
+ z2 = _parsedLineStyleProps2.z2,
11439
+ defX = _parsedLineStyleProps2.defX,
11440
+ defY = _parsedLineStyleProps2.defY;
11441
+
11442
+ var _this2$calcOffset = _this2.calcOffset(parsedLineStyleProps),
11251
11443
  startOffsetX = _this2$calcOffset.startOffsetX,
11252
11444
  startOffsetY = _this2$calcOffset.startOffsetY,
11253
11445
  endOffsetX = _this2$calcOffset.endOffsetX,
@@ -11259,7 +11451,9 @@
11259
11451
  } else if (name === 'lineDashOffset' || name === 'lineDash') {
11260
11452
  var _packed = [];
11261
11453
  objects.forEach(function (object) {
11262
- var _this2$calcDash = _this2.calcDash(object),
11454
+ var totalLength = object.getTotalLength();
11455
+
11456
+ var _this2$calcDash = _this2.calcDash(object.parsedStyle, totalLength),
11263
11457
  dashOffset = _this2$calcDash.dashOffset,
11264
11458
  dashSegmentPercent = _this2$calcDash.dashSegmentPercent,
11265
11459
  dashRatioInEachSegment = _this2$calcDash.dashRatioInEachSegment;
@@ -11279,16 +11473,15 @@
11279
11473
  }
11280
11474
  };
11281
11475
 
11282
- _proto.calcOffset = function calcOffset(line) {
11283
- var _line$parsedStyle2 = line.parsedStyle,
11284
- x1 = _line$parsedStyle2.x1,
11285
- y1 = _line$parsedStyle2.y1,
11286
- x2 = _line$parsedStyle2.x2,
11287
- y2 = _line$parsedStyle2.y2,
11288
- markerStart = _line$parsedStyle2.markerStart,
11289
- markerEnd = _line$parsedStyle2.markerEnd,
11290
- markerStartOffset = _line$parsedStyle2.markerStartOffset,
11291
- markerEndOffset = _line$parsedStyle2.markerEndOffset;
11476
+ _proto.calcOffset = function calcOffset(parsedStyle) {
11477
+ var x1 = parsedStyle.x1,
11478
+ y1 = parsedStyle.y1,
11479
+ x2 = parsedStyle.x2,
11480
+ y2 = parsedStyle.y2,
11481
+ markerStart = parsedStyle.markerStart,
11482
+ markerEnd = parsedStyle.markerEnd,
11483
+ markerStartOffset = parsedStyle.markerStartOffset,
11484
+ markerEndOffset = parsedStyle.markerEndOffset;
11292
11485
  var startOffsetX = 0;
11293
11486
  var startOffsetY = 0;
11294
11487
  var endOffsetX = 0;
@@ -11321,11 +11514,9 @@
11321
11514
  };
11322
11515
  };
11323
11516
 
11324
- _proto.calcDash = function calcDash(line) {
11325
- var _line$parsedStyle3 = line.parsedStyle,
11326
- lineDash = _line$parsedStyle3.lineDash,
11327
- lineDashOffset = _line$parsedStyle3.lineDashOffset;
11328
- var totalLength = line.getTotalLength();
11517
+ _proto.calcDash = function calcDash(parsedLineStyle, totalLength) {
11518
+ var lineDash = parsedLineStyle.lineDash,
11519
+ lineDashOffset = parsedLineStyle.lineDashOffset;
11329
11520
  var dashOffset = 0;
11330
11521
  var dashSegmentPercent = 1;
11331
11522
  var dashRatioInEachSegment = 0;
@@ -13762,6 +13953,10 @@
13762
13953
  named: g.Shape.ELLIPSE
13763
13954
  }]
13764
13955
  })], CircleRenderer);
13956
+ /**
13957
+ * Try downgrading the "simple" Path / Polyline to InstancedLine.
13958
+ * @see https://github.com/antvis/G/issues/1113
13959
+ */
13765
13960
 
13766
13961
  var PathRenderer = /*#__PURE__*/function (_Batch) {
13767
13962
  _inheritsLoose$2(PathRenderer, _Batch);
@@ -13774,7 +13969,7 @@
13774
13969
  }
13775
13970
 
13776
13971
  _this = _Batch.call.apply(_Batch, [this].concat(args)) || this;
13777
- _this.meshes = [FillMesh, LineMesh];
13972
+ _this.meshes = [FillMesh, LineMesh, InstancedLineMesh];
13778
13973
  return _this;
13779
13974
  }
13780
13975
 
@@ -13792,7 +13987,9 @@
13792
13987
  var hasStroke = stroke && !stroke.isNone;
13793
13988
  var hasDash = lineDash && lineDash.length && lineDash.every(function (item) {
13794
13989
  return item.value !== 0;
13795
- }); // Polyline don't need fill
13990
+ });
13991
+ var isLine = this.isLine(object);
13992
+ object.renderable.proxyNodeName = isLine ? g.Shape.LINE : null; // Polyline don't need fill
13796
13993
 
13797
13994
  if (index === 0 && (object.nodeName === g.Shape.POLYLINE || fill.isNone)) {
13798
13995
  return false;
@@ -13800,7 +13997,7 @@
13800
13997
 
13801
13998
 
13802
13999
  if (index === 1) {
13803
- if (strokeOpacity.value === 0 || opacity.value === 0 || lineWidth.value === 0 || !hasStroke) {
14000
+ if (isLine || strokeOpacity.value === 0 || opacity.value === 0 || lineWidth.value === 0 || !hasStroke) {
13804
14001
  return false;
13805
14002
  }
13806
14003
 
@@ -13808,11 +14005,56 @@
13808
14005
  // @see https://github.com/antvis/g/issues/824
13809
14006
  return hasDash;
13810
14007
  }
14008
+ } // use Line for simple Path
14009
+
14010
+
14011
+ if (index === 2) {
14012
+ return isLine;
13811
14013
  }
13812
14014
 
13813
14015
  return true;
13814
14016
  };
13815
14017
 
14018
+ _proto.isLine = function isLine(object) {
14019
+ if (object.nodeName === g.Shape.PATH) {
14020
+ var curve = object.parsedStyle.path.curve;
14021
+ var eps = 0.01; // only contains M & L commands
14022
+
14023
+ if (curve.length === 2 && curve[0][0] === 'M' && curve[1][0] === 'C') {
14024
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
14025
+ var _curve$ = curve[0],
14026
+ _1 = _curve$[0],
14027
+ p1x = _curve$[1],
14028
+ p1y = _curve$[2]; // eslint-disable-next-line @typescript-eslint/no-unused-vars
14029
+
14030
+ var _curve$2 = curve[1],
14031
+ _2 = _curve$2[0],
14032
+ cpx1 = _curve$2[1],
14033
+ cpy1 = _curve$2[2],
14034
+ cpx2 = _curve$2[3],
14035
+ cpy2 = _curve$2[4],
14036
+ p2x = _curve$2[5],
14037
+ p2y = _curve$2[6];
14038
+ var tangent = (p1x - p2x) / (p1y - p2y);
14039
+ return (p1x - cpx1) / (p1y - cpy1) - tangent < eps && (cpx2 - p2x) / (cpy2 - p2y) - tangent < eps;
14040
+ }
14041
+ } else if (object.nodeName === g.Shape.POLYLINE) {
14042
+ var points = object.parsedStyle.points.points;
14043
+
14044
+ var _tangent = (points[1][0] - points[1][1]) / (points[0][0] - points[0][1]);
14045
+
14046
+ for (var i = 1; i < points.length - 1; i++) {
14047
+ if ((points[i + 1][0] - points[i + 1][1]) / (points[i][0] - points[i][1]) !== _tangent) {
14048
+ return false;
14049
+ }
14050
+ }
14051
+
14052
+ return true;
14053
+ }
14054
+
14055
+ return false;
14056
+ };
14057
+
13816
14058
  return PathRenderer;
13817
14059
  }(Batch);
13818
14060