sea-chart 0.0.47-alpha.0 → 0.0.47-alpha.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.
@@ -1,8 +1,8 @@
1
1
  var _SQLStatisticsUtils;
2
2
  import dayjs from 'dayjs';
3
- import { CellType, MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP, getFormulaDisplayString, getPrecisionNumber, getTableById, getTableColumnByKey, isNumber } from 'dtable-utils';
3
+ import { CellType, MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP, getFormulaDisplayString, getPrecisionNumber, getTableById, getTableColumnByKey, isNumber, DateUtils } from 'dtable-utils';
4
4
  import { isObject } from 'lodash';
5
- import { CHART_SUMMARY_TYPE, CHART_TYPE, SUPPORT_DATA_SORT_CHART_TYPES, LABEL_COLORS, TABLE_DIMENSIONS, Y_AXIS_TYPE_PREFIX, STYLE_COLORS } from '../../constants';
5
+ import { CHART_SUMMARY_TYPE, CHART_TYPE, SUPPORT_DATA_SORT_CHART_TYPES, TABLE_DIMENSIONS, Y_AXIS_TYPE_PREFIX, STYLE_COLORS } from '../../constants';
6
6
  import { chartColumn2SqlColumn, summaryMethodColumn2SqlColumn } from '../sql';
7
7
  import { getClientLinkDisplayString } from '../cell-format-utils';
8
8
  import context from '../../context';
@@ -14,7 +14,7 @@ import BaseUtils from './base-utils';
14
14
  class SQLStatisticsUtils {}
15
15
  _SQLStatisticsUtils = SQLStatisticsUtils;
16
16
  SQLStatisticsUtils.dataSources = 'sql_statistics';
