amazing-react-charts 0.7.3 → 0.7.4

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.
@@ -62,9 +62,7 @@ var AreaChart = function AreaChart(props) {
62
62
  var yData = data.map(function (item) {
63
63
  return item.result;
64
64
  });
65
- var xData = xType === 'time' ? data.map(function (item) {
66
- return (0, _auxiliarFunctions.toDate)(item.label, dateFormat);
67
- }) : data.map(function (item) {
65
+ var xData = data.map(function (item) {
68
66
  return item.label;
69
67
  });
70
68
 
@@ -185,7 +183,7 @@ var AreaChart = function AreaChart(props) {
185
183
  },
186
184
  axisLabel: {
187
185
  formatter: function formatter(item) {
188
- return xType === 'time' ? (0, _auxiliarFunctions.formatTime)(item, dateFormat === 'yyyy-MM' ? 'MMM/yy' : 'dd MMM') : item;
186
+ return xType === 'time' ? (0, _auxiliarFunctions.formatTime)(item, (0, _auxiliarFunctions.getDateFormatType)(dateFormat)) : item;
189
187
  },
190
188
  rotate: rotateLabel || 0,
191
189
  rich: {
@@ -143,7 +143,7 @@ var LineChart = function LineChart(props) {
143
143
  },
144
144
  axisLabel: {
145
145
  formatter: function formatter(item) {
146
- return xType === 'time' ? (0, _auxiliarFunctions.formatTime)(dateFormat === 'yyyy-MM' ? item + '-02' : item, dateFormat === 'yyyy-MM' ? 'MMM/yy' : 'dd MMM') : item;
146
+ return xType === 'time' ? (0, _auxiliarFunctions.formatTime)(dateFormat === 'yyyy-MM' ? item + '-02' : item, (0, _auxiliarFunctions.getDateFormatType)(dateFormat)) : item;
147
147
  },
148
148
  rotate: rotateLabel || 0,
149
149
  textStyle: {
@@ -164,7 +164,7 @@ var LineChart = function LineChart(props) {
164
164
  axisLabel: {
165
165
  margin: yType === 'time' ? 16 : 14,
166
166
  formatter: function formatter(item) {
167
- return yType === 'time' ? (0, _auxiliarFunctions.timeConvert)(item) + 'h' : item + (typeof yComplement !== 'function' ? yComplement : '');
167
+ return yType === 'time' ? (0, _auxiliarFunctions.timeConvert)(item) + 'h' : (0, _auxiliarFunctions.takeLabelComplement)(item, yComplement);
168
168
  },
169
169
  textStyle: {
170
170
  fontSize: fontLabelSize || 11.5
@@ -164,12 +164,11 @@ var VerticalBarChart = function VerticalBarChart(props) {
164
164
  return {
165
165
  value: item.result,
166
166
  label: label,
167
+ itemStyle: item.style,
167
168
  itemId: item.itemId && item.itemId
168
169
  };
169
170
  });
170
- var xData = xType === 'time' ? data.map(function (item) {
171
- return (0, _auxiliarFunctions.toDate)(item.label, dateFormat);
172
- }) : data.map(function (item) {
171
+ var xData = data.map(function (item) {
173
172
  return item.label;
174
173
  });
175
174
 
@@ -283,7 +282,7 @@ var VerticalBarChart = function VerticalBarChart(props) {
283
282
  axisLabel: {
284
283
  rotate: rotateLabel && rotateLabel,
285
284
  formatter: function formatter(item) {
286
- return xType === 'time' ? (0, _auxiliarFunctions.formatTime)(item, dateFormat === 'yyyy-MM' ? 'MMM/yy' : 'dd/MM/yyyy') : specialLabel(item);
285
+ return xType === 'time' ? (0, _auxiliarFunctions.formatTime)(item, (0, _auxiliarFunctions.getDateFormatType)(dateFormat, 'dd/MM/yyyy')) : specialLabel(item);
287
286
  },
288
287
  interval: 0,
289
288
  fontSize: 11
@@ -7,7 +7,7 @@ export declare const generateAuxMessage: (label: string, result: number, complem
7
7
  export declare const monuntTimeMessage: (item: DataTooltip, stackedValues: number) => string;
8
8
  export declare const mountMessage: (value: DataTooltip, complement: Complement, axisType: string, stackedValues: number, sumDataValues: boolean) => string;
9
9
  export declare const toDate: (text: string, format?: string) => Date;
10
- export declare const formatTime: (text: string, dateFormat: string) => string;
10
+ export declare const formatTime: (text: string, dateFormat?: string) => string;
11
11
  export declare const formatTooltip: (text: string, dateFormat?: string) => string;
12
12
  export declare const formatTooltipWithHours: (text: string) => string;
13
13
  export declare const truncateLabel: (text: string, labelWordSize?: number) => string;
@@ -65,3 +65,4 @@ export declare const getWidthOpts: (width: WidthProps) => {
65
65
  export declare const convertImageToBase64FromUrl: (imgUrl: string) => Promise<unknown>;
66
66
  export declare const changeSpaceForUnderline: (value: string) => string;
67
67
  export declare const formatLabelWithImage: (text: string) => string;
68
+ export declare const getDateFormatType: (dateFormat: string, baseFormat?: string) => string;
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.formatLabelWithImage = exports.changeSpaceForUnderline = exports.convertImageToBase64FromUrl = exports.getWidthOpts = exports.getSaveAsImageWithTitle = exports.thousandSeparator = exports.getInitialValues = exports.getDataView = exports.getSaveAsImage = exports.fixedDomain = exports.getDomain = exports.fixedTruncateLabel = exports.truncateLabel = exports.formatTooltipWithHours = exports.formatTooltip = exports.formatTime = exports.toDate = exports.mountMessage = exports.monuntTimeMessage = exports.generateAuxMessage = exports.getPercentage = exports.timeConvert = exports.takeDonutChartComplement = exports.takeLabelComplement = void 0;
8
+ exports.getDateFormatType = exports.formatLabelWithImage = exports.changeSpaceForUnderline = exports.convertImageToBase64FromUrl = exports.getWidthOpts = exports.getSaveAsImageWithTitle = exports.thousandSeparator = exports.getInitialValues = exports.getDataView = exports.getSaveAsImage = exports.fixedDomain = exports.getDomain = exports.fixedTruncateLabel = exports.truncateLabel = exports.formatTooltipWithHours = exports.formatTooltip = exports.formatTime = exports.toDate = exports.mountMessage = exports.monuntTimeMessage = exports.generateAuxMessage = exports.getPercentage = exports.timeConvert = exports.takeDonutChartComplement = exports.takeLabelComplement = void 0;
9
9
 
10
10
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
11
 
@@ -103,7 +103,8 @@ var toDate = function toDate(text, format) {
103
103
 
104
104
  exports.toDate = toDate;
105
105
 
106
- var formatTime = function formatTime(text, dateFormat) {
106
+ var formatTime = function formatTime(text) {
107
+ var dateFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'dd MMM';
107
108
  return (0, _format.default)(new Date(text), dateFormat, {
108
109
  locale: _ptBR.default
109
110
  });
@@ -328,4 +329,14 @@ var formatLabelWithImage = function formatLabelWithImage(text) {
328
329
  return textFormatted;
329
330
  };
330
331
 
331
- exports.formatLabelWithImage = formatLabelWithImage;
332
+ exports.formatLabelWithImage = formatLabelWithImage;
333
+
334
+ var getDateFormatType = function getDateFormatType(dateFormat, baseFormat) {
335
+ if (dateFormat === 'yyyy-MM') {
336
+ return baseFormat ? baseFormat : 'MMM/yy';
337
+ }
338
+
339
+ return dateFormat;
340
+ };
341
+
342
+ exports.getDateFormatType = getDateFormatType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amazing-react-charts",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "An amazing react charts package based in echarts",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -9,8 +9,8 @@ import {
9
9
  getInitialValues,
10
10
  getSaveAsImage,
11
11
  timeConvert,
12
- toDate,
13
- takeLabelComplement
12
+ takeLabelComplement,
13
+ getDateFormatType
14
14
  } from '../lib/auxiliarFunctions'
15
15
  import {
16
16
  IDefaultChartProps,
@@ -57,10 +57,7 @@ const AreaChart = (props: IDefaultChartProps) => {
57
57
 
58
58
  const markLine = lineMarkValue && data.map(() => lineMarkValue)
59
59
  const yData = data.map((item: EntryData) => item.result)
60
- const xData =
61
- xType === 'time'
62
- ? data.map((item: EntryData) => toDate(item.label, dateFormat))
63
- : data.map((item: EntryData) => item.label)
60
+ const xData = data.map((item: EntryData) => item.label)
64
61
 
65
62
  const formatLabel = (chartValues: { data: number }) => {
66
63
  const { data } = chartValues
@@ -205,7 +202,7 @@ const AreaChart = (props: IDefaultChartProps) => {
205
202
  axisLabel: {
206
203
  formatter: (item: string) =>
207
204
  xType === 'time'
208
- ? formatTime(item, dateFormat === 'yyyy-MM' ? 'MMM/yy' : 'dd MMM')
205
+ ? formatTime(item, getDateFormatType(dateFormat))
209
206
  : item,
210
207
  rotate: rotateLabel || 0,
211
208
  rich: {
@@ -9,6 +9,7 @@ import {
9
9
  import {
10
10
  formatTime,
11
11
  getDataView,
12
+ getDateFormatType,
12
13
  getInitialValues,
13
14
  getSaveAsImage,
14
15
  getWidthOpts,
@@ -161,7 +162,7 @@ const LineChart = (props: IProps) => {
161
162
  xType === 'time'
162
163
  ? formatTime(
163
164
  dateFormat === 'yyyy-MM' ? item + '-02' : item,
164
- dateFormat === 'yyyy-MM' ? 'MMM/yy' : 'dd MMM'
165
+ getDateFormatType(dateFormat)
165
166
  )
166
167
  : item,
167
168
  rotate: rotateLabel || 0,
@@ -185,7 +186,7 @@ const LineChart = (props: IProps) => {
185
186
  formatter: (item: number) =>
186
187
  yType === 'time'
187
188
  ? timeConvert(item) + 'h'
188
- : item + (typeof yComplement !== 'function' ? yComplement : ''),
189
+ : takeLabelComplement(item, yComplement),
189
190
  textStyle: {
190
191
  fontSize: fontLabelSize || 11.5
191
192
  }
@@ -17,10 +17,10 @@ import {
17
17
  getDomain,
18
18
  getSaveAsImage,
19
19
  timeConvert,
20
- toDate,
21
20
  fixedTruncateLabel,
22
21
  takeLabelComplement,
23
- getWidthOpts
22
+ getWidthOpts,
23
+ getDateFormatType
24
24
  } from '../lib/auxiliarFunctions'
25
25
  import { WIDTH_STYLE } from './DonutChart'
26
26
 
@@ -146,14 +146,12 @@ const VerticalBarChart = (props: IProps) => {
146
146
  return {
147
147
  value: item.result,
148
148
  label: label,
149
+ itemStyle: item.style,
149
150
  itemId: item.itemId && item.itemId
150
151
  }
151
152
  })
152
153
 
153
- const xData =
154
- xType === 'time'
155
- ? data.map((item: EntryData) => toDate(item.label, dateFormat))
156
- : data.map((item: EntryData) => item.label)
154
+ const xData = data.map((item: EntryData) => item.label)
157
155
 
158
156
  const specialLabel = (item: string) =>
159
157
  fixedTruncateLabel(item, xData.length <= 5 ? 16 : 9)
@@ -292,7 +290,7 @@ const VerticalBarChart = (props: IProps) => {
292
290
  axisLabel: {
293
291
  rotate: rotateLabel && rotateLabel,
294
292
  formatter: (item: string) => xType === 'time'
295
- ? formatTime(item, dateFormat === 'yyyy-MM' ? 'MMM/yy' : 'dd/MM/yyyy')
293
+ ? formatTime(item, getDateFormatType(dateFormat, 'dd/MM/yyyy'))
296
294
  : specialLabel(item),
297
295
  interval: 0,
298
296
  fontSize: 11
@@ -6,9 +6,9 @@ route: /areachart
6
6
  import AreaChart from '../core/AreaChart'
7
7
  import { Playground } from 'docz'
8
8
 
9
- # Area chart example
9
+ # Demo
10
10
 
11
- ## Demo
11
+ ## Area chart example
12
12
  <Playground>
13
13
  <AreaChart
14
14
  color='#3e2723'
@@ -42,6 +42,7 @@ import { Playground } from 'docz'
42
42
  />
43
43
  </Playground>
44
44
 
45
+ ## Area chart example with time
45
46
  <Playground>
46
47
  <AreaChart
47
48
  color='#74007c'
@@ -65,6 +66,7 @@ import { Playground } from 'docz'
65
66
  />
66
67
  </Playground>
67
68
 
69
+ ## Area chart example with date
68
70
  <Playground>
69
71
  <AreaChart
70
72
  xType='time'
@@ -134,3 +136,22 @@ import { Playground } from 'docz'
134
136
  />
135
137
  </Playground>
136
138
 
139
+ ## Area chart example with date and time
140
+ <Playground>
141
+ <AreaChart
142
+ xType='time'
143
+ dateFormat="MMM/dd HH:mm"
144
+ title='area chart data'
145
+ toolboxTooltip={{ saveAsImage: 'saving'}}
146
+ tooltip={ { label: 'Data', result: 'O.S. em aberto' } }
147
+ color='#E65100'
148
+ data={
149
+ [
150
+ { label: '2019-09-01 08:40', result: 1 },
151
+ { label: '2019-09-02 12:32', result: 4 },
152
+ { label: '2019-09-03 14:20', result: 3 },
153
+ { label: '2019-09-04 19:25', result: 2 },
154
+ ]
155
+ }
156
+ />
157
+ </Playground>
@@ -6,9 +6,9 @@ route: /line-charts
6
6
  import LineChart from '../core/LineChart'
7
7
  import { Playground } from 'docz'
8
8
 
9
- # line chart example
9
+ # Demo
10
10
 
11
- ## Demo
11
+ ## line chart example
12
12
  <Playground>
13
13
  <LineChart
14
14
  showLabel
@@ -57,3 +57,40 @@ import { Playground } from 'docz'
57
57
  ] }
58
58
  />
59
59
  </Playground>
60
+
61
+
62
+ ## line chart example with date and time
63
+ <Playground>
64
+ <LineChart
65
+ showLabel
66
+ title='Concurrent lines'
67
+ xType='time'
68
+ toolboxTooltip={{ saveAsImage: 'saving'}}
69
+ dateFormat='MMM/dd HH:mm'
70
+ colors={ ['red', 'green', 'blue'] }
71
+ data={ [
72
+ {
73
+ name: 'top line',
74
+ values: [
75
+ { label: '2019-01 08:40', result: 10 },
76
+ { label: '2019-02 09:12', result: 40 },
77
+ { label: '2019-03 10:25', result: 30 },
78
+ { label: '2019-04 12:30', result: 20 },
79
+ { label: '2019-05 14:30', result: 40 },
80
+ { label: '2019-06 18:45', result: 50 }
81
+ ]
82
+ },
83
+ {
84
+ name: 'bottom line',
85
+ values: [
86
+ { label: '2019-01 08:40', result: 1 },
87
+ { label: '2019-02 09:12', result: 4 },
88
+ { label: '2019-03 10:25', result: 3 },
89
+ { label: '2019-04 12:30', result: 2 },
90
+ { label: '2019-05 14:30', result: 4 },
91
+ { label: '2019-06 18:45', result: 5 }
92
+ ]
93
+ }
94
+ ] }
95
+ />
96
+ </Playground>
@@ -6,8 +6,9 @@ route: /vertical-bar-chart
6
6
  import VerticalBarChart from "../core/VerticalBarChart";
7
7
  import { Playground } from "docz";
8
8
 
9
- # Vertical bar chart example
9
+ # Demo
10
10
 
11
+ ## Vertical bar chart example
11
12
  <Playground>
12
13
  <VerticalBarChart
13
14
  showBarLabel
@@ -163,8 +164,7 @@ import { Playground } from "docz";
163
164
  />
164
165
  </Playground>
165
166
 
166
- # Vertical bar chart example with customMaxDomain
167
-
167
+ ## Vertical bar chart example with customMaxDomain
168
168
  <Playground>
169
169
  <VerticalBarChart
170
170
  showBarLabel
@@ -189,8 +189,7 @@ import { Playground } from "docz";
189
189
  />
190
190
  </Playground>
191
191
 
192
- # Vertical bar chart with dateFormat
193
-
192
+ ## Vertical bar chart with dateFormat
194
193
  <Playground>
195
194
  <VerticalBarChart
196
195
  showBarLabel
@@ -211,8 +210,7 @@ import { Playground } from "docz";
211
210
  />
212
211
  </Playground>
213
212
 
214
- # Vertical bar chart with time format
215
-
213
+ ## Vertical bar chart with time format
216
214
  <Playground>
217
215
  <VerticalBarChart
218
216
  showBarLabel
@@ -240,3 +238,36 @@ import { Playground } from "docz";
240
238
  ]}
241
239
  />
242
240
  </Playground>
241
+
242
+ ## Vertical bar chart with yComplement like a function
243
+ <Playground>
244
+ <VerticalBarChart
245
+ yComplement={value => value === 1 ? 'Saudavel' : value === 2 ? 'Alerta' : value === 3 ? 'Crítico' : ''}
246
+ xType="time"
247
+ yType="value"
248
+ color="green"
249
+ customMaxDomain={3}
250
+ dateFormat='yyyy-MM-dd'
251
+ tooltip={{ label: 'Data', result: 'Sáude' }}
252
+ data={[
253
+ {
254
+ label: '2023-06-29',
255
+ result: '1',
256
+ itemId: 1,
257
+ style: { color: 'green' }
258
+ },
259
+ {
260
+ label: '2023-06-30',
261
+ result: '3',
262
+ itemId: 1,
263
+ style: { color: 'red' }
264
+ },
265
+ {
266
+ label: '2023-07-01',
267
+ result: '2',
268
+ itemId: 1,
269
+ style: { color: 'yellow' }
270
+ }
271
+ ]}
272
+ />
273
+ </Playground>
@@ -154,7 +154,7 @@ export const mountMessage = (
154
154
  export const toDate = (text: string, format?: string) =>
155
155
  parse(text, format ? format : 'yyyy-MM-dd', new Date())
156
156
 
157
- export const formatTime = (text: string, dateFormat: string) =>
157
+ export const formatTime = (text: string, dateFormat = 'dd MMM') =>
158
158
  format(new Date(text), dateFormat, { locale: ptBR })
159
159
 
160
160
  export const formatTooltip = (text: string, dateFormat?: string) =>
@@ -345,3 +345,11 @@ export const formatLabelWithImage = (text: string) => {
345
345
 
346
346
  return textFormatted
347
347
  }
348
+
349
+ export const getDateFormatType = (dateFormat: string, baseFormat?: string) => {
350
+ if (dateFormat === 'yyyy-MM') {
351
+ return baseFormat ? baseFormat : 'MMM/yy'
352
+ }
353
+
354
+ return dateFormat
355
+ }