@antv/l7-layers 2.9.25-alpha.0 → 2.9.26-alpha.1

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 (126) hide show
  1. package/es/heatmap/models/heatmap.js +1 -1
  2. package/es/tile/tileFactory/base.d.ts +1 -1
  3. package/es/tile/utils.js +1 -1
  4. package/lib/Geometry/index.js +114 -77
  5. package/lib/Geometry/models/billboard.js +232 -181
  6. package/lib/Geometry/models/index.js +18 -34
  7. package/lib/Geometry/models/plane.js +407 -278
  8. package/lib/Geometry/models/sprite.js +291 -189
  9. package/lib/canvas/index.js +101 -66
  10. package/lib/canvas/models/canvas.js +207 -140
  11. package/lib/canvas/models/index.js +12 -30
  12. package/lib/citybuliding/building.js +98 -63
  13. package/lib/citybuliding/models/build.js +192 -146
  14. package/lib/core/BaseLayer.js +1331 -814
  15. package/lib/core/BaseModel.js +457 -279
  16. package/lib/core/interface.js +40 -53
  17. package/lib/core/schema.js +21 -39
  18. package/lib/core/shape/Path.js +67 -79
  19. package/lib/core/shape/extrude.js +132 -91
  20. package/lib/core/triangulation.js +378 -196
  21. package/lib/earth/index.js +100 -62
  22. package/lib/earth/models/atmosphere.js +146 -112
  23. package/lib/earth/models/base.js +210 -150
  24. package/lib/earth/models/bloomsphere.js +146 -112
  25. package/lib/earth/utils.js +111 -91
  26. package/lib/heatmap/index.js +149 -92
  27. package/lib/heatmap/models/grid.js +118 -91
  28. package/lib/heatmap/models/grid3d.js +155 -123
  29. package/lib/heatmap/models/heatmap.js +475 -338
  30. package/lib/heatmap/models/hexagon.js +121 -92
  31. package/lib/heatmap/models/index.js +22 -37
  32. package/lib/heatmap/triangulation.js +31 -47
  33. package/lib/image/index.js +111 -74
  34. package/lib/image/models/dataImage.js +232 -174
  35. package/lib/image/models/image.js +175 -128
  36. package/lib/image/models/index.js +15 -32
  37. package/lib/index.js +263 -97
  38. package/lib/line/index.js +131 -85
  39. package/lib/line/models/arc.js +352 -237
  40. package/lib/line/models/arc_3d.js +334 -228
  41. package/lib/line/models/earthArc_3d.js +336 -228
  42. package/lib/line/models/great_circle.js +291 -200
  43. package/lib/line/models/half.js +286 -201
  44. package/lib/line/models/index.js +42 -50
  45. package/lib/line/models/line.js +428 -299
  46. package/lib/line/models/linearline.js +277 -203
  47. package/lib/line/models/simpleLine.js +239 -175
  48. package/lib/line/models/tile.js +348 -237
  49. package/lib/line/models/wall.js +327 -235
  50. package/lib/mask/index.js +92 -59
  51. package/lib/mask/models/fill.js +134 -82
  52. package/lib/mask/models/index.js +12 -30
  53. package/lib/plugins/DataMappingPlugin.js +342 -224
  54. package/lib/plugins/DataSourcePlugin.js +102 -87
  55. package/lib/plugins/FeatureScalePlugin.js +330 -240
  56. package/lib/plugins/LayerAnimateStylePlugin.js +61 -55
  57. package/lib/plugins/LayerModelPlugin.js +80 -73
  58. package/lib/plugins/LayerStylePlugin.js +48 -51
  59. package/lib/plugins/LightingPlugin.js +80 -68
  60. package/lib/plugins/MultiPassRendererPlugin.js +91 -65
  61. package/lib/plugins/PixelPickingPlugin.js +150 -109
  62. package/lib/plugins/RegisterStyleAttributePlugin.js +110 -110
  63. package/lib/plugins/ShaderUniformPlugin.js +118 -99
  64. package/lib/plugins/UpdateModelPlugin.js +40 -47
  65. package/lib/plugins/UpdateStyleAttributePlugin.js +93 -75
  66. package/lib/point/index.js +226 -150
  67. package/lib/point/models/earthExtrude.js +279 -201
  68. package/lib/point/models/earthFill.js +287 -202
  69. package/lib/point/models/extrude.js +299 -203
  70. package/lib/point/models/fill.js +406 -275
  71. package/lib/point/models/fillmage.js +365 -256
  72. package/lib/point/models/image.js +241 -168
  73. package/lib/point/models/index.js +46 -52
  74. package/lib/point/models/normal.js +183 -134
  75. package/lib/point/models/radar.js +304 -211
  76. package/lib/point/models/simplePoint.js +194 -142
  77. package/lib/point/models/text.js +608 -385
  78. package/lib/point/models/tile.js +314 -223
  79. package/lib/point/shape/extrude.js +56 -52
  80. package/lib/polygon/index.js +154 -102
  81. package/lib/polygon/models/extrude.js +311 -223
  82. package/lib/polygon/models/fill.js +215 -153
  83. package/lib/polygon/models/index.js +46 -52
  84. package/lib/polygon/models/ocean.js +244 -173
  85. package/lib/polygon/models/tile.js +144 -100
  86. package/lib/polygon/models/water.js +222 -153
  87. package/lib/raster/buffers/triangulation.js +27 -40
  88. package/lib/raster/index.js +115 -75
  89. package/lib/raster/models/index.js +16 -33
  90. package/lib/raster/models/raster.js +178 -135
  91. package/lib/raster/raster.js +187 -132
  92. package/lib/tile/interface.js +4 -16
  93. package/lib/tile/manager/tileConfigManager.js +125 -86
  94. package/lib/tile/manager/tileLayerManager.js +313 -229
  95. package/lib/tile/manager/tilePickerManager.js +192 -123
  96. package/lib/tile/models/tileModel.js +71 -52
  97. package/lib/tile/tileFactory/base.js +432 -309
  98. package/lib/tile/tileFactory/index.js +51 -49
  99. package/lib/tile/tileFactory/line.js +65 -50
  100. package/lib/tile/tileFactory/point.js +65 -50
  101. package/lib/tile/tileFactory/polygon.js +65 -50
  102. package/lib/tile/tileFactory/raster.js +66 -54
  103. package/lib/tile/tileFactory/rasterData.js +88 -76
  104. package/lib/tile/tileFactory/rasterDataLayer.js +97 -62
  105. package/lib/tile/tileFactory/vectorLayer.js +168 -109
  106. package/lib/tile/tileLayer/baseTileLayer.js +420 -221
  107. package/lib/tile/tmsTileLayer.js +110 -67
  108. package/lib/tile/utils.js +110 -92
  109. package/lib/utils/blend.js +59 -79
  110. package/lib/utils/collision-index.js +107 -64
  111. package/lib/utils/dataMappingStyle.js +105 -60
  112. package/lib/utils/extrude_polyline.js +600 -398
  113. package/lib/utils/grid-index.js +163 -111
  114. package/lib/utils/layerData.js +130 -99
  115. package/lib/utils/multiPassRender.js +49 -41
  116. package/lib/utils/polylineNormal.js +148 -96
  117. package/lib/utils/simpleLine.js +100 -85
  118. package/lib/utils/symbol-layout.js +219 -116
  119. package/lib/utils/updateShape.js +15 -41
  120. package/lib/wind/index.js +109 -71
  121. package/lib/wind/models/index.js +12 -30
  122. package/lib/wind/models/utils.js +144 -105
  123. package/lib/wind/models/wind.js +333 -224
  124. package/lib/wind/models/windRender.js +329 -218
  125. package/lib/wind/models/windShader.js +23 -181
  126. package/package.json +6 -6