17
- SQLStatisticsUtils.getGroupLabelFromDB = (cellValue, column, tables) => {
17
+ SQLStatisticsUtils.getGroupLabelFromDB = (cellValue, column, tables, dateGranularity) => {
18
18
  const collaborators = context.getCollaboratorsFromCache();
19
19
  const {
20
20
  type,
@@ -22,11 +22,21 @@ SQLStatisticsUtils.getGroupLabelFromDB = (cellValue, column, tables) => {
22
22
  } = column;
23
23
  switch (type) {
24
24
  case CellType.TEXT:
25
+ {
26
+ return cellValue || null;
27
+ }
25
28
  case CellType.DATE:
26
29
  case CellType.CTIME:
27
30
  case CellType.MTIME:
28
31
  {
29
- return cellValue || null;
32
+ if (!dateGranularity) {
33
+ return cellValue || null;
34
+ }
35
+ if (dateGranularity.toUpperCase() === 'QUARTER') {
36
+ // TODO: fix the unknown word 'QUARTAR'
37
+ return DateUtils.getDateByGranularity(cellValue, 'QUARTAR');
38
+ }
39
+ return DateUtils.getDateByGranularity(cellValue, dateGranularity);
30
40
  }
31
41
  case CellType.NUMBER:
32
42
  {
@@ -830,7 +840,8 @@ SQLStatisticsUtils.compareSQLResult2Javascript = (chart, sqlRows, chartSQLMap, c
830
840
  x_axis_compared_date_range_end,
831
841
  y_axis_summary_type,
832
842
  y_axis_summary_method,
833
- display_increase
843
+ display_increase,
844
+ x_axis_date_granularity
834
845
  } = config;
835
846
  const groupName1 = "".concat(x_axis_date_range_start, " - ").concat(x_axis_date_range_end);
836
847
  const groupName2 = "".concat(x_axis_compared_date_range_start, " - ").concat(x_axis_compared_date_range_end);
@@ -839,7 +850,7 @@ SQLStatisticsUtils.compareSQLResult2Javascript = (chart, sqlRows, chartSQLMap, c
839
850
  const isAdvanced = y_axis_summary_type === CHART_SUMMARY_TYPE.ADVANCED;
840
851
  sqlRows.forEach(item => {
841
852
  const name = item[sqlGroupbyColumnKey];
842
- const label = _SQLStatisticsUtils.getGroupLabelFromDB(name, groupbyColumn, tables);
853
+ const label = _SQLStatisticsUtils.getGroupLabelFromDB(name, groupbyColumn, tables, x_axis_date_granularity);
843
854
  const value = item[sqlSummaryColumnKey];
844
855
  if (name >= x_axis_date_range_start && name <= x_axis_date_range_end) {
845
856
  const currentValue = dateRangeResult.get(label);
@@ -1,4 +1,5 @@
1
1
  import { CellType, filter2SqlCondition, isNumericColumn, isDateColumn } from 'dtable-utils';
2
+ import dayjs from 'dayjs';
2
3
  import { getSqlGroup } from '../column-utils';
3
4
  import { CHART_TYPE, DTABLE_DB_SUMMARY_METHOD, CHART_SUMMARY_TYPE, CHART_Y_GROUP_TYPE } from '../../constants';
4
5
  import { fixGeoGranularity } from '../map';
@@ -311,11 +312,14 @@ class ChartDataSQL {
311
312
  this._compare_chart_statistic_2_sql = () => {
312
313
  const {
313
314
  x_axis_column_key,
314
- x_axis_date_granularity,
315
315
  x_axis_geolocation_granularity,
316
316
  y_axis_summary_type,
317
317
  y_axis_summary_column_key,
318
- y_axis_summary_method
318
+ y_axis_summary_method,
319
+ x_axis_date_range_start,
320
+ x_axis_date_range_end,
321
+ x_axis_compared_date_range_start,
322
+ x_axis_compared_date_range_end
319
323
  } = this.chart;
320
324
  const groupby_column = this._get_column_by_key(x_axis_column_key);
321
325
  if (!groupby_column) {
@@ -324,7 +328,7 @@ class ChartDataSQL {
324
328
  }
325
329
  this._update_filter_sql(true, groupby_column);
326
330
  const groupby_column_name = this._chart_column_name_to_sql(groupby_column, {
327
- 'date_granularity': x_axis_date_granularity,
331
+ 'date_granularity': 'day',
328
332
  'geolocation_granularity': x_axis_geolocation_granularity
329
333
  });
330
334
  let summary_column_name = this._summary_column_2_sql('COUNT', groupby_column);
@@ -336,7 +340,16 @@ class ChartDataSQL {
336
340
  }
337
341
  summary_column_name = this._summary_column_2_sql(y_axis_summary_method.toUpperCase(), summary_column);
338
342
  }
339
- return "SELECT ".concat(groupby_column_name, ", ").concat(summary_column_name, " FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY ").concat(groupby_column_name, " LIMIT 0, 5000");
343
+
344
+ // filter
345
+ let filter_sql = this.filter_sql;
346
+ if (x_axis_date_range_start && x_axis_date_range_end && x_axis_compared_date_range_start && x_axis_compared_date_range_end) {
347
+ filter_sql = this.filter_sql.length === 0 ? 'where ' : this.filter_sql + ' AND';
348
+ const formattedXAxisDateRangeEnd = dayjs(x_axis_date_range_end).add(1, 'days').format('YYYY-MM-DD');
349
+ const formattedXAxisComparedDateRangeEnd = dayjs(x_axis_compared_date_range_end).add(1, 'days').format('YYYY-MM-DD');
350
+ filter_sql = filter_sql + " ((".concat(groupby_column.name, " >= '").concat(x_axis_date_range_start, "' AND ").concat(groupby_column.name, " < '").concat(formattedXAxisDateRangeEnd, "') Or (").concat(groupby_column.name, " >= '").concat(x_axis_compared_date_range_start, "' AND ").concat(groupby_column.name, " < '").concat(formattedXAxisComparedDateRangeEnd, "'))");
351
+ }
352
+ return "SELECT ".concat(groupby_column_name, ", ").concat(summary_column_name, " FROM ").concat(this.table_name, " ").concat(filter_sql, " GROUP BY ").concat(groupby_column_name, " LIMIT 0, 5000");
340
353
  };
341
354
  this._combination_chart_statistic_2_sql = () => {
342
355
  const x_axis_column_key = this.chart['x_axis_column_key'] || '';
@@ -281,16 +281,22 @@ const pieChartStatisticColumn2sqlColumn = (chart, table) => {
281
281
  };
282
282
  };
283
283
  const basicChartStatisticColumn2sqlColumn = (chart, table) => {
284
+ let {
285
+ x_axis_date_granularity
286
+ } = chart;
284
287
  const {
288
+ type,
285
289
  x_axis_column_key,
286
290
  y_axis_summary_type,
287
291
  y_axis_summary_method,
288
292
  y_axis_summary_column_key,
289
- x_axis_date_granularity,
290
293
  x_axis_geolocation_granularity
291
294
  } = chart;
292
295
  const groupbyColumn = getTableColumnByKey(table, x_axis_column_key);
293
296
  if (!groupbyColumn) return {};
297
+ if (type === CHART_TYPE.COMPARE_BAR) {
298
+ x_axis_date_granularity = 'DAY';
299
+ }
294
300
  const {
295
301
  key: sqlGroupbyColumnKey
296
302
  } = column2SqlColumn(groupbyColumn, {
@@ -548,7 +548,7 @@ export default class ChartComponent extends Component {
548
548
  showMarkers: true,
549
549
  marker: {
550
550
  strokeOpacity: 0,
551
- r: 6
551
+ r: 5
552
552
  },
553
553
  crosshairs: {
554
554
  line: {
@@ -262,7 +262,7 @@ class Combination extends ChartComponent {
262
262
  duration: 1000,
263
263
  easing: 'easeLinear'
264
264
  }
265
- }).shape('circle').size(4).style({
265
+ }).shape('circle').size(3).style({
266
266
  stroke: 0,
267
267
  fillOpacity: 1
268
268
  }).label(display_data ? 'value_right' : false, {
@@ -371,9 +371,9 @@ class Combination extends ChartComponent {
371
371
  // fillOpacity: 0.3,
372
372
  // });
373
373
  point.style('name', name => {
374
- let r = 4;
374
+ let r = 3;
375
375
  if (name === e.data.data.name) {
376
- r = 8;
376
+ r = 5;
377
377
  }
378
378
  return {
379
379
  r,
@@ -391,7 +391,7 @@ class Combination extends ChartComponent {
391
391
  // fillOpacity: 1,
392
392
  // });
393
393
  point.style('name', name => {
394
- let r = 4;
394
+ let r = 3;
395
395
  return {
396
396
  r,
397
397
  stroke: 0,
@@ -106,7 +106,7 @@ class LineGroup extends ChartComponent {
106
106
  duration: 1000,
107
107
  easing: 'easeLinear'
108
108
  }
109
- }).shape('circle').size(4).style({
109
+ }).shape('circle').size(3).style({
110
110
  stroke: 0,
111
111
  fillOpacity: 1
112
112
  });
@@ -100,7 +100,7 @@ class Line extends ChartComponent {
100
100
  duration: 1000,
101
101
  easing: 'easeLinear'
102
102
  }
103
- }).shape('circle').size(4).style({
103
+ }).shape('circle').size(3).style({
104
104
  stroke: 0,
105
105
  fillOpacity: 1
106
106
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sea-chart",
3
- "version": "0.0.47-alpha.0",
3
+ "version": "0.0.47-alpha.2",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",