dtable-statistic 4.1.4 → 4.1.6

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.
@@ -161,6 +161,10 @@
161
161
  height: 100%;
162
162
  }
163
163
 
164
+ .statistic-chart-container.map {
165
+ padding: 20px;
166
+ }
167
+
164
168
  .statistic-chart-loading-container {
165
169
  position: absolute;
166
170
  width: 100%;
@@ -314,10 +314,6 @@ function calculateGeolocationBasicChart(chart, value, username, userId) {
314
314
  summary_type = chart.summary_type,
315
315
  summary_column = chart.summary_column,
316
316
  summary_method = chart.summary_method;
317
- var geolocationGranularity = null;
318
- if (type && !type.includes('world')) {
319
- geolocationGranularity = fixMapGeoGranularity(chart);
320
- }
321
317
  var table = TableUtils.getTableById(value.tables, table_id);
322
318
  var view = table && Views.getViewById(table.views, view_id);
323
319
  if (!view) {
@@ -327,6 +323,12 @@ function calculateGeolocationBasicChart(chart, value, username, userId) {
327
323
  if (!geoColumn) {
328
324
  return;
329
325
  }
326
+ var geolocationGranularity = null;
327
+ if (type && type.includes('world')) {
328
+ geolocationGranularity = geoColumn.type === CellType.GEOLOCATION ? chart.geolocation_granularity : null;
329
+ } else {
330
+ geolocationGranularity = fixMapGeoGranularity(chart);
331
+ }
330
332
  var summaryColumn = TableUtils.getTableColumnByKey(table, summary_column);
331
333
  var statRows = Views.getViewRows(view, table, value, username, userId);
332
334
  var formulaRows = Views.getTableFormulaResults(table, statRows, value);
package/es/custom-g2.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // register theme
2
2
  import * as CanvasEngine from '@antv/g-canvas/esm/index';
3
+ // import * as SvgEngine from '@antv/g-svg/esm/index';
3
4
  import Area from '@antv/g2/esm/geometry/area';
4
5
  import Edge from '@antv/g2/esm/geometry/edge';
5
6
  import HeatMap from '@antv/g2/esm/geometry/heatmap';
@@ -96,6 +97,7 @@ export { getRectWithCornerRadius } from '@antv/g2/esm/geometry/shape/interval/ut
96
97
 
97
98
  // register G renderer
98
99
  registerEngine('canvas', CanvasEngine);
100
+ // registerEngine('svg', SvgEngine);
99
101
 
100
102
  // register internal G2 geometry
101
103
  registerGeometry('Polygon', Polygon);
@@ -34,10 +34,6 @@ var Map = /*#__PURE__*/function (_BaseChart) {
34
34
  isCalculatingData: false
35
35
  });
36
36
  _this.updateStatisticData(_this.fixData(statData));
37
- if (_this.props.isPreview) {
38
- var canvasSize = _this.getCanvasSize();
39
- _this.chart.changeSize(canvasSize.w, canvasSize.h);
40
- }
41
37
  });
42
38
  };
