amazing-react-charts 0.7.7 → 0.7.9

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
- var _typeof = require("@babel/runtime/helpers/typeof");
5
+ var _typeof3 = require("@babel/runtime/helpers/typeof");
6
6
 
7
7
  Object.defineProperty(exports, "__esModule", {
8
8
  value: true
@@ -11,6 +11,8 @@ exports.default = void 0;
11
11
 
12
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
13
 
14
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
15
+
14
16
  var React = _interopRequireWildcard(require("react"));
15
17
 
16
18
  var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
@@ -21,7 +23,7 @@ var _constants = require("../lib/constants");
21
23
 
22
24
  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); }
23
25
 
24
- 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; }
26
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(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; }
25
27
 
26
28
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
27
29
 
@@ -60,6 +62,12 @@ var LineChart = function LineChart(props) {
60
62
  var names = data.map(function (item) {
61
63
  return item.name;
62
64
  });
65
+
66
+ var formatLabel = function formatLabel(chartValues) {
67
+ var data = chartValues.data;
68
+ return yType === 'time' ? (0, _auxiliarFunctions.timeConvert)(Number(data)) + 'h' : (0, _auxiliarFunctions.takeLabelComplement)(Number(data), yComplement);
69
+ };
70
+
63
71
  var series = data.map(function (item) {
64
72
  return {
65
73
  name: item.name,
@@ -76,7 +84,14 @@ var LineChart = function LineChart(props) {
76
84
  position: 'top',
77
85
  fontSize: yType === 'time' ? 10 : 11.5,
78
86
  color: 'black',
79
- distance: 1.1
87
+ distance: 1.1,
88
+ formatter: function formatter(item) {
89
+ if (typeof yComplement === 'function' && (0, _typeof2.default)(item) === 'object') {
90
+ return yComplement(item.data);
91
+ }
92
+
93
+ typeof yComplement === 'function' ? yComplement : formatLabel;
94
+ }
80
95
  }
81
96
  };
82
97
  });
@@ -134,7 +134,8 @@ var VerticalBarChart = function VerticalBarChart(props) {
134
134
  onClickBar = props.onClickBar,
135
135
  marginRightToolbox = props.marginRightToolbox,
136
136
  customMaxDomain = props.customMaxDomain,
137
- interval = props.interval;
137
+ interval = props.interval,
138
+ scrollStart = props.scrollStart;
138
139
  var isCustomDomain = customMaxDomain ? customMaxDomain : _auxiliarFunctions.getDomain;
139
140
  var yData = data.map(function (item) {
140
141
  var results = data.map(function (item) {
@@ -241,13 +242,16 @@ var VerticalBarChart = function VerticalBarChart(props) {
241
242
  return "".concat(label, ": ").concat(labelPrint, " <br>") + "".concat(result, ": ").concat(values, " <br>") + complement;
242
243
  };
243
244
 
244
- var scrollable = data.length > 12 ? [{
245
+ var arrayInitialSize = scrollStart || (dateFormat === 'yyyy-MM' ? 12 : 30);
246
+ var scrollable = data.length > arrayInitialSize ? [{
245
247
  type: 'inside',
248
+ start: (0, _auxiliarFunctions.getInitialValues)(xData.length, dateFormat, scrollStart),
246
249
  endValue: xData.length > 12 ? xData[11] : xData[xData.length - 1],
247
250
  zoomOnMouseWheel: 'shift'
248
251
  }, {
249
252
  show: true,
250
253
  type: 'slider',
254
+ start: (0, _auxiliarFunctions.getInitialValues)(xData.length, dateFormat, scrollStart),
251
255
  endValue: xData.length > 12 ? xData[11] : xData[xData.length - 1]
252
256
  }] : [];
253
257
  var options = {
@@ -112,7 +112,8 @@ var formatTime = function formatTime(text) {
112
112
 
113
113
  exports.formatTime = formatTime;
114
114
 
115
- var formatTooltip = function formatTooltip(text, dateFormat) {
115
+ var formatTooltip = function formatTooltip(text) {
116
+ var dateFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'dd MMM';
116
117
  return (0, _format.default)(new Date(text), getDateFormatType(dateFormat, 'dd/MM/yyyy'), {
117
118
  locale: _ptBR.default
118
119
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amazing-react-charts",
3
- "version": "0.7.7",
3
+ "version": "0.7.9",
4
4
  "description": "An amazing react charts package based in echarts",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -55,6 +55,14 @@ const LineChart = (props: IProps) => {
55
55
  const yData = data[0].values.map(item => item.result)
56
56
  const xData = data[0].values.map(item => item.label)
57
57
  const names = data.map(item => item.name)
58
+
59
+ const formatLabel = (chartValues: { data: number }) => {
60
+ const { data } = chartValues
61
+
62
+ return yType === 'time'
63
+ ? timeConvert(Number(data as number)) + 'h'
64
+ : takeLabelComplement(Number(data), yComplement)
65
+ }
58
66
 
59
67
  const series = data.map(item => ({
60
68
  name: item.name,
@@ -71,7 +79,18 @@ const LineChart = (props: IProps) => {
71
79
  position: 'top',
72
80
  fontSize: yType === 'time' ? 10 : 11.5,
73
81
  color: 'black',
74
- distance: 1.1
82
+ distance: 1.1,
83
+ formatter: (item: number | string | {data: number}) => {
84
+ if(typeof yComplement === 'function' && typeof item === 'object') {
85
+ return yComplement(item.data)
86
+ }
87
+
88
+
89
+ typeof yComplement === 'function'
90
+ ? yComplement
91
+ : formatLabel
92
+
93
+ }
75
94
  }
76
95
  }))
77
96
 
@@ -20,7 +20,8 @@ import {
20
20
  fixedTruncateLabel,
21
21
  takeLabelComplement,
22
22
  getWidthOpts,
23
- getDateFormatType
23
+ getDateFormatType,
24
+ getInitialValues
24
25
  } from '../lib/auxiliarFunctions'
25
26
  import { WIDTH_STYLE } from '../lib/constants'
26
27
 
@@ -115,6 +116,7 @@ const VerticalBarChart = (props: IProps) => {
115
116
  marginRightToolbox,
116
117
  customMaxDomain,
117
118
  interval,
119
+ scrollStart
118
120
  } = props
119
121
 
120
122
  const isCustomDomain = customMaxDomain
@@ -241,17 +243,21 @@ const VerticalBarChart = (props: IProps) => {
241
243
  )
242
244
  }
243
245
 
246
+ const arrayInitialSize = scrollStart || (dateFormat === 'yyyy-MM' ? 12 : 30)
247
+
244
248
  const scrollable: ZoomProps[] =
245
- data.length > 12
249
+ data.length > arrayInitialSize
246
250
  ? [
247
251
  {
248
252
  type: 'inside',
253
+ start: getInitialValues(xData.length, dateFormat, scrollStart),
249
254
  endValue: xData.length > 12 ? xData[11] : xData[xData.length - 1],
250
255
  zoomOnMouseWheel: 'shift'
251
256
  },
252
257
  {
253
258
  show: true,
254
259
  type: 'slider',
260
+ start: getInitialValues(xData.length, dateFormat, scrollStart),
255
261
  endValue: xData.length > 12 ? xData[11] : xData[xData.length - 1]
256
262
  }
257
263
  ]
@@ -157,11 +157,10 @@ export const toDate = (text: string, format?: string) =>
157
157
  export const formatTime = (text: string, dateFormat = 'dd MMM') =>
158
158
  format(new Date(text), dateFormat, { locale: ptBR })
159
159
 
160
- export const formatTooltip = (text: string, dateFormat?: string) =>
161
- format(
162
- new Date(text), getDateFormatType(dateFormat, 'dd/MM/yyyy'), {
163
- locale: ptBR
164
- })
160
+ export const formatTooltip = (text: string, dateFormat = 'dd MMM') => format(
161
+ new Date(text), getDateFormatType(dateFormat, 'dd/MM/yyyy'), {
162
+ locale: ptBR
163
+ })
165
164
 
166
165
  export const formatTooltipWithHours = (text: string) =>
167
166
  format(new Date(text), 'dd/MM/yyyy HH:mm', { locale: ptBR })