ag-common 0.0.379 → 0.0.381

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.
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.getAndValidateToken = void 0;
16
16
  /* eslint-disable import/no-unresolved */
17
17
  const jsonwebtoken_1 = require("jsonwebtoken");
18
+ // eslint-disable-next-line import/no-named-as-default
18
19
  const jwks_rsa_1 = __importDefault(require("jwks-rsa"));
19
20
  const log_1 = require("../../common/helpers/log");
20
21
  const api_1 = require("./api");
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ export interface IInfiniteScrollList {
3
+ children: any[];
4
+ className?: string;
5
+ startIndex?: number;
6
+ onScroll?: (e: {
7
+ scrollTop: number;
8
+ isDown: boolean;
9
+ }) => void;
10
+ /** how many to initially show, and to add per scroll. default 10 */
11
+ incrementNumber?: number;
12
+ }
13
+ export declare const InfiniteScrollList: (p: IInfiniteScrollList) => JSX.Element;
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.InfiniteScrollList = void 0;
30
+ const styled_1 = __importDefault(require("@emotion/styled"));
31
+ const react_1 = __importStar(require("react"));
32
+ const debounce_1 = require("../../helpers/debounce");
33
+ const dom_1 = require("../../helpers/dom");
34
+ const Base = styled_1.default.div `
35
+ overflow-y: auto;
36
+ height: 100%;
37
+ width: 100%;
38
+ `;
39
+ //if we see this, then we havent shown user enough items - allow click to load more
40
+ const LoadMore = styled_1.default.div `
41
+ cursor: pointer;
42
+ text-decoration: underline;
43
+ `;
44
+ const InfiniteScrollList = (p) => {
45
+ var _a;
46
+ const { incrementNumber = 10 } = p;
47
+ const ref = (0, react_1.createRef)();
48
+ const [startIndex] = (0, react_1.useState)((_a = p.startIndex) !== null && _a !== void 0 ? _a : 0);
49
+ const [endIndex, setEndIndex] = (0, react_1.useState)((startIndex !== null && startIndex !== void 0 ? startIndex : 0) + incrementNumber);
50
+ const [startScrollTop, setStartScrollTop] = (0, react_1.useState)(0);
51
+ const handleScrollTop = (e) => {
52
+ const { scrollTop, clientHeight, scrollHeight } = e.currentTarget;
53
+ const hasReachedEnd = scrollTop + clientHeight === scrollHeight;
54
+ if (hasReachedEnd) {
55
+ setEndIndex(endIndex + incrementNumber);
56
+ }
57
+ };
58
+ (0, react_1.useEffect)(() => {
59
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
60
+ setStartScrollTop(ref.current.scrollTop);
61
+ // eslint-disable-next-line react-hooks/exhaustive-deps
62
+ }, []);
63
+ const sliced = p.children.slice(0, endIndex);
64
+ const lastDisplayIndex = Math.min(p.children.length, endIndex);
65
+ return (react_1.default.createElement(Base, Object.assign({ ref: ref, className: p.className, onScroll: (e) => {
66
+ const { scrollTop } = e.currentTarget;
67
+ handleScrollTop(e);
68
+ //
69
+ (0, debounce_1.debounce)(() => {
70
+ var _a;
71
+ setStartScrollTop(scrollTop);
72
+ (_a = p === null || p === void 0 ? void 0 : p.onScroll) === null || _a === void 0 ? void 0 : _a.call(p, { scrollTop, isDown: startScrollTop < scrollTop });
73
+ }, {
74
+ key: 'in-scr',
75
+ time: 50,
76
+ });
77
+ } }, (0, dom_1.filterDataProps)(p)),
78
+ sliced,
79
+ `Showing ${lastDisplayIndex} of ${p.children.length} results`,
80
+ lastDisplayIndex < p.children.length && (react_1.default.createElement(LoadMore, { onClick: () => setEndIndex(endIndex + incrementNumber) }, "Load More?"))));
81
+ };
82
+ exports.InfiniteScrollList = InfiniteScrollList;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ export interface IPieChartData {
3
+ label: string;
4
+ value: number;
5
+ color: string;
6
+ }
7
+ export interface IPieChart {
8
+ data: IPieChartData[];
9
+ className?: string;
10
+ }
11
+ export declare const PieChart: React.FC<IPieChart>;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PieChart = void 0;
7
+ const styled_1 = __importDefault(require("@emotion/styled"));
8
+ const react_1 = __importDefault(require("react"));
9
+ const Base = styled_1.default.div `
10
+ width: 100%;
11
+ height: 100%;
12
+ `;
13
+ const PieChart = ({ data, className }) => {
14
+ const total = data.reduce((sum, { value }) => sum + value, 0);
15
+ const width = 500;
16
+ const height = 500;
17
+ const centerX = width / 2;
18
+ const centerY = height / 2;
19
+ const radius = Math.min(width, height) / 2;
20
+ let cumulativeAngle = 0;
21
+ return (react_1.default.createElement(Base, { className: className },
22
+ react_1.default.createElement("svg", { viewBox: `0 0 ${width} ${height}` }, data.map(({ label, value, color }) => {
23
+ const angle = (value / total) * 360;
24
+ const startX = centerX + radius * Math.cos((cumulativeAngle * Math.PI) / 180);
25
+ const startY = centerY + radius * Math.sin((cumulativeAngle * Math.PI) / 180);
26
+ const endX = centerX +
27
+ radius * Math.cos(((cumulativeAngle + angle) * Math.PI) / 180);
28
+ const endY = centerY +
29
+ radius * Math.sin(((cumulativeAngle + angle) * Math.PI) / 180);
30
+ const largeArcFlag = angle > 180 ? 1 : 0;
31
+ const midAngle = cumulativeAngle + angle / 2;
32
+ const midX = centerX + radius * 0.75 * Math.cos((midAngle * Math.PI) / 180);
33
+ const midY = centerY + radius * 0.75 * Math.sin((midAngle * Math.PI) / 180);
34
+ cumulativeAngle += angle;
35
+ return (react_1.default.createElement("g", { key: label },
36
+ react_1.default.createElement("title", null, `${label}: ${value}`),
37
+ react_1.default.createElement("path", { d: `M ${startX} ${startY} A ${radius} ${radius} 0 ${largeArcFlag} 1 ${endX} ${endY} L ${centerX} ${centerY} Z`, fill: color }),
38
+ react_1.default.createElement("text", { x: midX, y: midY, textAnchor: "middle", alignmentBaseline: "middle", stroke: "white", strokeWidth: '3px' }, label),
39
+ react_1.default.createElement("text", { x: midX, y: midY, textAnchor: "middle", alignmentBaseline: "middle", fill: "black" }, label)));
40
+ }))));
41
+ };
42
+ exports.PieChart = PieChart;
@@ -1,6 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import { ISearchDialog, TSearchModalRes } from './types';
3
- export declare const SearchBase: <T>({ onSelectItem, onSearchTextChange, placeholderText, renderItem, displayItems, willDisplayItem, getKeyF, className, texts, maxDisplayItems, defaultValue, }: ISearchDialog<T> & {
4
- onSearchTextChange?: ((v: string) => void) | undefined;
5
- onSelectItem?: ((v: TSearchModalRes<T>) => void) | undefined;
6
- }) => JSX.Element;
3
+ type ISearchBase<T> = ISearchDialog<T> & {
4
+ onSearchTextChange?: (v: string) => void;
5
+ onSelectItem?: (v: TSearchModalRes<T>) => void;
6
+ };
7
+ export declare const SearchBase: <T>(p: ISearchBase<T>) => JSX.Element;
8
+ export {};
@@ -30,38 +30,14 @@ exports.SearchBase = void 0;
30
30
  const styled_1 = __importDefault(require("@emotion/styled"));