@@ -1,258 +1,348 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
- var __decorateClass = (decorators, target, key, kind) => {
22
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
23
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
24
- if (decorator = decorators[i])
25
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
26
- if (kind && result)
27
- __defProp(target, key, result);
28
- return result;
29
- };
30
-
31
- // src/plugins/FeatureScalePlugin.ts
32
- var FeatureScalePlugin_exports = {};
33
- __export(FeatureScalePlugin_exports, {
34
- default: () => FeatureScalePlugin
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
35
9
  });
36
- module.exports = __toCommonJS(FeatureScalePlugin_exports);
37
- var import_l7_core = require("@antv/l7-core");
38
- var import_d3_array = require("d3-array");
39
- var d3interpolate = __toESM(require("d3-interpolate"));
40
- var d3 = __toESM(require("d3-scale"));
41
- var import_inversify = require("inversify");
42
- var import_lodash = require("lodash");
43
- var import_reflect_metadata = require("reflect-metadata");
10
+ exports.default = void 0;
11
+
12
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
13
+
14
+ var _initializerDefineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerDefineProperty"));
15
+
16
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
17
+
18
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
19
+
20
+ var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime/helpers/applyDecoratedDescriptor"));
21
+
22
+ var _initializerWarningHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerWarningHelper"));
23
+
24
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
25
+
26
+ var _l7Core = require("@antv/l7-core");
27
+
28
+ var _d3Array = require("d3-array");
29
+
30
+ var d3interpolate = _interopRequireWildcard(require("d3-interpolate"));
31
+
32
+ var d3 = _interopRequireWildcard(require("d3-scale"));
33
+
34
+ var _inversify = require("inversify");
35
+
36
+ var _lodash = require("lodash");
37
+
38
+ require("reflect-metadata");
39
+
40
+ var _scaleMap, _dec, _dec2, _class, _class2, _descriptor;
41
+
42
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
43
+
44
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
45
+
44
46
  var dateRegex = /^(?:(?!0000)[0-9]{4}([-/.]+)(?:(?:0?[1-9]|1[0-2])\1(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])\1(?:29|30)|(?:0?[13578]|1[02])\1(?:31))|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)([-/.]?)0?2\2(?:29))(\s+([01]|([01][0-9]|2[0-3])):([0-9]|[0-5][0-9]):([0-9]|[0-5][0-9]))?$/;
