buckaroo-js-core 0.8.0
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.
- package/.prettierrc +16 -0
- package/CHANGELOG.md +23 -0
- package/LICENSE +15 -0
- package/README.md +66 -0
- package/buckaroo_js/baked_data/colorMap.d.ts +3 -0
- package/buckaroo_js/baked_data/colorMap.d.ts.map +1 -0
- package/buckaroo_js/baked_data/colorMap.js +520 -0
- package/buckaroo_js/baked_data/colorMap.js.map +1 -0
- package/buckaroo_js/baked_data/staticData.d.ts +124 -0
- package/buckaroo_js/baked_data/staticData.d.ts.map +1 -0
- package/buckaroo_js/baked_data/staticData.js +459 -0
- package/buckaroo_js/baked_data/staticData.js.map +1 -0
- package/buckaroo_js/components/ColumnsEditor.d.ts +19 -0
- package/buckaroo_js/components/ColumnsEditor.d.ts.map +1 -0
- package/buckaroo_js/components/ColumnsEditor.js +68 -0
- package/buckaroo_js/components/ColumnsEditor.js.map +1 -0
- package/buckaroo_js/components/CommandUtils.d.ts +22 -0
- package/buckaroo_js/components/CommandUtils.d.ts.map +1 -0
- package/buckaroo_js/components/CommandUtils.js +17 -0
- package/buckaroo_js/components/CommandUtils.js.map +1 -0
- package/buckaroo_js/components/DCFCell.d.ts +28 -0
- package/buckaroo_js/components/DCFCell.d.ts.map +1 -0
- package/buckaroo_js/components/DCFCell.js +120 -0
- package/buckaroo_js/components/DCFCell.js.map +1 -0
- package/buckaroo_js/components/DFViewerParts/DFViewer.d.ts +29 -0
- package/buckaroo_js/components/DFViewerParts/DFViewer.d.ts.map +1 -0
- package/buckaroo_js/components/DFViewerParts/DFViewer.js +163 -0
- package/buckaroo_js/components/DFViewerParts/DFViewer.js.map +1 -0
- package/buckaroo_js/components/DFViewerParts/DFWhole.d.ts +111 -0
- package/buckaroo_js/components/DFViewerParts/DFWhole.d.ts.map +1 -0
- package/buckaroo_js/components/DFViewerParts/DFWhole.js +17 -0
- package/buckaroo_js/components/DFViewerParts/DFWhole.js.map +1 -0
- package/buckaroo_js/components/DFViewerParts/Displayer.d.ts +19 -0
- package/buckaroo_js/components/DFViewerParts/Displayer.d.ts.map +1 -0
- package/buckaroo_js/components/DFViewerParts/Displayer.js +221 -0
- package/buckaroo_js/components/DFViewerParts/Displayer.js.map +1 -0
- package/buckaroo_js/components/DFViewerParts/HistogramCell.d.ts +20 -0
- package/buckaroo_js/components/DFViewerParts/HistogramCell.d.ts.map +1 -0
- package/buckaroo_js/components/DFViewerParts/HistogramCell.js +184 -0
- package/buckaroo_js/components/DFViewerParts/HistogramCell.js.map +1 -0
- package/buckaroo_js/components/DFViewerParts/SeriesSummaryTooltip.d.ts +5 -0
- package/buckaroo_js/components/DFViewerParts/SeriesSummaryTooltip.d.ts.map +1 -0
- package/buckaroo_js/components/DFViewerParts/SeriesSummaryTooltip.js +18 -0
- package/buckaroo_js/components/DFViewerParts/SeriesSummaryTooltip.js.map +1 -0
- package/buckaroo_js/components/DFViewerParts/gridUtils.d.ts +24 -0
- package/buckaroo_js/components/DFViewerParts/gridUtils.d.ts.map +1 -0
- package/buckaroo_js/components/DFViewerParts/gridUtils.js +230 -0
- package/buckaroo_js/components/DFViewerParts/gridUtils.js.map +1 -0
- package/buckaroo_js/components/DependentTabs.d.ts +33 -0
- package/buckaroo_js/components/DependentTabs.d.ts.map +1 -0
- package/buckaroo_js/components/DependentTabs.js +108 -0
- package/buckaroo_js/components/DependentTabs.js.map +1 -0
- package/buckaroo_js/components/OperationDetail.d.ts +16 -0
- package/buckaroo_js/components/OperationDetail.d.ts.map +1 -0
- package/buckaroo_js/components/OperationDetail.js +144 -0
- package/buckaroo_js/components/OperationDetail.js.map +1 -0
- package/buckaroo_js/components/OperationUtils.d.ts +17 -0
- package/buckaroo_js/components/OperationUtils.d.ts.map +1 -0
- package/buckaroo_js/components/OperationUtils.js +14 -0
- package/buckaroo_js/components/OperationUtils.js.map +1 -0
- package/buckaroo_js/components/Operations.d.ts +24 -0
- package/buckaroo_js/components/Operations.d.ts.map +1 -0
- package/buckaroo_js/components/Operations.js +209 -0
- package/buckaroo_js/components/Operations.js.map +1 -0
- package/buckaroo_js/components/StatusBar.d.ts +12 -0
- package/buckaroo_js/components/StatusBar.d.ts.map +1 -0
- package/buckaroo_js/components/StatusBar.js +155 -0
- package/buckaroo_js/components/StatusBar.js.map +1 -0
- package/buckaroo_js/components/WidgetTypes.d.ts +25 -0
- package/buckaroo_js/components/WidgetTypes.d.ts.map +1 -0
- package/buckaroo_js/components/WidgetTypes.js +3 -0
- package/buckaroo_js/components/WidgetTypes.js.map +1 -0
- package/buckaroo_js/components/bakedOperationDefaults.d.ts +5 -0
- package/buckaroo_js/components/bakedOperationDefaults.d.ts.map +1 -0
- package/buckaroo_js/components/bakedOperationDefaults.js +15 -0
- package/buckaroo_js/components/bakedOperationDefaults.js.map +1 -0
- package/buckaroo_js/components/utils.d.ts +294 -0
- package/buckaroo_js/components/utils.d.ts.map +1 -0
- package/buckaroo_js/components/utils.js +143 -0
- package/buckaroo_js/components/utils.js.map +1 -0
- package/buckaroo_js/extension.d.ts +2 -0
- package/buckaroo_js/extension.d.ts.map +1 -0
- package/buckaroo_js/extension.js +20 -0
- package/buckaroo_js/extension.js.map +1 -0
- package/buckaroo_js/index.d.ts +25 -0
- package/buckaroo_js/index.d.ts.map +1 -0
- package/buckaroo_js/index.js +46 -0
- package/buckaroo_js/index.js.map +1 -0
- package/buckaroo_js/vendor/RechartExtra.d.ts +38 -0
- package/buckaroo_js/vendor/RechartExtra.d.ts.map +1 -0
- package/buckaroo_js/vendor/RechartExtra.js +17 -0
- package/buckaroo_js/vendor/RechartExtra.js.map +1 -0
- package/buckaroo_js/vendor/RechartTooltip.d.ts +82 -0
- package/buckaroo_js/vendor/RechartTooltip.d.ts.map +1 -0
- package/buckaroo_js/vendor/RechartTooltip.js +232 -0
- package/buckaroo_js/vendor/RechartTooltip.js.map +1 -0
- package/codecov.yml +16 -0
- package/eslint.config.mjs +88 -0
- package/examples/App.tsx +160 -0
- package/examples/CodeBlock.tsx +27 -0
- package/examples/CodePenButton.tsx +77 -0
- package/examples/ReadmeBlock.tsx +11 -0
- package/examples/app.css +29 -0
- package/examples/ex/ColumnsEditorEx.tsx +5 -0
- package/examples/ex/CommandViewerEx.tsx +20 -0
- package/examples/ex/DFViewerEx.tsx +3 -0
- package/examples/ex/DFViewerEx_large.tsx +266 -0
- package/examples/ex/DFViewerEx_real_summary.tsx +20 -0
- package/examples/ex/DFViewerEx_short_data.tsx +22 -0
- package/examples/ex/DFViewerEx_string_index.tsx +1012 -0
- package/examples/ex/HistogramEx.tsx +67 -0
- package/examples/ex/StatusBarEx.tsx +46 -0
- package/examples/ex/WidgetDCFCellEx.tsx +6 -0
- package/examples/example.css +20 -0
- package/examples/index-iframe.hnottml +24 -0
- package/examples/index-react18.tsx +8 -0
- package/examples/index.html +20 -0
- package/examples/jsx-loader.ts +16 -0
- package/examples/tsconfig.json +31 -0
- package/index.d.ts +2 -0
- package/index.d.ts.map +1 -0
- package/index.js +7 -0
- package/index.js.map +1 -0
- package/jest.config.js +24 -0
- package/package.json +117 -0
- package/screen-animation.gif +0 -0
- package/src/buckaroo_js/baked_data/colorMap.ts +523 -0
- package/src/buckaroo_js/baked_data/staticData.ts +503 -0
- package/src/buckaroo_js/components/ColumnsEditor.tsx +66 -0
- package/src/buckaroo_js/components/CommandUtils.ts +40 -0
- package/src/buckaroo_js/components/DCFCell.tsx +175 -0
- package/src/buckaroo_js/components/DFViewerParts/DFViewer.tsx +215 -0
- package/src/buckaroo_js/components/DFViewerParts/DFWhole.ts +190 -0
- package/src/buckaroo_js/components/DFViewerParts/Displayer.ts +215 -0
- package/src/buckaroo_js/components/DFViewerParts/HistogramCell.tsx +251 -0
- package/src/buckaroo_js/components/DFViewerParts/SeriesSummaryTooltip.tsx +20 -0
- package/src/buckaroo_js/components/DFViewerParts/gridUtils.ts +290 -0
- package/src/buckaroo_js/components/DependentTabs.tsx +134 -0
- package/src/buckaroo_js/components/OperationDetail.tsx +203 -0
- package/src/buckaroo_js/components/OperationUtils.ts +33 -0
- package/src/buckaroo_js/components/Operations.tsx +243 -0
- package/src/buckaroo_js/components/StatusBar.tsx +190 -0
- package/src/buckaroo_js/components/WidgetTypes.tsx +42 -0
- package/src/buckaroo_js/components/bakedOperationDefaults.ts +14 -0
- package/src/buckaroo_js/components/utils.ts +60 -0
- package/src/buckaroo_js/extension.ts +15 -0
- package/src/buckaroo_js/index.ts +34 -0
- package/src/buckaroo_js/style/dcf-npm.css +244 -0
- package/src/buckaroo_js/style/icons/arrow-down-short-dark.svg +4 -0
- package/src/buckaroo_js/style/icons/arrow-down-short.svg +4 -0
- package/src/buckaroo_js/style/icons/arrow-up-short-dark.svg +4 -0
- package/src/buckaroo_js/style/icons/arrow-up-short.svg +4 -0
- package/src/buckaroo_js/style/icons/filter-dark.svg +3 -0
- package/src/buckaroo_js/style/icons/filter.svg +3 -0
- package/src/buckaroo_js/vendor/RechartExtra.ts +60 -0
- package/src/buckaroo_js/vendor/RechartTooltip.tsx +357 -0
- package/src/index.tsx +3 -0
- package/tsconfig.json +41 -0
- package/webpack.config.ts +97 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import {ValueFormatterFunc, ValueFormatterParams} from 'ag-grid-community';
|
|
2
|
+
import {
|
|
3
|
+
DisplayerArgs,
|
|
4
|
+
cellRendererDisplayers,
|
|
5
|
+
FloatDisplayerA,
|
|
6
|
+
IntegerDisplayerA,
|
|
7
|
+
DatetimeLocaleDisplayerA,
|
|
8
|
+
StringDisplayerA,
|
|
9
|
+
ObjDisplayerA
|
|
10
|
+
} from './DFWhole';
|
|
11
|
+
import _ from 'lodash';
|
|
12
|
+
import {Base64PNGDisplayer, HistogramCell, LinkCellRenderer, SVGDisplayer} from './HistogramCell';
|
|
13
|
+
import {CellRendererArgs, FormatterArgs} from './DFWhole';
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
this code should all be unit tested and in examples. Examples will
|
|
17
|
+
show potential developers how this behaves. Examples should be made
|
|
18
|
+
inside of AG-Grid, and independently.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export const basicIntFormatter = new Intl.NumberFormat('en-US', {
|
|
22
|
+
minimumFractionDigits: 0,
|
|
23
|
+
maximumFractionDigits: 3
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const getStringFormatter = (args: StringDisplayerA) => {
|
|
27
|
+
const stringFormatter = (params: ValueFormatterParams): string => {
|
|
28
|
+
const val = params.value;
|
|
29
|
+
if (val && args.max_length) {
|
|
30
|
+
return val.slice(0, args.max_length);
|
|
31
|
+
}
|
|
32
|
+
return val;
|
|
33
|
+
};
|
|
34
|
+
return stringFormatter;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const dictDisplayer = (val: Record<string, any>): string => {
|
|
38
|
+
const objBody = _.map(val, (value, key) => `'${key}': ${objDisplayer(value)}`).join(',');
|
|
39
|
+
return `{ ${objBody} }`;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const isValidDate = (possibleDate: any): boolean => {
|
|
43
|
+
if (_.isDate(possibleDate) && isFinite(possibleDate.getTime())) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
const DEFAULT_DATE_FORMAT: Intl.DateTimeFormatOptions = {
|
|
49
|
+
year: 'numeric',
|
|
50
|
+
month: 'numeric',
|
|
51
|
+
day: 'numeric',
|
|
52
|
+
hour: 'numeric',
|
|
53
|
+
minute: 'numeric',
|
|
54
|
+
second: 'numeric',
|
|
55
|
+
hour12: false
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const dateDisplayerDefault = (d: Date): string => {
|
|
59
|
+
const fullStr = d.toLocaleDateString('en-CA', DEFAULT_DATE_FORMAT);
|
|
60
|
+
const [dateStr, timeStr] = fullStr.split(',');
|
|
61
|
+
const retVal = `${dateStr} ${timeStr}`;
|
|
62
|
+
return retVal;
|
|
63
|
+
};
|
|
64
|
+
const objDisplayer = (val: any | any[]): string => {
|
|
65
|
+
if (val === undefined || val === null) {
|
|
66
|
+
return 'None';
|
|
67
|
+
} else if (_.isArray(val)) {
|
|
68
|
+
return `[ ${val.map(objDisplayer).join(', ')}]`;
|
|
69
|
+
} else if (_.isBoolean(val)) {
|
|
70
|
+
return boolDisplayer(val);
|
|
71
|
+
} else if (_.isObject(val)) {
|
|
72
|
+
return dictDisplayer(val);
|
|
73
|
+
} else {
|
|
74
|
+
return val.toString();
|
|
75
|
+
}
|
|
76
|
+
return val;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const getObjectFormatter = (fArgs: ObjDisplayerA) => {
|
|
80
|
+
const objFormatter = (params: ValueFormatterParams): string => {
|
|
81
|
+
const val = params.value;
|
|
82
|
+
const fullString = objDisplayer(val);
|
|
83
|
+
if (fArgs.max_length) {
|
|
84
|
+
return fullString.slice(0, fArgs.max_length);
|
|
85
|
+
} else {
|
|
86
|
+
return fullString;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
return objFormatter;
|
|
90
|
+
};
|
|
91
|
+
export const objFormatter = getObjectFormatter({displayer: 'obj'});
|
|
92
|
+
|
|
93
|
+
export const boolDisplayer = (val: boolean) => {
|
|
94
|
+
if (val === true) {
|
|
95
|
+
return 'True';
|
|
96
|
+
} else if (val === false) {
|
|
97
|
+
return 'False';
|
|
98
|
+
}
|
|
99
|
+
return '';
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export const booleanFormatter = (params: ValueFormatterParams): string => {
|
|
103
|
+
const val = params.value;
|
|
104
|
+
return boolDisplayer(val);
|
|
105
|
+
};
|
|
106
|
+
const getIntegerFormatter = (hint: IntegerDisplayerA) => {
|
|
107
|
+
const commas = Math.floor(hint.max_digits / 3);
|
|
108
|
+
const totalWidth = commas + hint.max_digits;
|
|
109
|
+
|
|
110
|
+
const formatter = new Intl.NumberFormat('en-US');
|
|
111
|
+
const numericFormatter = (params: ValueFormatterParams): string => {
|
|
112
|
+
const val = params.value;
|
|
113
|
+
if (val === null) {
|
|
114
|
+
return '';
|
|
115
|
+
}
|
|
116
|
+
return formatter.format(params.value).padStart(totalWidth, ' ');
|
|
117
|
+
};
|
|
118
|
+
return numericFormatter;
|
|
119
|
+
};
|
|
120
|
+
export const getFloatFormatter = (hint: FloatDisplayerA) => {
|
|
121
|
+
const floatFormatter = new Intl.NumberFormat('en-US', {
|
|
122
|
+
minimumFractionDigits: hint.min_fraction_digits,
|
|
123
|
+
maximumFractionDigits: hint.max_fraction_digits
|
|
124
|
+
});
|
|
125
|
+
return (params: ValueFormatterParams): string => {
|
|
126
|
+
if (params.value === null) {
|
|
127
|
+
return '';
|
|
128
|
+
}
|
|
129
|
+
const res: string = floatFormatter.format(params.value);
|
|
130
|
+
if (!_.includes(res, '.')) {
|
|
131
|
+
const padLength = res.length + hint.max_fraction_digits + 1;
|
|
132
|
+
return res.padEnd(padLength);
|
|
133
|
+
} else {
|
|
134
|
+
const fracPart = res.split('.')[1];
|
|
135
|
+
const padLength = hint.max_fraction_digits - fracPart.length + res.length;
|
|
136
|
+
return res.padEnd(padLength);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export const getDatetimeFormatter = (colHint: DatetimeLocaleDisplayerA) => {
|
|
142
|
+
return (params: ValueFormatterParams): string => {
|
|
143
|
+
const val = params.value;
|
|
144
|
+
if (val === null || val === undefined) {
|
|
145
|
+
return '';
|
|
146
|
+
}
|
|
147
|
+
const d = new Date(val);
|
|
148
|
+
if (!isValidDate(d)) {
|
|
149
|
+
return '';
|
|
150
|
+
}
|
|
151
|
+
return d.toLocaleDateString(colHint.locale, colHint.args);
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export const defaultDatetimeFormatter = (params: ValueFormatterParams): string => {
|
|
156
|
+
const val = params.value;
|
|
157
|
+
if (val === null || val === undefined) {
|
|
158
|
+
return '';
|
|
159
|
+
}
|
|
160
|
+
const d = new Date(val);
|
|
161
|
+
if (!isValidDate(d)) {
|
|
162
|
+
return '';
|
|
163
|
+
}
|
|
164
|
+
return dateDisplayerDefault(d);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export function getFormatter(fArgs: FormatterArgs): ValueFormatterFunc<unknown> {
|
|
168
|
+
switch (fArgs.displayer) {
|
|
169
|
+
case 'integer':
|
|
170
|
+
return getIntegerFormatter(fArgs);
|
|
171
|
+
case 'string':
|
|
172
|
+
return getStringFormatter(fArgs);
|
|
173
|
+
case 'datetimeDefault':
|
|
174
|
+
return defaultDatetimeFormatter;
|
|
175
|
+
case 'datetimeLocaleString':
|
|
176
|
+
return getDatetimeFormatter(fArgs);
|
|
177
|
+
case 'float':
|
|
178
|
+
return getFloatFormatter(fArgs);
|
|
179
|
+
case 'boolean':
|
|
180
|
+
return booleanFormatter;
|
|
181
|
+
case 'obj':
|
|
182
|
+
return getObjectFormatter(fArgs);
|
|
183
|
+
default:
|
|
184
|
+
return getStringFormatter({displayer: 'string'});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/*
|
|
189
|
+
{
|
|
190
|
+
cellRenderer: 'agCheckboxCellRenderer',
|
|
191
|
+
cellRendererParams: { disabled: true}
|
|
192
|
+
}
|
|
193
|
+
*/
|
|
194
|
+
export function getCellRenderer(crArgs: CellRendererArgs) {
|
|
195
|
+
switch (crArgs.displayer) {
|
|
196
|
+
case 'histogram':
|
|
197
|
+
return HistogramCell;
|
|
198
|
+
case 'linkify':
|
|
199
|
+
return LinkCellRenderer;
|
|
200
|
+
case 'Base64PNGImageDisplayer':
|
|
201
|
+
return Base64PNGDisplayer;
|
|
202
|
+
case 'boolean_checkbox':
|
|
203
|
+
return 'agCheckboxCellRenderer';
|
|
204
|
+
case 'SVGDisplayer':
|
|
205
|
+
return SVGDisplayer;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function getFormatterFromArgs(dispArgs: DisplayerArgs) {
|
|
210
|
+
if (_.includes(cellRendererDisplayers, dispArgs.displayer)) {
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
213
|
+
const fArgs = dispArgs as FormatterArgs;
|
|
214
|
+
return getFormatter(fArgs);
|
|
215
|
+
}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import {createPortal} from 'react-dom';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
BarChart,
|
|
7
|
+
Bar
|
|
8
|
+
//Tooltip,
|
|
9
|
+
//Legend,
|
|
10
|
+
//Cell, XAxis, YAxis, CartesianGrid, , ResponsiveContainer,
|
|
11
|
+
} from 'recharts';
|
|
12
|
+
import {Tooltip} from '../../vendor/RechartTooltip';
|
|
13
|
+
|
|
14
|
+
import {isNumOrStr, ValueType} from '../../vendor/RechartExtra';
|
|
15
|
+
import {ValueFormatterFunc} from 'ag-grid-community';
|
|
16
|
+
|
|
17
|
+
function defaultFormatter<TValue extends ValueType>(value: TValue) {
|
|
18
|
+
return _.isArray(value) && isNumOrStr(value[0]) && isNumOrStr(value[1])
|
|
19
|
+
? // ? (value.join(' ~ ') as TValue)
|
|
20
|
+
('{value[0]} ~ {value[1]}' as TValue)
|
|
21
|
+
: value;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const bakedData = [
|
|
25
|
+
{
|
|
26
|
+
name: 'Page A',
|
|
27
|
+
population: 4000
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'Page B',
|
|
31
|
+
population: 3000
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'Page C',
|
|
35
|
+
population: 2000
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'Page D',
|
|
39
|
+
population: 2780
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'Page E',
|
|
43
|
+
population: 1890
|
|
44
|
+
}
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
export interface HistogramNode {
|
|
48
|
+
name: string;
|
|
49
|
+
population: number;
|
|
50
|
+
}
|
|
51
|
+
export const makeData = (histogram: number[]) => {
|
|
52
|
+
const accum: HistogramNode[] = [];
|
|
53
|
+
for (let i = 0; i < histogram.length; i++) {
|
|
54
|
+
accum.push({
|
|
55
|
+
name: `${i + 1}/${histogram.length}`,
|
|
56
|
+
population: histogram[i]
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
//console.log('accum', accum)
|
|
60
|
+
return accum;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const formatter = (value: any, name: any, props: any) => {
|
|
64
|
+
if (props.payload.name === 'longtail') {
|
|
65
|
+
return [value, name];
|
|
66
|
+
} else {
|
|
67
|
+
return [value, props.payload.name];
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export function FloatingTooltip({items, x, y}: any) {
|
|
72
|
+
const offset = 30;
|
|
73
|
+
const renderedItems = items.map((name: [string, number], value: number | string) => {
|
|
74
|
+
const [realName, realValue] = name;
|
|
75
|
+
const formattedVal = realValue === 0 ? '<1' : realValue;
|
|
76
|
+
return (
|
|
77
|
+
<React.Fragment>
|
|
78
|
+
<dt>{realName}</dt>
|
|
79
|
+
<dd>{formattedVal}%</dd>
|
|
80
|
+
</React.Fragment>
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
return createPortal(
|
|
84
|
+
<div
|
|
85
|
+
className='floating-tooltip'
|
|
86
|
+
style={{position: 'absolute', top: y + offset, left: x + offset}}
|
|
87
|
+
>
|
|
88
|
+
<dl>{renderedItems}</dl>
|
|
89
|
+
</div>,
|
|
90
|
+
document.body
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const ToolTipAdapter = (args: any) => {
|
|
95
|
+
const {active, formatter, payload} = args;
|
|
96
|
+
if (active && payload && payload.length) {
|
|
97
|
+
const renderContent2 = () => {
|
|
98
|
+
//const items = (itemSorter ? _.sortBy(payload, itemSorter) : payload).map((entry, i) => {
|
|
99
|
+
const items = payload.map((entry: any, i: number) => {
|
|
100
|
+
if (entry.type === 'none') {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const finalFormatter = entry.formatter || formatter || defaultFormatter;
|
|
105
|
+
const {value, name} = entry;
|
|
106
|
+
let finalValue: React.ReactNode = value;
|
|
107
|
+
let finalName: React.ReactNode = name;
|
|
108
|
+
if (finalFormatter && finalValue !== null && finalName !== null) {
|
|
109
|
+
const formatted = finalFormatter(value, name, entry, i, payload);
|
|
110
|
+
if (Array.isArray(formatted)) {
|
|
111
|
+
[finalValue, finalName] = formatted;
|
|
112
|
+
} else {
|
|
113
|
+
finalValue = formatted;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return [finalName, finalValue];
|
|
118
|
+
});
|
|
119
|
+
return items;
|
|
120
|
+
};
|
|
121
|
+
return (
|
|
122
|
+
<div className='custom-tooltip'>
|
|
123
|
+
<FloatingTooltip items={renderContent2()} x={args.box.x} y={args.box.y} />
|
|
124
|
+
</div>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return null;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const getTextCellRenderer = (formatter: ValueFormatterFunc<any>) => {
|
|
132
|
+
const TextCellRenderer = (props: any) => {
|
|
133
|
+
return <span>{formatter(props)}</span>;
|
|
134
|
+
};
|
|
135
|
+
return TextCellRenderer;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export const LinkCellRenderer = (props: any) => {
|
|
139
|
+
return <a href={props.value}>{props.value}</a>;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export const Base64PNGDisplayer = (props: any) => {
|
|
143
|
+
const imgString = 'data:image/png;base64,' + props.value;
|
|
144
|
+
return <img src={imgString}></img>;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export const SVGDisplayer = (props: any) => {
|
|
148
|
+
const markup = {__html: props.value};
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<div //style={{border:'1px solid red', borderBottom:'1px solid green'}}
|
|
152
|
+
dangerouslySetInnerHTML={markup}
|
|
153
|
+
></div>
|
|
154
|
+
);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export const HistogramCell = (props: any) => {
|
|
158
|
+
//debugger;
|
|
159
|
+
if (props === undefined || props.value === undefined) {
|
|
160
|
+
return <span></span>;
|
|
161
|
+
}
|
|
162
|
+
const histogram = props.value;
|
|
163
|
+
//for key "index", the value is "histogram"
|
|
164
|
+
// this causes ReChart to blow up, so we check to see if it's an array
|
|
165
|
+
if (histogram === undefined || !_.isArray(histogram)) {
|
|
166
|
+
return <span></span>;
|
|
167
|
+
}
|
|
168
|
+
const dumbClickHandler = (rechartsArgs: any, _unused_react: any) => {
|
|
169
|
+
// I can't find the type for rechartsArgs
|
|
170
|
+
// these are probably the keys we care about
|
|
171
|
+
// activeTooltipIndex
|
|
172
|
+
// activeLabel
|
|
173
|
+
console.log('dumbClickHandler', rechartsArgs);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<div className='histogram-component'>
|
|
178
|
+
<BarChart
|
|
179
|
+
width={100}
|
|
180
|
+
height={24}
|
|
181
|
+
barGap={1}
|
|
182
|
+
data={histogram}
|
|
183
|
+
onClick={dumbClickHandler}
|
|
184
|
+
>
|
|
185
|
+
<defs>
|
|
186
|
+
<pattern id='star' width='10' height='10' patternUnits='userSpaceOnUse'>
|
|
187
|
+
<polygon stroke='pink' points='0,0 2,5 0,10 5,8 10,10 8,5 10,0 5,2' />
|
|
188
|
+
</pattern>
|
|
189
|
+
<pattern
|
|
190
|
+
id='stripe'
|
|
191
|
+
width='4'
|
|
192
|
+
height='4'
|
|
193
|
+
patternUnits='userSpaceOnUse'
|
|
194
|
+
patternTransform='rotate(45)'
|
|
195
|
+
>
|
|
196
|
+
<rect width='2' height='4' fill='red' />
|
|
197
|
+
</pattern>
|
|
198
|
+
<pattern id='circles' width='4' height='4' patternUnits='userSpaceOnUse'>
|
|
199
|
+
<circle data-color='outline' stroke='pink' cx='.5' cy='.5' r='1.5'></circle>
|
|
200
|
+
</pattern>
|
|
201
|
+
|
|
202
|
+
<pattern
|
|
203
|
+
id='checkers'
|
|
204
|
+
x='0'
|
|
205
|
+
y='0'
|
|
206
|
+
width='4'
|
|
207
|
+
height='4'
|
|
208
|
+
patternUnits='userSpaceOnUse'
|
|
209
|
+
>
|
|
210
|
+
<rect stroke='#0f0' x='0' width='2' height='2' y='0'></rect>
|
|
211
|
+
<rect x='2' width='2' height='2' y='2'></rect>
|
|
212
|
+
</pattern>
|
|
213
|
+
|
|
214
|
+
<pattern
|
|
215
|
+
id='leafs'
|
|
216
|
+
x='0'
|
|
217
|
+
y='0'
|
|
218
|
+
width='6'
|
|
219
|
+
height='6'
|
|
220
|
+
patternUnits='userSpaceOnUse'
|
|
221
|
+
patternTransform='translate(1, 1) rotate(0) skewX(0)'
|
|
222
|
+
>
|
|
223
|
+
<svg width='5' height='5' viewBox='0 0 100 100'>
|
|
224
|
+
<g fill='teal' opacity='1'>
|
|
225
|
+
<path d='M99.9557 99.9557C45.4895 98.3748 1.6248 54.5101 0.0439453 0.0439453C54.5101 1.6248 98.3748 45.4895 99.9557 99.9557Z'></path>
|
|
226
|
+
</g>
|
|
227
|
+
</svg>
|
|
228
|
+
</pattern>
|
|
229
|
+
</defs>
|
|
230
|
+
<Bar dataKey='population' stroke='#000' fill='gray' stackId='stack' />
|
|
231
|
+
<Bar dataKey='tail' stroke='#000' fill='gray' stackId='stack' />
|
|
232
|
+
<Bar dataKey='true' stroke='#00f' fill='#00f' stackId='stack' />
|
|
233
|
+
<Bar dataKey='false' stroke='#000' fill='#fff' stackId='stack' />
|
|
234
|
+
<Bar dataKey='cat_pop' stroke='pink' fill='url(#circles)' stackId='stack' />
|
|
235
|
+
<Bar dataKey='unique' stroke='#0f0' fill='url(#checkers)' stackId='stack' />
|
|
236
|
+
<Bar dataKey='longtail' stroke='teal' fill='url(#leafs)' stackId='stack' />
|
|
237
|
+
<Bar dataKey='NA' fill='url(#stripe)' stackId='stack' />
|
|
238
|
+
|
|
239
|
+
<Tooltip
|
|
240
|
+
formatter={formatter}
|
|
241
|
+
labelStyle={{display: 'None'}}
|
|
242
|
+
wrapperStyle={{zIndex: 999991}}
|
|
243
|
+
contentStyle={{color: 'black'}}
|
|
244
|
+
content={<ToolTipAdapter />}
|
|
245
|
+
offset={20}
|
|
246
|
+
allowEscapeViewBox={{x: true}}
|
|
247
|
+
/>
|
|
248
|
+
</BarChart>
|
|
249
|
+
</div>
|
|
250
|
+
);
|
|
251
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {DFViewer} from './DFViewer';
|
|
3
|
+
import {DFWhole} from './DFWhole';
|
|
4
|
+
import {ITooltipParams} from 'ag-grid-community';
|
|
5
|
+
|
|
6
|
+
export function getBakedDFViewer(seriesDf: DFWhole) {
|
|
7
|
+
const retFunc = (props: ITooltipParams) => {
|
|
8
|
+
return (
|
|
9
|
+
<div>
|
|
10
|
+
<h1> series_summary </h1>
|
|
11
|
+
<DFViewer
|
|
12
|
+
df_data={seriesDf.data}
|
|
13
|
+
df_viewer_config={seriesDf.dfviewer_config}
|
|
14
|
+
summary_stats_data={[]}
|
|
15
|
+
></DFViewer>
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
return retFunc;
|
|
20
|
+
}
|