31
31
  const react_1 = __importStar(require("react"));
32
32
  const common_1 = require("../../../common");
33
- const helpers_1 = require("../../helpers");
34
- const CrossIcon_1 = require("../../icons/CrossIcon");
35
- const Magnify_1 = require("../../icons/Magnify");
36
33
  const styles_1 = require("../../styles");
37
- const TextEdit_1 = require("../TextEdit");
34
+ const SearchBox_1 = require("./SearchBox");
38
35
  const Base = styled_1.default.div `
39
36
  display: flex;
40
37
  flex-flow: column;
41
38
  flex-grow: 1;
42
39
  width: 100%;
43
40
  `;
44
- const SearchBox = styled_1.default.div `
45
- padding: 1rem;
46
- display: flex;
47
- flex-flow: row;
48
- justify-content: center;
49
- align-items: center;
50
- width: calc(100% - 2rem);
51
- margin: auto;
52
-
53
- @media ${styles_1.smallScreen} {
54
- margin: 0;
55
- padding: 0;
56
- padding-top: 0.5rem;
57
- width: 100%;
58
- }
59
- `;
60
- const Icon = styled_1.default.div `
61
- width: 1.5rem;
62
- height: 1.5rem;
63
- margin-right: 0.5rem;
64
- `;
65
41
  const Content = styled_1.default.div `
66
42
  width: calc(100% - 2rem);
67
43
  margin: auto;
@@ -87,43 +63,27 @@ const Row = styled_1.default.div `
87
63
  width: 100%;