45
- var scaleMap = {
46
- [import_l7_core.ScaleTypes.LINEAR]: d3.scaleLinear,
47
- [import_l7_core.ScaleTypes.POWER]: d3.scalePow,
48
- [import_l7_core.ScaleTypes.LOG]: d3.scaleLog,
49
- [import_l7_core.ScaleTypes.IDENTITY]: d3.scaleIdentity,
50
- [import_l7_core.ScaleTypes.SEQUENTIAL]: d3.scaleSequential,
51
- [import_l7_core.ScaleTypes.TIME]: d3.scaleTime,
52
- [import_l7_core.ScaleTypes.QUANTILE]: d3.scaleQuantile,
53
- [import_l7_core.ScaleTypes.QUANTIZE]: d3.scaleQuantize,
54
- [import_l7_core.ScaleTypes.THRESHOLD]: d3.scaleThreshold,
55
- [import_l7_core.ScaleTypes.CAT]: d3.scaleOrdinal,
56
- [import_l7_core.ScaleTypes.DIVERGING]: d3.scaleDiverging
57
- };
58
- var FeatureScalePlugin = class {
59
- constructor() {
60
- this.scaleCache = {};
61
- this.scaleOptions = {};
47
+ var scaleMap = (_scaleMap = {}, (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.LINEAR, d3.scaleLinear), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.POWER, d3.scalePow), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.LOG, d3.scaleLog), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.IDENTITY, d3.scaleIdentity), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.SEQUENTIAL, d3.scaleSequential), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.TIME, d3.scaleTime), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.QUANTILE, d3.scaleQuantile), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.QUANTIZE, d3.scaleQuantize), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.THRESHOLD, d3.scaleThreshold), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.CAT, d3.scaleOrdinal), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.DIVERGING, d3.scaleDiverging), _scaleMap);
48
+ /**
49
+ * 根据 Source 原始数据为指定字段创建 Scale,保存在 StyleAttribute 上,供下游插件使用
50
+ */
51
+
52
+ var FeatureScalePlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inversify.inject)(_l7Core.TYPES.IGlobalConfigService), _dec(_class = (_class2 = /*#__PURE__*/function () {
53
+ function FeatureScalePlugin() {
54
+ (0, _classCallCheck2.default)(this, FeatureScalePlugin);
55
+ (0, _initializerDefineProperty2.default)(this, "configService", _descriptor, this);
56
+ (0, _defineProperty2.default)(this, "scaleCache", {});
57
+ (0, _defineProperty2.default)(this, "scaleOptions", {});
62
58
  }
63
- apply(layer, {
64
- styleAttributeService
65
- }) {
66
- layer.hooks.init.tap("FeatureScalePlugin", () => {
67
- this.scaleOptions = layer.getScaleOptions();
68
- const attributes = styleAttributeService.getLayerStyleAttributes();
69
- const { dataArray } = layer.getSource().data;
70
- if (dataArray.length === 0) {
71
- return;
72
- }
73
- this.caculateScalesForAttributes(attributes || [], dataArray);
74
- });
75
- layer.hooks.beforeRenderData.tap("FeatureScalePlugin", () => {
76
- this.scaleOptions = layer.getScaleOptions();
77
- const attributes = styleAttributeService.getLayerStyleAttributes();
78
- const { dataArray } = layer.getSource().data;
79
- this.caculateScalesForAttributes(attributes || [], dataArray);
80
- layer.layerModelNeedUpdate = true;
81
- return true;
82
- });
83
- layer.hooks.beforeRender.tap("FeatureScalePlugin", () => {
84
- if (layer.layerModelNeedUpdate) {
85
- return;
86
- }
87
- this.scaleOptions = layer.getScaleOptions();
88
- const attributes = styleAttributeService.getLayerStyleAttributes();
89
- if (attributes) {
90
- const { dataArray } = layer.getSource().data;
59
+
60
+ (0, _createClass2.default)(FeatureScalePlugin, [{
61
+ key: "apply",
62
+ value: function apply(layer, _ref) {
63
+ var _this = this;
64
+
65
+ var styleAttributeService = _ref.styleAttributeService;
66
+ layer.hooks.init.tap('FeatureScalePlugin', function () {
67
+ _this.scaleOptions = layer.getScaleOptions();
68
+ var attributes = styleAttributeService.getLayerStyleAttributes();
69
+ var dataArray = layer.getSource().data.dataArray;
70
+
91
71
  if (dataArray.length === 0) {
92
72
  return;
93
73
  }
94
- const attributesToRescale = attributes.filter((attribute) => attribute.needRescale);
95
- if (attributesToRescale.length) {
96
- this.caculateScalesForAttributes(attributesToRescale, dataArray);
74
+
75
+ _this.caculateScalesForAttributes(attributes || [], dataArray);
76
+ }); // 检测数据是否需要更新
77
+
78
+ layer.hooks.beforeRenderData.tap('FeatureScalePlugin', function () {
79
+ _this.scaleOptions = layer.getScaleOptions();
80
+ var attributes = styleAttributeService.getLayerStyleAttributes();
81
+ var dataArray = layer.getSource().data.dataArray;
82
+
83
+ _this.caculateScalesForAttributes(attributes || [], dataArray);
84
+
85
+ layer.layerModelNeedUpdate = true;
86
+ return true;
87
+ });
88
+ layer.hooks.beforeRender.tap('FeatureScalePlugin', function () {
89
+ if (layer.layerModelNeedUpdate) {
90
+ return;
97
91
  }
98
- }
99
- });
100
- }
101
- isNumber(n) {
102
- return !isNaN(parseFloat(n)) && isFinite(n);
103
- }
104
- caculateScalesForAttributes(attributes, dataArray) {
105
- this.scaleCache = {};
106
- attributes.forEach((attribute) => {
107
- if (attribute.scale) {
108
- const attributeScale = attribute.scale;
109
- attributeScale.names = this.parseFields(attribute.scale.field || []);
110
- const scales = [];
111
- attributeScale.names.forEach((field) => {
112
- var _a;
113
- scales.push(this.createScale(field, attribute.name, (_a = attribute.scale) == null ? void 0 : _a.values, dataArray));
114
- });
115
- if (scales.some((scale) => scale.type === import_l7_core.StyleScaleType.VARIABLE)) {
116
- attributeScale.type = import_l7_core.StyleScaleType.VARIABLE;
117
- scales.forEach((scale) => {
118
- var _a, _b;
119
- if (!attributeScale.callback && attributeScale.values !== "text") {
120
- switch ((_a = scale.option) == null ? void 0 : _a.type) {
121
- case import_l7_core.ScaleTypes.LOG:
122
- case import_l7_core.ScaleTypes.LINEAR:
123
- case import_l7_core.ScaleTypes.POWER:
124
- if (attributeScale.values && attributeScale.values.length > 2) {
125
- const tick = scale.scale.ticks(attributeScale.values.length);
126
- scale.scale.domain(tick);
127
- }
128
- attributeScale.values ? scale.scale.range(attributeScale.values) : scale.scale.range(scale.option.domain);
129
- break;
130
- case import_l7_core.ScaleTypes.QUANTILE:
131
- case import_l7_core.ScaleTypes.QUANTIZE:
132
- case import_l7_core.ScaleTypes.THRESHOLD:
133
- scale.scale.range(attributeScale.values);
134
- break;
135
- case import_l7_core.ScaleTypes.CAT:
136
- attributeScale.values ? scale.scale.range(attributeScale.values) : scale.scale.range(scale.option.domain);
137
- break;
138
- case import_l7_core.ScaleTypes.DIVERGING:
139
- case import_l7_core.ScaleTypes.SEQUENTIAL:
140
- scale.scale.interpolator(d3interpolate.interpolateRgbBasis(attributeScale.values));
141
- break;
142
- }
143
- }
144
- if (attributeScale.values === "text") {
145
- scale.scale.range((_b = scale.option) == null ? void 0 : _b.domain);
146
- }
92
+
93
+ _this.scaleOptions = layer.getScaleOptions();
94
+ var attributes = styleAttributeService.getLayerStyleAttributes();
95
+
96
+ if (attributes) {
97
+ var dataArray = layer.getSource().data.dataArray;
98
+
99
+ if (dataArray.length === 0) {
100
+ return;
101
+ }
102
+
103
+ var attributesToRescale = attributes.filter(function (attribute) {
104
+ return attribute.needRescale;
147
105
  });
148
- } else {
149
- attributeScale.type = import_l7_core.StyleScaleType.CONSTANT;
150
- attributeScale.defaultValues = scales.map((scale, index) => {
151
- return scale.scale(attributeScale.names[index]);
106
+
107
+ if (attributesToRescale.length) {
108
+ _this.caculateScalesForAttributes(attributesToRescale, dataArray);
109
+ }
110
+ }
111
+ });
112
+ }
113
+ }, {
114
+ key: "isNumber",
115
+ value: function isNumber(n) {
116
+ return !isNaN(parseFloat(n)) && isFinite(n);
117
+ }
118
+ }, {
119
+ key: "caculateScalesForAttributes",
120
+ value: function caculateScalesForAttributes(attributes, dataArray) {
121
+ var _this2 = this;
122
+
123
+ this.scaleCache = {};
124
+ attributes.forEach(function (attribute) {
125
+ if (attribute.scale) {
126
+ // 创建Scale
127
+ var attributeScale = attribute.scale;
128
+ attributeScale.names = _this2.parseFields(attribute.scale.field || []);
129
+ var scales = []; // 为每个字段创建 Scale
130
+
131
+ attributeScale.names.forEach(function (field) {
132
+ var _attribute$scale;
133
+
134
+ scales.push(_this2.createScale(field, attribute.name, (_attribute$scale = attribute.scale) === null || _attribute$scale === void 0 ? void 0 : _attribute$scale.values, dataArray));
135
+ }); // 为scales 设置值区间 Range
136
+
137
+ if (scales.some(function (scale) {
138
+ return scale.type === _l7Core.StyleScaleType.VARIABLE;
139
+ })) {
140
+ attributeScale.type = _l7Core.StyleScaleType.VARIABLE;
141
+ scales.forEach(function (scale) {
142
+ var _scale$option;
143
+
144
+ // 如果设置了回调, 这不需要设置range
145
+ if (!attributeScale.callback && attributeScale.values !== 'text') {
146
+ switch ((_scale$option = scale.option) === null || _scale$option === void 0 ? void 0 : _scale$option.type) {
147
+ case _l7Core.ScaleTypes.LOG:
148
+ case _l7Core.ScaleTypes.LINEAR:
149
+ case _l7Core.ScaleTypes.POWER:
150
+ if (attributeScale.values && attributeScale.values.length > 2) {
151
+ var tick = scale.scale.ticks(attributeScale.values.length);
152
+ scale.scale.domain(tick);
153
+ }
154
+
155
+ attributeScale.values ? scale.scale.range(attributeScale.values) : scale.scale.range(scale.option.domain);
156
+ break;
157
+
158
+ case _l7Core.ScaleTypes.QUANTILE:
159
+ case _l7Core.ScaleTypes.QUANTIZE:
160
+ case _l7Core.ScaleTypes.THRESHOLD:
161
+ scale.scale.range(attributeScale.values); //
162
+
163
+ break;
164
+
165
+ case _l7Core.ScaleTypes.CAT:
166
+ attributeScale.values ? scale.scale.range(attributeScale.values) : scale.scale.range(scale.option.domain);
167
+ break;
168
+
169
+ case _l7Core.ScaleTypes.DIVERGING:
170
+ case _l7Core.ScaleTypes.SEQUENTIAL:
171
+ scale.scale.interpolator( // @ts-ignore
172
+ d3interpolate.interpolateRgbBasis(attributeScale.values));
173
+ break;
174
+ }
175
+ }
176
+
177
+ if (attributeScale.values === 'text') {
178
+ var _scale$option2;
179
+
180
+ scale.scale.range((_scale$option2 = scale.option) === null || _scale$option2 === void 0 ? void 0 : _scale$option2.domain);
181
+ }
182
+ });
183
+ } else {
184
+ // 设置attribute 常量值 常量直接在value取值
185
+ attributeScale.type = _l7Core.StyleScaleType.CONSTANT;
186
+ attributeScale.defaultValues = scales.map(function (scale, index) {
187
+ return scale.scale(attributeScale.names[index]);
188
+ });
189
+ }
190
+
191
+ attributeScale.scalers = scales.map(function (scale) {
192
+ return {
193
+ field: scale.field,
194
+ func: scale.scale,
195
+ option: scale.option
196
+ };
152
197
  });
198
+ attribute.needRescale = false;
153
199
  }
154
- attributeScale.scalers = scales.map((scale) => {
155
- return {
156
- field: scale.field,
157
- func: scale.scale,
158
- option: scale.option
159
- };
160
- });
161
- attribute.needRescale = false;
162
- }
163
- });
164
- }
165
- parseFields(field) {
166
- if (Array.isArray(field)) {
167
- return field;
200
+ });
168
201
  }
169
- if ((0, import_lodash.isString)(field)) {
170
- return field.split("*");
202
+ /**
203
+ * @example
204
+ * 'w*h' => ['w', 'h']
205
+ * 'w' => ['w']
206
+ */
207
+
208
+ }, {
209
+ key: "parseFields",
210
+ value: function parseFields(field) {
211
+ if (Array.isArray(field)) {
212
+ return field;
213
+ }
214
+
215
+ if ((0, _lodash.isString)(field)) {
216
+ return field.split('*');
217
+ }
218
+
219
+ return [field];
171
220
  }
172
- return [field];
173
- }
174
- createScale(field, name, values, data) {
175
- var _a, _b;
176
- const scaleOption = this.scaleOptions[name] && ((_a = this.scaleOptions[name]) == null ? void 0 : _a.field) === field ? this.scaleOptions[name] : this.scaleOptions[field];
177
- const styleScale = {
178
- field,
179
- scale: void 0,
180
- type: import_l7_core.StyleScaleType.VARIABLE,
181
- option: scaleOption
182
- };
183
- if (!data || !data.length) {
184
- if (scaleOption && scaleOption.type) {
185
- styleScale.scale = this.createDefaultScale(scaleOption);
186
- } else {
221
+ }, {
222
+ key: "createScale",
223
+ value: function createScale(field, name, values, data) {
224
+ var _this$scaleOptions$na, _find;
225
+
226
+ // scale 支持根据视觉通道和字段
227
+ var scaleOption = this.scaleOptions[name] && ((_this$scaleOptions$na = this.scaleOptions[name]) === null || _this$scaleOptions$na === void 0 ? void 0 : _this$scaleOptions$na.field) === field ? this.scaleOptions[name] // TODO zi
228
+ : this.scaleOptions[field];
229
+ var styleScale = {
230
+ field: field,
231
+ scale: undefined,
232
+ type: _l7Core.StyleScaleType.VARIABLE,
233
+ option: scaleOption
234
+ };
235
+
236
+ if (!data || !data.length) {
237
+ if (scaleOption && scaleOption.type) {
238
+ styleScale.scale = this.createDefaultScale(scaleOption);
239
+ } else {
240
+ styleScale.scale = d3.scaleOrdinal([field]);
241
+ styleScale.type = _l7Core.StyleScaleType.CONSTANT;
242
+ }
243
+
244
+ return styleScale;
245
+ }
246
+
247
+ var firstValue = (_find = data.find(function (d) {
248
+ return !(0, _lodash.isNil)(d[field]);
249
+ })) === null || _find === void 0 ? void 0 : _find[field]; // 常量 Scale
250
+
251
+ if (this.isNumber(field) || (0, _lodash.isNil)(firstValue) && !scaleOption) {
187
252
  styleScale.scale = d3.scaleOrdinal([field]);
188
- styleScale.type = import_l7_core.StyleScaleType.CONSTANT;
253
+ styleScale.type = _l7Core.StyleScaleType.CONSTANT;
254
+ } else {
255
+ // 根据数据类型判断 默认等分位,时间,和枚举类型
256
+ var type = scaleOption && scaleOption.type || this.getDefaultType(firstValue);
257
+
258
+ if (values === 'text') {
259
+ // text 为内置变 如果是文本则为cat
260
+ type = _l7Core.ScaleTypes.CAT;
261
+ }
262
+
263
+ var cfg = this.createScaleConfig(type, field, scaleOption, data);
264
+ styleScale.scale = this.createDefaultScale(cfg);
265
+ styleScale.option = cfg;
189
266
  }
267
+
190
268
  return styleScale;
191
269
  }
192
- const firstValue = (_b = data.find((d) => !(0, import_lodash.isNil)(d[field]))) == null ? void 0 : _b[field];
193
- if (this.isNumber(field) || (0, import_lodash.isNil)(firstValue) && !scaleOption) {
194
- styleScale.scale = d3.scaleOrdinal([field]);
195
- styleScale.type = import_l7_core.StyleScaleType.CONSTANT;
196
- } else {
197
- let type = scaleOption && scaleOption.type || this.getDefaultType(firstValue);
198
- if (values === "text") {
199
- type = import_l7_core.ScaleTypes.CAT;
270
+ }, {
271
+ key: "getDefaultType",
272
+ value: function getDefaultType(firstValue) {
273
+ var type = _l7Core.ScaleTypes.LINEAR;
274
+
275
+ if (typeof firstValue === 'string') {
276
+ type = dateRegex.test(firstValue) ? _l7Core.ScaleTypes.TIME : _l7Core.ScaleTypes.CAT;
200
277
  }
201
- const cfg = this.createScaleConfig(type, field, scaleOption, data);
202
- styleScale.scale = this.createDefaultScale(cfg);
203
- styleScale.option = cfg;
204
- }
205
- return styleScale;
206
- }
207
- getDefaultType(firstValue) {
208
- let type = import_l7_core.ScaleTypes.LINEAR;
209
- if (typeof firstValue === "string") {
210
- type = dateRegex.test(firstValue) ? import_l7_core.ScaleTypes.TIME : import_l7_core.ScaleTypes.CAT;
211
- }
212
- return type;
213
- }
214
- createScaleConfig(type, field, scaleOption, data) {
215
- const cfg = {
216
- type
217
- };
218
- const values = (data == null ? void 0 : data.map((item) => item[field])) || [];
219
- if (scaleOption == null ? void 0 : scaleOption.domain) {
220
- cfg.domain = scaleOption == null ? void 0 : scaleOption.domain;
221
- } else if (type !== import_l7_core.ScaleTypes.CAT && type !== import_l7_core.ScaleTypes.QUANTILE && type !== import_l7_core.ScaleTypes.DIVERGING) {
222
- cfg.domain = (0, import_d3_array.extent)(values);
223
- } else if (type === import_l7_core.ScaleTypes.CAT) {
224
- cfg.domain = (0, import_lodash.uniq)(values);
225
- } else if (type === import_l7_core.ScaleTypes.QUANTILE) {
226
- cfg.domain = values;
227
- } else if (type === import_l7_core.ScaleTypes.DIVERGING) {
228
- const minMax = (0, import_d3_array.extent)(values);
229
- const neutral = (scaleOption == null ? void 0 : scaleOption.neutral) !== void 0 ? scaleOption == null ? void 0 : scaleOption.neutral : (minMax[0] + minMax[1]) / 2;
230
- cfg.domain = [minMax[0], neutral, minMax[1]];
231
- }
232
- return { ...cfg, ...scaleOption };
233
- }
234
- createDefaultScale({ type, domain, unknown, clamp, nice }) {
235
- const scale = scaleMap[type]();
236
- if (domain && scale.domain) {
237
- scale.domain(domain);
238
- }
239
- if (unknown) {
240
- scale.unknown(unknown);
241
- }
242
- if (clamp !== void 0 && scale.clamp) {
243
- scale.clamp(clamp);
244
- }
245
- if (nice !== void 0 && scale.nice) {
246
- scale.nice(nice);
278
+
279
+ return type;
280
+ } // 生成Scale 默认配置
281
+
282
+ }, {
283
+ key: "createScaleConfig",
284
+ value: function createScaleConfig(type, field, scaleOption, data) {
285
+ var cfg = {
286
+ type: type
287
+ };
288
+ var values = (data === null || data === void 0 ? void 0 : data.map(function (item) {
289
+ return item[field];
290
+ })) || [];
291
+
292
+ if (scaleOption !== null && scaleOption !== void 0 && scaleOption.domain) {
293
+ cfg.domain = scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.domain;
294
+ } else if (type !== _l7Core.ScaleTypes.CAT && type !== _l7Core.ScaleTypes.QUANTILE && type !== _l7Core.ScaleTypes.DIVERGING) {
295
+ // linear/
296
+ cfg.domain = (0, _d3Array.extent)(values);
297
+ } else if (type === _l7Core.ScaleTypes.CAT) {
298
+ cfg.domain = (0, _lodash.uniq)(values);
299
+ } else if (type === _l7Core.ScaleTypes.QUANTILE) {
300
+ cfg.domain = values;
301
+ } else if (type === _l7Core.ScaleTypes.DIVERGING) {
302
+ var minMax = (0, _d3Array.extent)(values);
303
+ var neutral = (scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.neutral) !== undefined ? scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.neutral : (minMax[0] + minMax[1]) / 2;
304
+ cfg.domain = [minMax[0], neutral, minMax[1]];
305
+ }
306
+
307
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, cfg), scaleOption);
308
+ } // 创建Scale 实例
309
+
310
+ }, {
311
+ key: "createDefaultScale",
312
+ value: function createDefaultScale(_ref2) {
313
+ var type = _ref2.type,
314
+ domain = _ref2.domain,
315
+ unknown = _ref2.unknown,
316
+ clamp = _ref2.clamp,
317
+ nice = _ref2.nice;
318
+ // @ts-ignore
319
+ var scale = scaleMap[type]();
320
+
321
+ if (domain && scale.domain) {
322
+ scale.domain(domain);
323
+ }
324
+
325
+ if (unknown) {
326
+ scale.unknown(unknown);
327
+ }
328
+
329
+ if (clamp !== undefined && scale.clamp) {
330
+ scale.clamp(clamp);
331
+ }
332
+
333
+ if (nice !== undefined && scale.nice) {
334
+ scale.nice(nice);
335
+ } // TODO 其他属性支持
336
+
337
+
338
+ return scale;
247
339
  }
248
- return scale;
249
- }
250
- };
251
- __decorateClass([
252
- (0, import_inversify.inject)(import_l7_core.TYPES.IGlobalConfigService)
253
- ], FeatureScalePlugin.prototype, "configService", 2);
254
- FeatureScalePlugin = __decorateClass([
255
- (0, import_inversify.injectable)()
256
- ], FeatureScalePlugin);
257
- // Annotate the CommonJS export names for ESM import in node:
258
- 0 && (module.exports = {});
340
+ }]);
341
+ return FeatureScalePlugin;
342
+ }(), (_descriptor = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "configService", [_dec2], {
343
+ configurable: true,
344
+ enumerable: true,
345
+ writable: true,
346
+ initializer: null
347
+ })), _class2)) || _class);
348
+ exports.default = FeatureScalePlugin;