dtable-statistic 4.1.1 → 4.1.3

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.
@@ -581,3 +581,61 @@
581
581
  .statistic-chart-container .collaborators-formatter .collaborator {
582
582
  margin-right: 0 !important;
583
583
  }
584
+
585
+ .btn-move-to-statistic-view {
586
+ display: flex;
587
+ align-items: center;
588
+ }
589
+
590
+ .statistic-views-dropdown {
591
+ width: 100%;
592
+ }
593
+
594
+ .statistic-views-dropdown-toggle {
595
+ display: flex;
596
+ align-items: center;
597
+ }
598
+
599
+ .statistic-views-dropdown .item-text {
600
+ flex: 1;
601
+ }
602
+
603
+ .statistic-views-dropdown .icon-dropdown-toggle {
604
+ display: inline-flex;
605
+ align-items: center;
606
+ width: 12px;
607
+ height: 12px;
608
+ margin-right: 12px;
609
+ }
610
+
611
+ .move-to-statistic-views-toggle {
612
+ opacity: 0;
613
+ width: 0;
614
+ min-width: 0;
615
+ margin-left: -12px;
616
+ padding: 0;
617
+ }
618
+
619
+ .dropdown-item .statistic-views-dropdown .item-icon.dtable-icon-right-slide {
620
+ display: inline-flex;
621
+ font-size: 12px;
622
+ -webkit-transform: scale(.8);
623
+ transform: scale(.8);
624
+ }
625
+
626
+ .statistic-views-dropdown-menu {
627
+ margin-top: -16px !important;
628
+ margin-left: -12px !important;
629
+ }
630
+
631
+ .statistic-views-dropdown-menu .dropdown-item {
632
+ display: flex;
633
+ align-items: center;
634
+ min-height: 32px;
635
+ padding: 3px 12px;
636
+ }
637
+
638
+ .statistic-views-dropdown-menu .statistic-view-name {
639
+ display: inline-block;
640
+ width: 100%;
641
+ }
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!-- Generator: Adobe Illustrator 21.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3
+ <svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
4
+ viewBox="0 0 32 32" style="enable-background:new 0 0 32 32;" xml:space="preserve">
5
+ <style type="text/css">
6
+ .st0{fill:#949494;}
7
+ </style>
8
+ <title>move-to</title>
9
+ <g id="move-to-">
10
+ <g id="export" transform="translate(2.000000, 3.000000)">
11
+ <path id="形状结合" fill="currentColor" class="st0" d="M10.7,0c0.4,0,0.8,0.1,1.4,0.4c0.7,0.3,1.1,0.7,1.5,1s0.6,0.7,0.8,1
12
+ c0.2,0.3,0.3,0.5,0.6,0.6c0.2,0.1,0.5,0.2,0.9,0.2h8.5c1,0,1.9,0.3,2.5,0.9C27.5,4.8,28,5.5,28,6.4v16.3c0,1-0.4,1.7-1.1,2.3
13
+ S25.4,26,24.4,26H3.5c-1.1,0-1.8-0.2-2.5-1c-0.7-0.8-1-1.4-1-2.3l0-10.3c0-0.1,0-0.2,0-0.4l0-8.8l0,0c0-1,0.5-1.6,1.1-2.2
14
+ C1.8,0.3,2.4,0,3.1,0H10.7z M17.4,9.6c-0.8-0.8-1.6-0.8-2.4,0l0,0l-0.1,0.1c-0.7,0.8-0.6,1.5,0.1,2.3l0,0l1.1,1.1l-8.4,0
15
+ c-1.1,0-1.7,0.6-1.7,1.7l0,0L6,15c0.1,1,0.6,1.5,1.7,1.5l0,0l8.3,0l-1.1,1.1c-0.8,0.8-0.8,1.6,0,2.4l0,0l0.1,0.1
16
+ c0.8,0.7,1.5,0.6,2.3-0.1l0,0l3.6-3.6c0.1-0.1,0.3-0.2,0.4-0.3l0,0l0.1-0.1c0.6-0.7,0.6-1.4,0.1-2c-0.1-0.1-0.2-0.2-0.3-0.3l0,0
17
+ l-0.1-0.1l0,0l0,0L17.4,9.6z"/>
18
+ </g>
19
+ </g>
20
+ </svg>
@@ -9,6 +9,8 @@ import BaseCalculator from './base-calculator';
9
9
  import { formatNumericValue, getSummaryColumnMethod } from '../utils/common-utils';
10
10
  import { getSqlGroup } from '../utils/sql-utils';
11
11
  import { DTABLE_DB_SUMMARY_METHOD } from '../constants';
12
+ import { fixMapGeoGranularity } from '../utils/map';
13
+ import StatUtils from '../utils/stat-utils';
12
14
  var MapCalculator = /*#__PURE__*/function (_BaseCalculator) {
13
15
  _inherits(MapCalculator, _BaseCalculator);
14
16
  var _super = _createSuper(MapCalculator);
@@ -87,12 +89,12 @@ var MapCalculator = /*#__PURE__*/function (_BaseCalculator) {
87
89
  key: "queryDb",
88
90
  value: function () {
89
91
  var _queryDb = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(chart) {
90
- var table_id, view_id, geo_column, summary_type, summary_method, summary_column, geolocation_granularity, selectedTable, selectedView, column, columnName, isAdvanced, method, sqlCondition, groupName, sqlString, summaryColumn, summaryColumnName, summaryColumnMethod, result, data, newResult, _summaryColumnMethod, valueKey;
92
+ var table_id, view_id, geo_column, summary_type, summary_method, summary_column, selectedTable, selectedView, column, columnName, isAdvanced, geoGranularity, method, sqlCondition, groupName, sqlString, summaryColumn, summaryColumnName, summaryColumnMethod, result, data, newResult, _summaryColumnMethod, valueKey;
91
93
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
92
94
  while (1) {
93
95
  switch (_context2.prev = _context2.next) {
94
96
  case 0:
95
- table_id = chart.table_id, view_id = chart.view_id, geo_column = chart.geo_column, summary_type = chart.summary_type, summary_method = chart.summary_method, summary_column = chart.summary_column, geolocation_granularity = chart.geolocation_granularity;
97
+ table_id = chart.table_id, view_id = chart.view_id, geo_column = chart.geo_column, summary_type = chart.summary_type, summary_method = chart.summary_method, summary_column = chart.summary_column;
96
98
  selectedTable = this.getTableById(table_id);
97
99
  selectedView = this.getViewById(view_id, selectedTable);
98
100
  column = TableUtils.getTableColumnByKey(selectedTable, geo_column);
@@ -104,65 +106,69 @@ var MapCalculator = /*#__PURE__*/function (_BaseCalculator) {
104
106
  case 6:
105
107
  columnName = column.name;
106
108
  isAdvanced = summary_type === 'advanced';
109
+ geoGranularity = fixMapGeoGranularity(chart);
107
110
  method = isAdvanced ? DTABLE_DB_SUMMARY_METHOD[summary_method] : 'COUNT';
108
111
  sqlCondition = filter2SqlCondition(selectedTable, selectedView);
109
- groupName = getSqlGroup(geolocation_granularity, column);
112
+ groupName = getSqlGroup(geoGranularity, column);
110
113
  sqlString = '';
111
114
  summaryColumnName = '';
112
115
  if (!isAdvanced) {
113
- _context2.next = 22;
116
+ _context2.next = 23;
114
117
  break;
115
118
  }
116
119
  summaryColumn = TableUtils.getTableColumnByKey(selectedTable, summary_column);
117
120
  if (summaryColumn) {
118
- _context2.next = 17;
121
+ _context2.next = 18;
119
122
  break;
120
123
  }
121
124
  return _context2.abrupt("return", []);
122
- case 17:
125
+ case 18:
123
126
  summaryColumnName = summaryColumn.name;
124
127
  summaryColumnMethod = getSummaryColumnMethod(method, summaryColumnName);
125
128
  sqlString = "select ".concat(groupName, ", ").concat(summaryColumnMethod, " from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by ").concat(groupName, " limit 5000");
126
- _context2.next = 23;
129
+ _context2.next = 24;
127
130
  break;
128
- case 22:
129
- sqlString = "select ".concat(groupName, ", ").concat(method, "(`").concat(columnName, "`) from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by ").concat(groupName, " limit 5000");
130
131
  case 23:
131
- _context2.next = 25;
132
+ sqlString = "select ".concat(groupName, ", ").concat(method, "(`").concat(columnName, "`) from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by ").concat(groupName, " limit 5000");
133
+ case 24:
134
+ _context2.next = 26;
132
135
  return this.sqlQuery(sqlString);
133
- case 25:
136
+ case 26:
134
137
  result = _context2.sent;
135
138
  if (!(result.status === 200 && result.data.success)) {
136
- _context2.next = 35;
139
+ _context2.next = 36;
137
140
  break;
138
141
  }
139
142
  data = result.data;
140
143
  if (data.results) {
141
- _context2.next = 30;
144
+ _context2.next = 31;
142
145
  break;
143
146
  }
144
147
  return _context2.abrupt("return", []);
145
- case 30:
148
+ case 31:
146
149
  newResult = [];
147
150
  _summaryColumnMethod = getSummaryColumnMethod(method, summaryColumnName);
148
151
  valueKey = isAdvanced ? "".concat(_summaryColumnMethod) : "".concat(method, "(").concat(columnName, ")");
149
152
  data.results.forEach(function (item) {
150
153
  var currentValue = item[groupName];
151
154
  var value = item[valueKey];
155
+ var formatted_value = value;
152
156
  if (isAdvanced) {
153
157
  value = formatNumericValue(value, summaryColumn);
158
+ formatted_value = StatUtils.getFormattedValue(value, summaryColumn, method);
154
159
  }
155
160
  if (currentValue) {
156
161
  newResult.push({
157
162
  name: currentValue,
158
- value: value
163
+ value: value,
164
+ formatted_value: formatted_value
159
165
  });
160
166
  }
161
167
  });
162
168
  return _context2.abrupt("return", newResult);
163
- case 35:
164
- return _context2.abrupt("return", []);
165
169
  case 36:
170
+ return _context2.abrupt("return", []);
171
+ case 37:
166
172
  case "end":
167
173
  return _context2.stop();
168
174
  }
@@ -6,6 +6,7 @@ import { getColorFromSingleSelectColumn } from '../../utils/column-utils';
6
6
  import { isArrayCellValue } from '../../utils/common-utils';
7
7
  import { getFormattedLabel, isValidRow } from '../../utils/row-utils';
8
8
  import StatUtils from '../../utils/stat-utils';
9
+ import { fixMapGeoGranularity } from '../../utils/map';
9
10
  var MAP_CHART_TYPES = [STAT_TYPE.MAP, STAT_TYPE.WORLD_MAP, STAT_TYPE.MAP_BUBBLE, STAT_TYPE.WORLD_MAP_BUBBLE];
10
11
  function calculateChart(chart, value, username, userId) {
11
12
  var type = chart.type;
@@ -309,11 +310,10 @@ function calculateGeolocationBasicChart(chart, value, username, userId) {
309
310
  var table_id = chart.table_id,
310
311
  view_id = chart.view_id,
311
312
  geo_column = chart.geo_column,
312
- geolocation_granularity = chart.geolocation_granularity,
313
313
  summary_type = chart.summary_type,
314
314
  summary_column = chart.summary_column,
315
315
  summary_method = chart.summary_method;
316
- var geolocationGranularity = geolocation_granularity;
316
+ var geolocationGranularity = fixMapGeoGranularity(chart);
317
317
  var table = TableUtils.getTableById(value.tables, table_id);
318
318
  var view = table && Views.getViewById(table.views, view_id);
319
319
  if (!view) {
@@ -77,6 +77,7 @@ var ChartAdditionEditDialog = /*#__PURE__*/function (_Component) {
77
77
  getTables: this.props.getTables,
78
78
  getViews: this.props.getViews,
79
79
  getTableById: getTableById,
80
+ queryMapJson: this.props.queryMapJson,
80
81
  getConvertedChart: this.props.getConvertedChart,
81
82
  modifyChartName: this.modifyChartName,
82
83
  modifyChart: this.modifyChart,
@@ -41,6 +41,7 @@ var EnlargeChartDialog = /*#__PURE__*/function (_Component) {
41
41
  eventBus: eventBus,
42
42
  chartCalculator: chartCalculator,
43
43
  getTableById: getTableById,
44
+ queryMapJson: _this.props.queryMapJson,
44
45
  toggleStatisticRecordsDialog: toggleStatisticRecordsDialog
45
46
  };
46
47
  return /*#__PURE__*/React.createElement("div", {
@@ -6,6 +6,7 @@ import React, { Fragment } from 'react';
6
6
  import intl from 'react-intl-universal';
7
7
  import { Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap';
8
8
  import { STAT_TYPE } from '../../constants';
9
+ import Icon from '../icon';
9
10
  var StatisticDropdownMenu = /*#__PURE__*/function (_React$Component) {
10
11
  _inherits(StatisticDropdownMenu, _React$Component);
11
12
  var _super = _createSuper(StatisticDropdownMenu);
@@ -14,6 +15,9 @@ var StatisticDropdownMenu = /*#__PURE__*/function (_React$Component) {
14
15
  _classCallCheck(this, StatisticDropdownMenu);
15
16
  _this = _super.call(this, props);
16
17
  _this.onDropdownToggleClick = function (e) {
18
+ if (e.target && _this.viewsDropdownToggle && _this.viewsDropdownToggle.contains(e.target)) {
19
+ return;
20
+ }
17
21
  e.preventDefault();
18
22
  e.stopPropagation();
19
23
  _this.setState({
@@ -26,17 +30,39 @@ var StatisticDropdownMenu = /*#__PURE__*/function (_React$Component) {
26
30
  _this.editStatItem = function () {
27
31
  _this.props.editStatItem();
28
32
  };
33
+ _this.onShowViewsMenu = function () {
34
+ _this.setState({
35
+ isShowViewsMenu: true
36
+ });
37
+ };
38
+ _this.onHideViewsMenu = function () {
39
+ _this.setState({
40
+ isShowViewsMenu: false
41
+ });
42
+ };
43
+ _this.onToggleViewsMenu = function () {
44
+ _this.setState({
45
+ isShowViewsMenu: !_this.state.isShowViewsMenu
46
+ });
47
+ };
48
+ _this.onMoveChartToView = function (viewId) {
49
+ _this.props.moveChartToView(viewId);
50
+ };
29
51
  _this.state = {
30
- isItemMenuShow: false
52
+ isItemMenuShow: false,
53
+ isShowViewsMenu: false
31
54
  };
32
55
  return _this;
33
56
  }
34
57
  _createClass(StatisticDropdownMenu, [{
35
58
  key: "render",
36
59
  value: function render() {
60
+ var _this2 = this;
37
61
  var _this$props = this.props,
38
62
  isTableReadOnly = _this$props.isTableReadOnly,
39
63
  chartType = _this$props.chartType;
64
+ var otherViews = this.props.getOtherStatistics();
65
+ var hasOtherViews = otherViews && otherViews.length > 0;
40
66
  return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Dropdown, {
41
67
  isOpen: this.state.isItemMenuShow,
42
68
  toggle: this.onDropdownToggleClick,
@@ -80,13 +106,63 @@ var StatisticDropdownMenu = /*#__PURE__*/function (_React$Component) {
80
106
  className: "item-icon dtable-font dtable-icon-download"
81
107
  }), /*#__PURE__*/React.createElement("span", {
82
108
  className: "item-text"
83
- }, intl.get('Export_as_picture'))), !isTableReadOnly && /*#__PURE__*/React.createElement(DropdownItem, {
109
+ }, intl.get('Export_as_picture'))), !isTableReadOnly && /*#__PURE__*/React.createElement(Fragment, null, hasOtherViews && /*#__PURE__*/React.createElement(DropdownItem, {
110
+ className: "pr-2 btn-move-to-statistic-view",
111
+ tag: "div",
112
+ onClick: function onClick(evt) {
113
+ evt.stopPropagation();
114
+ evt.nativeEvent.stopImmediatePropagation();
115
+ _this2.onShowViewsMenu();
116
+ },
117
+ onMouseEnter: this.onShowViewsMenu,
118
+ onMouseLeave: this.onHideViewsMenu
119
+ }, /*#__PURE__*/React.createElement(Dropdown, {
120
+ className: "statistic-views-dropdown",
121
+ direction: "right",
122
+ isOpen: this.state.isShowViewsMenu,
123
+ toggle: this.onToggleViewsMenu
124
+ }, /*#__PURE__*/React.createElement("div", {
125
+ className: "statistic-views-dropdown-toggle",
126
+ ref: function ref(_ref) {
127
+ return _this2.viewsDropdownToggle = _ref;
128
+ }
129
+ }, /*#__PURE__*/React.createElement(Icon, {
130
+ symbol: "move-to",
131
+ className: "statistic-type-move-to item-icon"
132
+ }), /*#__PURE__*/React.createElement("span", {
133
+ className: "item-text"
134
+ }, intl.get('Move_to')), /*#__PURE__*/React.createElement("span", {
135
+ className: "icon-dropdown-toggle"
136
+ }, /*#__PURE__*/React.createElement("i", {
137
+ className: "item-icon dtable-font dtable-icon-right-slide"
138
+ })), /*#__PURE__*/React.createElement(DropdownToggle, {
139
+ className: "move-to-statistic-views-toggle"
140
+ })), this.state.isShowViewsMenu && /*#__PURE__*/React.createElement(DropdownMenu, {
141
+ className: "statistic-views-dropdown-menu",
142
+ flip: false,
143
+ positionFixed: true,
144
+ modifiers: {
145
+ preventOverflow: {
146
+ boundariesElement: document.body
147
+ }
148
+ }
149
+ }, otherViews.map(function (view) {
150
+ var _id = view._id,
151
+ name = view.name;
152
+ return /*#__PURE__*/React.createElement(DropdownItem, {
153
+ key: "move-to-statistic-view-".concat(_id),
154
+ onClick: _this2.onMoveChartToView.bind(_this2, _id)
155
+ }, /*#__PURE__*/React.createElement("span", {
156
+ className: "statistic-view-name text-truncate",
157
+ title: name
158
+ }, name));
159
+ })))), /*#__PURE__*/React.createElement(DropdownItem, {
84
160
  onMouseDown: this.deleteStatItem
85
161
  }, /*#__PURE__*/React.createElement("i", {
86
162
  className: "item-icon dtable-font dtable-icon-delete"
87
163
  }), /*#__PURE__*/React.createElement("span", {
88
164
  className: "item-text"
89
- }, intl.get('Delete'))))));
165
+ }, intl.get('Delete')))))));
90
166
  }
91
167
  }]);
92
168
  return StatisticDropdownMenu;
@@ -15,6 +15,7 @@ export var DASHBOARD_ACTION_TYPE = {
15
15
  MODIFY_DASHBOARD_LAYOUT: 'modify_dashboard_layout',
16
16
  ADD_CHART: 'add_chart',
17
17
  MODIFY_CHART: 'modify_chart',
18
+ MOVE_CHART_TO_VIEW: 'move_chart_to_view',
18
19
  DELETE_CHART: 'delete_chart'
19
20
  };
20
21
  export var STAT_TYPE = {
@@ -0,0 +1,7 @@
1
+ export var MAP_LEVEL = {
2
+ WORLD: 'world',
3
+ COUNTRY: 'country',
4
+ PROVINCE: 'province',
5
+ CITY: 'city'
6
+ };
7
+ export var MUNICIPALITIES = ['北京市', '天津市', '上海市', '重庆市'];