43
39
  _this.rerenderChart = function () {
@@ -246,22 +242,24 @@ var Map = /*#__PURE__*/function (_BaseChart) {
246
242
  _this.statisticView.interaction('element-active');
247
243
  _this.statisticView.render();
248
244
  };
249
- _this.getCanvasSize = function () {
245
+ _this.getSize = function () {
250
246
  var statItem = _this.props.statItem;
251
247
  var map_level = statItem.map_level,
252
248
  map_location = statItem.map_location;
253
- var maxWidth = _this.container.clientWidth;
254
- var maxHeight = _this.container.clientHeight;
249
+ var containerWidth = _this.container.clientWidth - 40; // 40: padding
250
+ var containerHeight = _this.container.clientHeight - 40;
255
251
  var _getRegionScaleOffset = getRegionScaleOffsets(map_level, map_location),
256
252
  scale_w = _getRegionScaleOffset.scale_w,
257
253
  scale_h = _getRegionScaleOffset.scale_h;
258
- var h = maxHeight;
254
+ var h = containerHeight;
259
255
  var w = h * (scale_w / scale_h);
260
- if (w > maxWidth) {
261
- w = maxWidth;
256
+ if (w > containerWidth) {
257
+ w = containerWidth;
262
258
  h = w * (scale_h / scale_w);
263
259
  }
264
260
  return {
261
+ containerWidth: containerWidth,
262
+ containerHeight: containerHeight,
265
263
  w: w,
266
264
  h: h
267
265
  };
@@ -269,13 +267,19 @@ var Map = /*#__PURE__*/function (_BaseChart) {
269
267
  _this.initStatisticContext = function (geolocation) {
270
268
  _this.mapData = geolocation;
271
269
  if (!_this.container) return;
270
+
272
271
  // create chart
273
- var canvasSize = _this.getCanvasSize();
272
+ var _this$getSize = _this.getSize(),
273
+ containerWidth = _this$getSize.containerWidth,
274
+ containerHeight = _this$getSize.containerHeight,
275
+ mapWidth = _this$getSize.w;
276
+ var horizontalPadding = (containerWidth - mapWidth) / 4;
277
+ var leftPadding = horizontalPadding < 20 ? 20 : horizontalPadding;
274
278
  _this.chart = new Chart({
275
279
  container: _this.container,
276
- width: canvasSize.w,
277
- height: canvasSize.h,
278
- padding: [20, 20]
280
+ width: containerWidth,
281
+ height: containerHeight,
282
+ padding: [0, horizontalPadding, 0, leftPadding]
279
283
  });
280
284
  _this.chart.on('element:click', function (e) {
281
285
  var statItem = _this.props.statItem;
@@ -401,10 +405,6 @@ var Map = /*#__PURE__*/function (_BaseChart) {
401
405
  }
402
406
  } else {
403
407
  this.updateStatisticData(this.fixData(this.calculateData));
404
- if (this.props.isPreview) {
405
- var canvasSize = this.getCanvasSize();
406
- this.chart.changeSize(canvasSize.w, canvasSize.h);
407
- }
408
408
  }
409
409
  }
410
410
  }, {
@@ -424,7 +424,7 @@ var Map = /*#__PURE__*/function (_BaseChart) {
424
424
  ref: function ref(_ref) {
425
425
  return _this4.container = _ref;
426
426
  },
427
- className: "statistic-chart-container d-flex justify-content-around align-items-center w-100 h-100"
427
+ className: "statistic-chart-container map d-flex justify-content-around align-items-center w-100 h-100"
428
428
  }));
429
429
  }
430
430
  }]);