88
64
  cursor: pointer;
89
65
  `;
90
- const CrossIconStyled = (0, styled_1.default)(CrossIcon_1.CrossIcon) `
91
- position: absolute;
92
- right: 1rem;
93
- @media ${styles_1.bigScreen} {
94
- right: 2rem;
95
- }
96
- `;
97
- const SearchBase = ({ onSelectItem, onSearchTextChange, placeholderText, renderItem, displayItems, willDisplayItem, getKeyF, className, texts, maxDisplayItems = 20, defaultValue, }) => {
98
- var _a, _b;
99
- const [searchText, setSearchText] = (0, react_1.useState)(defaultValue !== null && defaultValue !== void 0 ? defaultValue : '');
66
+ const SearchBase = (p) => {
67
+ var _a, _b, _c, _d;
68
+ const { maxDisplayItems = 20 } = p;
69
+ const [searchText, setSearchText] = (0, react_1.useState)((_a = p.defaultValue) !== null && _a !== void 0 ? _a : '');
100
70
  const resWrap = (foundItem) => {
71
+ var _a, _b;
101
72
  if (!foundItem) {
102
- onSelectItem === null || onSelectItem === void 0 ? void 0 : onSelectItem(undefined);
73
+ (_a = p.onSelectItem) === null || _a === void 0 ? void 0 : _a.call(p, undefined);
103
74
  }
104
75
  else {
105
- onSelectItem === null || onSelectItem === void 0 ? void 0 : onSelectItem({ foundItem, searchText });
76
+ (_b = p.onSelectItem) === null || _b === void 0 ? void 0 : _b.call(p, { foundItem, searchText });
106
77
  }
107
78
  };
108
- const filteredItemsRaw = displayItems.filter((i) => willDisplayItem(searchText, i));
79
+ const filteredItemsRaw = p.displayItems.filter((i) => p.willDisplayItem(searchText, i));
109
80
  const { part: filteredItems } = (0, common_1.take)(filteredItemsRaw, maxDisplayItems);
110
- const showText = (_b = (_a = texts === null || texts === void 0 ? void 0 : texts.totalItems) === null || _a === void 0 ? void 0 : _a.call(texts, filteredItems.length, displayItems.length)) !== null && _b !== void 0 ? _b : `Showing ${filteredItems.length} out of ${displayItems.length} total
81
+ const showText = (_d = (_c = (_b = p.texts) === null || _b === void 0 ? void 0 : _b.totalItems) === null || _c === void 0 ? void 0 : _c.call(_b, filteredItems.length, p.displayItems.length)) !== null && _d !== void 0 ? _d : `Showing ${filteredItems.length} out of ${p.displayItems.length} total
111
82
  items`;