@@ -20,6 +20,11 @@ var WorldMap = /*#__PURE__*/function (_BaseChart) {
20
20
  var _this;
21
21
  _classCallCheck(this, WorldMap);
22
22
  _this = _super.call(this, props);
23
+ _this.rerenderChart = function () {
24
+ if (!_this.chart) return;
25
+ _this.chart.destroy();
26
+ _this.initStatisticContext(_this.geoData);
27
+ };
23
28
  _this.fixData = function (statisticData) {
24
29
  if (!statisticData) return [];
25
30
  var statisticNewData = [];
@@ -225,16 +230,18 @@ var WorldMap = /*#__PURE__*/function (_BaseChart) {
225
230
  }
226
231
  _this.chart.render();
227
232
  };
228
- _this.getCanvasSize = function () {
229
- var maxWidth = _this.container.clientWidth;
230
- var maxHeight = _this.container.clientHeight;
231
- var h = maxHeight;
233
+ _this.getSize = function () {
234
+ var containerWidth = _this.container.clientWidth - 40; // 40: padding
235
+ var containerHeight = _this.container.clientHeight - 40;
236
+ var h = containerHeight;
232
237
  var w = h * (WIDTH / HEIGHT);
233
- if (w > maxWidth) {
234
- w = maxWidth;
238
+ if (w > containerWidth) {
239
+ w = containerWidth;
235
240
  h = w * (HEIGHT / WIDTH);
236
241
  }
237
242
  return {
243
+ containerWidth: containerWidth,
244
+ containerHeight: containerHeight,
238
245
  w: w,
239
246
  h: h
240
247
  };
@@ -246,13 +253,19 @@ var WorldMap = /*#__PURE__*/function (_BaseChart) {
246
253
  _this.countryMap.set(item.properties.name_cn, item.properties.name);
247
254
  });
248
255
  if (!_this.container) return;
256
+
249
257
  // create chart
250
- var canvasSize = _this.getCanvasSize();
258
+ var _this$getSize = _this.getSize(),
259
+ containerWidth = _this$getSize.containerWidth,
260
+ containerHeight = _this$getSize.containerHeight,
261
+ mapWidth = _this$getSize.w;
262
+ var horizontalPadding = (containerWidth - mapWidth) / 4;
263
+ var leftPadding = horizontalPadding < 20 ? 20 : horizontalPadding;
251
264
  _this.chart = new Chart({
252
265
  container: _this.container,
253
- width: canvasSize.w,
254
- height: canvasSize.h,
255
- padding: [20, 20]
266
+ width: containerWidth,
267
+ height: containerHeight,
268
+ padding: [0, horizontalPadding, 0, leftPadding]
256
269
  });
257
270
  _this.chart.on('element:click', function (e) {
258
271
  var statItem = _this.props.statItem;
@@ -371,28 +384,20 @@ var WorldMap = /*#__PURE__*/function (_BaseChart) {
371
384
  isCalculatingData: true
372
385
  });
373
386
  if (this.container) {
374
- if (this.chart) {
375
- this.chart.destroy();
376
- this.initStatisticContext(this.geoData);
377
- }
387
+ this.rerenderChart();
378
388
  chartCalculator.calculate(statItem).then(function (calculation) {
379
389
  _this3.setState({
380
390
  isCalculatingData: false
381
391
  });
382
392
  _this3.calculateData = calculation;
383
393
  _this3.updateStatisticData(_this3.fixData(calculation));
384
- if (_this3.props.isPreview) {
385
- var canvasSize = _this3.getCanvasSize();
386
- _this3.chart.changeSize(canvasSize.w, canvasSize.h);
387
- }
388
394
  });
389
395
  }
390
396
  } else {
391
- this.updateStatisticData(this.fixData(this.calculateData));
392
397
  if (this.props.isPreview) {
393
- var canvasSize = this.getCanvasSize();
394
- this.chart.changeSize(canvasSize.w, canvasSize.h);
398
+ this.rerenderChart();
395
399
  }
400
+ this.updateStatisticData(this.fixData(this.calculateData));
396
401
  }
397
402
  }
398
403
  }, {
@@ -412,7 +417,7 @@ var WorldMap = /*#__PURE__*/function (_BaseChart) {
412
417
  ref: function ref(_ref) {
413
418
  return _this4.container = _ref;
414
419
  },
415
- className: "statistic-chart-container d-flex justify-content-around align-items-center w-100 h-100"
420
+ className: "statistic-chart-container map d-flex justify-content-around align-items-center w-100 h-100"
416
421
  }));
417
422
  }
418
423
  }]);
@@ -220,8 +220,9 @@ var getPieColor = function getPieColor(color_option, column, index, data, curren
220
220
  return selectedItem.color || '#dbdbdb';
221
221
  }
222
222
  } else {
223
- var newIndex = String(index).at(-1);
224
- return colors[newIndex];
223
+ var sIndex = String(index);
224
+ var colorIndex = sIndex.charAt(sIndex.length - 1);
225
+ return colors[colorIndex];
225
226
  }
226
227
  };
227
228
  export function formatPieChartData(data, statItem, table, currentTheme) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtable-statistic",
3
- "version": "4.1.4",
3
+ "version": "4.1.6",
4
4
  "description": "statistics",
5
5
  "main": "dist/dtable-statistic.js",
6
6
  "author": "seafile",