112
- const textEditRef = (0, react_1.createRef)();
113
- return (react_1.default.createElement(Base, { className: className },
114
- react_1.default.createElement(SearchBox, { "data-type": "search" },
115
- react_1.default.createElement(TextEdit_1.TextEdit, { ref: textEditRef, placeholder: placeholderText, defaultEditing: { focus: true }, singleLine: true, leftContent: react_1.default.createElement(Icon, null, Magnify_1.Magnify), noGrow: true, allowUndo: false, onEscape: () => resWrap(undefined), onClickOutsideWithNoValue: null, onSubmit: (v) => (0, helpers_1.debounce)(() => {
116
- setSearchText(v);
117
- onSearchTextChange === null || onSearchTextChange === void 0 ? void 0 : onSearchTextChange(v);
118
- }, { key: 'pagesearch', time: 200 }), defaultValue: defaultValue }),
119
- searchText && (react_1.default.createElement(CrossIconStyled, { onClick: () => {
120
- var _a;
121
- (_a = textEditRef.current) === null || _a === void 0 ? void 0 : _a.setValue('');
122
- setSearchText('');
123
- onSearchTextChange === null || onSearchTextChange === void 0 ? void 0 : onSearchTextChange('');
124
- } }))),
83
+ return (react_1.default.createElement(Base, { className: p.className },
84
+ react_1.default.createElement(SearchBox_1.SearchBox, Object.assign({}, p, { searchText: searchText, setSearchText: setSearchText, onClear: () => resWrap(undefined) })),
125
85
  react_1.default.createElement(Content, { "data-hasitems": !!filteredItems.length, "data-type": "content" },
126
- filteredItems.map((item, index) => (react_1.default.createElement(Row, { key: getKeyF(item), onClick: () => resWrap(item) }, renderItem({ searchText, item, index })))),
86
+ filteredItems.map((item, index) => (react_1.default.createElement(Row, { key: p.getKeyF(item), onClick: () => resWrap(item) }, p.renderItem({ searchText, item, index })))),
127
87
  searchText && react_1.default.createElement(Row, null, showText))));
128
88
  };
129
89
  exports.SearchBase = SearchBase;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ export declare const SearchBox: (p: {
3
+ placeholderText?: string | undefined;
4
+ onClear?: (() => void) | undefined;
5
+ searchText: string;
6
+ setSearchText: (s: string) => void;
7
+ onSearchTextChange?: ((v: string) => void) | undefined;
8
+ defaultValue?: string | undefined;
9
+ }) => JSX.Element;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.SearchBox = void 0;
30
+ const styled_1 = __importDefault(require("@emotion/styled"));
31
+ const react_1 = __importStar(require("react"));
32
+ const helpers_1 = require("../../helpers");
33
+ const icons_1 = require("../../icons");
34
+ const styles_1 = require("../../styles");
35
+ const TextEdit_1 = require("../TextEdit");
36
+ const Base = styled_1.default.div `
37
+ padding: 1rem;
38
+ display: flex;
39
+ flex-flow: row;
40
+ justify-content: center;
41
+ align-items: center;
42
+ width: calc(100% - 2rem);
43
+ margin: auto;
44
+
45
+ @media ${styles_1.smallScreen} {
46
+ margin: 0;
47
+ padding: 0;
48
+ padding-top: 0.5rem;
49
+ width: 100%;
50
+ }
51
+ `;
52
+ const Icon = styled_1.default.div `
53
+ width: 1.5rem;
54
+ height: 1.5rem;
55
+ margin-right: 0.5rem;
56
+ `;
57
+ const CrossIconStyled = (0, styled_1.default)(icons_1.CrossIcon) `
58
+ position: absolute;
59
+ right: 1rem;
60
+ @media ${styles_1.bigScreen} {
61
+ right: 2rem;
62
+ }
63
+ `;
64
+ const SearchBox = (p) => {
65
+ const textEditRef = (0, react_1.createRef)();
66
+ (0, react_1.useEffect)(() => {
67
+ var _a;
68
+ (_a = textEditRef.current) === null || _a === void 0 ? void 0 : _a.setValue(p.searchText);
69
+ }, [p.searchText, textEditRef]);
70
+ return (react_1.default.createElement(Base, { "data-type": "search" },
71
+ react_1.default.createElement(TextEdit_1.TextEdit, { ref: textEditRef, placeholder: p.placeholderText, defaultEditing: { focus: true }, singleLine: true, leftContent: react_1.default.createElement(Icon, null,
72
+ react_1.default.createElement(icons_1.Magnify, null)), noGrow: true, allowUndo: false, onEscape: () => { var _a; return (_a = p.onClear) === null || _a === void 0 ? void 0 : _a.call(p); }, onClickOutsideWithNoValue: null, onSubmit: (v) => (0, helpers_1.debounce)(() => {
73
+ var _a;
74
+ p.setSearchText(v);
75
+ (_a = p.onSearchTextChange) === null || _a === void 0 ? void 0 : _a.call(p, v);
76
+ }, { key: 'pagesearch', time: 200 }), defaultValue: p.defaultValue }),
77
+ p.searchText && (react_1.default.createElement(CrossIconStyled, { onClick: () => {
78
+ var _a, _b;
79
+ (_a = textEditRef.current) === null || _a === void 0 ? void 0 : _a.setValue('');
80
+ p.setSearchText('');
81
+ (_b = p.onSearchTextChange) === null || _b === void 0 ? void 0 : _b.call(p, '');
82
+ } }))));
83
+ };
84
+ exports.SearchBox = SearchBox;
@@ -1,4 +1,6 @@
1
+ export * from './Base';
1
2
  export * from './Dialog';
2
3
  export * from './Inline';
3
4
  export * from './Modal';
5
+ export * from './SearchBox';
4
6
  export * from './types';
@@ -14,7 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Base"), exports);
17
18
  __exportStar(require("./Dialog"), exports);
18
19
  __exportStar(require("./Inline"), exports);
19
20
  __exportStar(require("./Modal"), exports);
21
+ __exportStar(require("./SearchBox"), exports);
20
22
  __exportStar(require("./types"), exports);
@@ -97,7 +97,12 @@ exports.TextEdit = (0, react_2.forwardRef)((p, ref) => {
97
97
  const [editing, setEditingRaw] = (0, react_2.useState)(!!defaultEditing);
98
98
  const valueChange = value !== defaultValue;
99
99
  (0, react_2.useImperativeHandle)(ref, () => ({
100
- setValue,
100
+ setValue: (v) => {
101
+ if (v === value) {
102
+ return;
103
+ }
104
+ setValue(v);
105
+ },
101
106
  }));
102
107
  (0, useOnClickOutside_1.useOnClickOutside)({
103
108
  disabled: onClickOutsideWithNoValue === null || disableEdit,
@@ -145,12 +150,16 @@ exports.TextEdit = (0, react_2.forwardRef)((p, ref) => {
145
150
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
146
151
  ref: ref, tabIndex: -1, "data-nogrow": noGrow }, (0, dom_1.filterDataProps)(p)),
147
152
  leftContent || null,
148
- react_2.default.createElement(Comp, { tabIndex: editing ? 0 : undefined, "data-editing": "true", "data-valuechange": valueChange.toString(), ref: taref, "data-type": "text", value: value, onChange: (v) => {
153
+ react_2.default.createElement(Comp, { tabIndex: editing ? 0 : undefined, "data-editing": "true", "data-valuechange": valueChange.toString(),
154
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
155
+ ref: taref, "data-type": "text", value: value, onChange: (v) => {
149
156
  setValue(v.currentTarget.value);
150
157
  if (!allowUndo) {
151
158
  onSubmit(v.currentTarget.value, false);
152
159
  }
153
- }, placeholder: placeholder, rows: singleLine ? 1 : undefined, maxLength: maxLength, onKeyDown: (e) => {
160
+ }, placeholder: placeholder, rows: singleLine ? 1 : undefined, maxLength: maxLength,
161
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
162
+ onKeyDown: (e) => {
154
163
  if ((onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e)) === false) {
155
164
  e.preventDefault();
156
165
  return;
@@ -0,0 +1,21 @@
1
+ import { FC } from 'react';
2
+ export interface ITimelineChartSeries {
3
+ data: {
4
+ x: number;
5
+ y: number;
6
+ }[];
7
+ /** shown on page */
8
+ label?: string;
9
+ key: string;
10
+ color: string;
11
+ /** optional onclick href */
12
+ onClick?: () => void;
13
+ /** hover text */
14
+ title?: string;
15
+ }
16
+ export interface ITimelineChart {
17
+ series: ITimelineChartSeries[];
18
+ strokeWidth?: number;
19
+ className?: string;
20
+ }
21
+ export declare const TimelineChart: FC<ITimelineChart>;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TimelineChart = void 0;
7
+ const styled_1 = __importDefault(require("@emotion/styled"));
8
+ const react_1 = __importDefault(require("react"));
9
+ const Base = styled_1.default.div `
10
+ display: flex;
11
+ flex-flow: column;
12
+ justify-content: center;
13
+ align-items: center;
14
+ width: 100%;
15
+ height: 100%;
16
+ svg {
17
+ overflow: initial;
18
+ }
19
+ `;
20
+ const TimelineChart = ({ series, strokeWidth = 3, className, }) => {
21
+ if (series.length === 0) {
22
+ return react_1.default.createElement(Base, null);
23
+ }
24
+ const width = 600;
25
+ const height = 200;
26
+ const xValues = series.flatMap((s) => s.data.map((d) => d.x));
27
+ const yValues = series.flatMap((s) => s.data.map((d) => d.y));
28
+ const xMin = Math.min(...xValues);
29
+ const xMax = Math.max(...xValues);
30
+ const yMin = Math.min(...yValues);
31
+ const yMax = Math.max(...yValues);
32
+ const xScale = (x) => { var _a; return (_a = Math.ceil(width * ((x - xMin) / (xMax - xMin)))) !== null && _a !== void 0 ? _a : 0; };
33
+ const yScale = (y) => {
34
+ let ret = Math.ceil(height * ((yMax - y) / (yMax - yMin)));
35
+ if (isNaN(ret)) {
36
+ ret = y;
37
+ }
38
+ return ret !== null && ret !== void 0 ? ret : y;
39
+ };
40
+ const getPathData = ({ data }) => {
41
+ const pd1 = data
42
+ .sort((a, b) => (a.x < b.x ? -1 : 1))
43
+ .map(({ x, y }) => {
44
+ const xScaled = xScale(x);
45
+ const yScaled = yScale(y);
46
+ return { xScaled, yScaled };
47
+ });
48
+ const pathData = pd1.map(({ xScaled, yScaled }, i) => i === 0 ? `M${xScaled} ${yScaled}` : ` L${xScaled} ${yScaled}`);
49
+ return pathData.join('\n');
50
+ };
51
+ return (react_1.default.createElement(Base, { className: className },
52
+ react_1.default.createElement("svg", { viewBox: `0 -10 ${width} ${height + 20}` }, series.map(({ color, data, label, key, onClick, title }) => {
53
+ var _a, _b, _c, _d;
54
+ return (react_1.default.createElement("g", { key: key },
55
+ react_1.default.createElement("title", null, title || label),
56
+ react_1.default.createElement("path", { d: getPathData({ color, data, label, key }), fill: "none", stroke: color, strokeWidth: strokeWidth, onClick: () => onClick === null || onClick === void 0 ? void 0 : onClick(), style: { cursor: onClick ? 'pointer' : 'default' } }),
57
+ label && (react_1.default.createElement(react_1.default.Fragment, null,
58
+ react_1.default.createElement("text", { x: xScale((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.x) + strokeWidth * 2, y: yScale((_b = data[data.length - 1]) === null || _b === void 0 ? void 0 : _b.y), fontSize: "12", textAnchor: "middle", dominantBaseline: "middle", stroke: "white", strokeWidth: '3px' }, label),
59
+ react_1.default.createElement("text", { x: xScale((_c = data === null || data === void 0 ? void 0 : data[0]) === null || _c === void 0 ? void 0 : _c.x) + strokeWidth * 2, y: yScale((_d = data[data.length - 1]) === null || _d === void 0 ? void 0 : _d.y), fontSize: "12", textAnchor: "middle", dominantBaseline: "middle", fill: "black" }, label)))));
60
+ }))));
61
+ };
62
+ exports.TimelineChart = TimelineChart;
@@ -11,10 +11,12 @@ export * from './HeadersRaw';
11
11
  export * from './HorizontalScrollBar';
12
12
  export * from './Icon';
13
13
  export * from './Image';
14
+ export * from './InfiniteScroll';
14
15
  export * from './KebabDots';
15
16
  export * from './Loader';
16
17
  export * from './Modal';
17
18
  export * from './OpenApiCodeBlock';
19
+ export * from './PieChart';
18
20
  export * from './ProgressBar';
19
21
  export * from './Prompt';
20
22
  export * from './RowOrColumn';
@@ -24,5 +26,6 @@ export * from './SparkLine';
24
26
  export * from './Table';
25
27
  export * from './TextEdit';
26
28
  export * from './TextWithButton';
29
+ export * from './TimelineChart';
27
30
  export * from './Toast';
28
31
  export * from './UserImage';
@@ -27,10 +27,12 @@ __exportStar(require("./HeadersRaw"), exports);
27
27
  __exportStar(require("./HorizontalScrollBar"), exports);
28
28
  __exportStar(require("./Icon"), exports);
29
29
  __exportStar(require("./Image"), exports);
30
+ __exportStar(require("./InfiniteScroll"), exports);
30
31
  __exportStar(require("./KebabDots"), exports);
31
32
  __exportStar(require("./Loader"), exports);
32
33
  __exportStar(require("./Modal"), exports);
33
34
  __exportStar(require("./OpenApiCodeBlock"), exports);
35
+ __exportStar(require("./PieChart"), exports);
34
36
  __exportStar(require("./ProgressBar"), exports);
35
37
  __exportStar(require("./Prompt"), exports);
36
38
  __exportStar(require("./RowOrColumn"), exports);
@@ -40,5 +42,6 @@ __exportStar(require("./SparkLine"), exports);
40
42
  __exportStar(require("./Table"), exports);
41
43
  __exportStar(require("./TextEdit"), exports);
42
44
  __exportStar(require("./TextWithButton"), exports);
45
+ __exportStar(require("./TimelineChart"), exports);
43
46
  __exportStar(require("./Toast"), exports);
44
47
  __exportStar(require("./UserImage"), exports);
@@ -1,2 +1,5 @@
1
1
  /// <reference types="react" />
2
- export declare const Magnify: JSX.Element;
2
+ export declare const Magnify: ({ colour, }: {
3
+ /** default "#000" */
4
+ colour?: string | undefined;
5
+ }) => JSX.Element;
@@ -5,5 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Magnify = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
- exports.Magnify = (react_1.default.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 490 490" },
9
- react_1.default.createElement("path", { fill: "none", stroke: "#000", strokeWidth: "36", strokeLinecap: "round", d: "M280 278a153 153 0 1 0-2 2l170 170m-91-117 110 110-26 26-110-110" })));
8
+ const Magnify = ({ colour = '#000', }) => (react_1.default.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 490 490" },
9
+ react_1.default.createElement("path", { fill: "none", stroke: colour, strokeWidth: "36", strokeLinecap: "round", d: "M280 278a153 153 0 1 0-2 2l170 170m-91-117 110 110-26 26-110-110" })));
10
+ exports.Magnify = Magnify;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.379",
3
+ "version": "0.0.381",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",