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,243 @@
|
|
|
1
|
+
import React, {useState} from 'react';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import {Operation, SetOperationsFunc, OperationEventFunc, NoArgEventFunc} from './OperationUtils';
|
|
4
|
+
import {CommandConfigT} from './CommandUtils';
|
|
5
|
+
import {replaceInArr} from './utils';
|
|
6
|
+
|
|
7
|
+
import {OperationDetail} from './OperationDetail';
|
|
8
|
+
import {AgGridReact} from 'ag-grid-react'; // the AG Grid React Component
|
|
9
|
+
import {ColDef, GridOptions} from 'ag-grid-community';
|
|
10
|
+
//import { CustomCellRendererProps } from '@ag-grid-community/react';
|
|
11
|
+
|
|
12
|
+
import {updateAtMatch} from './utils';
|
|
13
|
+
import 'ag-grid-community/styles/ag-grid.css';
|
|
14
|
+
import 'ag-grid-community/styles/ag-theme-alpine.css';
|
|
15
|
+
|
|
16
|
+
export const OperationsList = ({
|
|
17
|
+
operations,
|
|
18
|
+
activeKey,
|
|
19
|
+
setActiveKey,
|
|
20
|
+
delKey
|
|
21
|
+
}: {
|
|
22
|
+
operations: Operation[];
|
|
23
|
+
activeKey?: string;
|
|
24
|
+
setActiveKey: React.Dispatch<React.SetStateAction<string>>;
|
|
25
|
+
delKey: any;
|
|
26
|
+
}) => {
|
|
27
|
+
const renderOperation = (params: any) => (
|
|
28
|
+
<span className='missionSpan'>
|
|
29
|
+
<span
|
|
30
|
+
style={{
|
|
31
|
+
height: 30,
|
|
32
|
+
width: 30,
|
|
33
|
+
margin: 3,
|
|
34
|
+
paddingBottom: 8,
|
|
35
|
+
float: 'left',
|
|
36
|
+
background: 'grey'
|
|
37
|
+
}}
|
|
38
|
+
onClick={delKey(params.value[0])}
|
|
39
|
+
>
|
|
40
|
+
X
|
|
41
|
+
</span>
|
|
42
|
+
<span>{params.value[1]}</span>
|
|
43
|
+
</span>
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const getColumns = (passedOperations: Operation[]): ColDef[] =>
|
|
47
|
+
_.map(Array.from(passedOperations.entries()), ([index, element]) => {
|
|
48
|
+
const name = element[0]['symbol'];
|
|
49
|
+
const key = name + index.toString();
|
|
50
|
+
const column = {
|
|
51
|
+
field: key,
|
|
52
|
+
headerName: name,
|
|
53
|
+
cellRenderer: renderOperation
|
|
54
|
+
}; // width: 20, maxWidth: 60};
|
|
55
|
+
return column;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const rowElements: Record<string, [string, string]>[] = _.map(
|
|
59
|
+
Array.from(operations.entries()),
|
|
60
|
+
([index, element]) => {
|
|
61
|
+
const name = element[0]['symbol'];
|
|
62
|
+
const key = name + index.toString();
|
|
63
|
+
const rowEl: Record<string, [string, string]> = {};
|
|
64
|
+
rowEl[key] = [key, element[2]]; //key, colName
|
|
65
|
+
return rowEl;
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
const rows = [_.merge({}, ...rowElements)];
|
|
69
|
+
const columns = getColumns(operations);
|
|
70
|
+
|
|
71
|
+
const styledColumns = updateAtMatch(
|
|
72
|
+
_.clone(columns),
|
|
73
|
+
activeKey || '___never',
|
|
74
|
+
{
|
|
75
|
+
cellStyle: {background: 'var(--ag-range-selection-background-color-3)'}
|
|
76
|
+
},
|
|
77
|
+
{cellStyle: {}}
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const gridOptions: GridOptions = {
|
|
81
|
+
rowSelection: 'single',
|
|
82
|
+
headerHeight: 30,
|
|
83
|
+
onCellClicked: (event) => {
|
|
84
|
+
const colName = event.column.getColId();
|
|
85
|
+
setActiveKey(colName);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
return (
|
|
89
|
+
<div style={{height: 78, width: 1000}} className='ag-theme-alpine'>
|
|
90
|
+
<AgGridReact
|
|
91
|
+
gridOptions={gridOptions}
|
|
92
|
+
rowData={rows}
|
|
93
|
+
columnDefs={styledColumns}
|
|
94
|
+
></AgGridReact>
|
|
95
|
+
</div>
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const OperationAdder = ({
|
|
100
|
+
column,
|
|
101
|
+
addOperationCb,
|
|
102
|
+
defaultArgs
|
|
103
|
+
}: {
|
|
104
|
+
column: string;
|
|
105
|
+
addOperationCb: any;
|
|
106
|
+
defaultArgs: any;
|
|
107
|
+
}): JSX.Element => {
|
|
108
|
+
const addOperationByName = (localOperationName: string) => {
|
|
109
|
+
return () => {
|
|
110
|
+
const defaultOperation = defaultArgs[localOperationName];
|
|
111
|
+
addOperationCb(replaceInArr(defaultOperation, 'col', column));
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<div className='operation-adder'>
|
|
117
|
+
<span className={'column-name'}> Column: {column}</span>
|
|
118
|
+
<fieldset>
|
|
119
|
+
{_.keys(defaultArgs).map((optionVal) => (
|
|
120
|
+
<button key={optionVal} onClick={addOperationByName(optionVal)}>
|
|
121
|
+
{' '}
|
|
122
|
+
{optionVal}{' '}
|
|
123
|
+
</button>
|
|
124
|
+
))}
|
|
125
|
+
</fieldset>
|
|
126
|
+
</div>
|
|
127
|
+
);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export const OperationViewer = ({
|
|
131
|
+
operations,
|
|
132
|
+
setOperations,
|
|
133
|
+
activeColumn,
|
|
134
|
+
allColumns,
|
|
135
|
+
commandConfig
|
|
136
|
+
}: {
|
|
137
|
+
operations: Operation[];
|
|
138
|
+
setOperations: SetOperationsFunc;
|
|
139
|
+
activeColumn: string;
|
|
140
|
+
allColumns: string[];
|
|
141
|
+
commandConfig: CommandConfigT;
|
|
142
|
+
}) => {
|
|
143
|
+
const opToKey = (idx: number, op: Operation): string => {
|
|
144
|
+
const name = op[0]['symbol'];
|
|
145
|
+
return name + idx.toString();
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const operationObjs = _.map(Array.from(operations.entries()), ([index, element]) => {
|
|
149
|
+
const rowEl: Record<string, Operation> = {};
|
|
150
|
+
rowEl[opToKey(index, element)] = element;
|
|
151
|
+
return rowEl;
|
|
152
|
+
});
|
|
153
|
+
//why am I doing this? probably something so I gauruntee a clean dict
|
|
154
|
+
|
|
155
|
+
const operationDict = _.merge({}, ...operationObjs);
|
|
156
|
+
|
|
157
|
+
const idxObjs = _.map(Array.from(operations.entries()), ([index, element]) => {
|
|
158
|
+
const rowEl: Record<string, number> = {};
|
|
159
|
+
rowEl[opToKey(index, element)] = index;
|
|
160
|
+
return rowEl;
|
|
161
|
+
});
|
|
162
|
+
const keyToIdx = _.merge({}, ...idxObjs);
|
|
163
|
+
|
|
164
|
+
// previously was null
|
|
165
|
+
const [activeKey, setActiveKey] = useState('');
|
|
166
|
+
|
|
167
|
+
function getSetOperation(key: string): OperationEventFunc {
|
|
168
|
+
return (newOperation: Operation) => {
|
|
169
|
+
const index = keyToIdx[key];
|
|
170
|
+
const nextOperations = operations.map((c, i) => {
|
|
171
|
+
if (i === index) {
|
|
172
|
+
return newOperation;
|
|
173
|
+
} else {
|
|
174
|
+
return c;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
console.log('about to call setOperations', key, newOperation);
|
|
178
|
+
setOperations(nextOperations);
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function getDeleteOperation(key: string): NoArgEventFunc {
|
|
183
|
+
return (): void => {
|
|
184
|
+
const index = keyToIdx[key];
|
|
185
|
+
const nextOperations = operations.map((c, i) => {
|
|
186
|
+
if (i === index) {
|
|
187
|
+
return undefined;
|
|
188
|
+
} else {
|
|
189
|
+
return c;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
//const newIdx = Math.max(0, index - 1);
|
|
193
|
+
const newOps = _.filter(nextOperations) as Operation[];
|
|
194
|
+
console.log('getDeleteOperations', operations.length, newOps.length);
|
|
195
|
+
setOperations(newOps);
|
|
196
|
+
//setActiveKey(opToKey(newIdx, newOps[newIdx]));
|
|
197
|
+
//setActiveKey('');
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const getColumns = (passedOperations: Operation[]): ColDef[] =>
|
|
202
|
+
_.map(Array.from(passedOperations.entries()), ([index, element]) => {
|
|
203
|
+
const name = element[0]['symbol'];
|
|
204
|
+
const key = name + index.toString();
|
|
205
|
+
const column = {field: key, headerName: name}; // width: 20, maxWidth: 60};
|
|
206
|
+
return column;
|
|
207
|
+
});
|
|
208
|
+
const addOperation: OperationEventFunc = (newOperation: Operation) => {
|
|
209
|
+
const newOperationArr = [...operations, newOperation];
|
|
210
|
+
setOperations(newOperationArr);
|
|
211
|
+
const newOperationKey = getColumns(newOperationArr)[newOperationArr.length - 1].field;
|
|
212
|
+
if (newOperationKey !== undefined) {
|
|
213
|
+
setActiveKey(newOperationKey);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
const {argspecs, defaultArgs} = commandConfig;
|
|
217
|
+
return (
|
|
218
|
+
<div className='command-viewer'>
|
|
219
|
+
<OperationAdder
|
|
220
|
+
column={activeColumn}
|
|
221
|
+
addOperationCb={addOperation}
|
|
222
|
+
defaultArgs={defaultArgs}
|
|
223
|
+
/>
|
|
224
|
+
<div className='operations-box'>
|
|
225
|
+
<h4> Operations </h4>
|
|
226
|
+
<OperationsList
|
|
227
|
+
operations={operations}
|
|
228
|
+
activeKey={activeKey}
|
|
229
|
+
setActiveKey={setActiveKey}
|
|
230
|
+
delKey={getDeleteOperation}
|
|
231
|
+
/>
|
|
232
|
+
</div>
|
|
233
|
+
{activeKey && (
|
|
234
|
+
<OperationDetail
|
|
235
|
+
command={operationDict[activeKey]}
|
|
236
|
+
setCommand={getSetOperation(activeKey)}
|
|
237
|
+
columns={allColumns}
|
|
238
|
+
commandPatterns={argspecs}
|
|
239
|
+
/>
|
|
240
|
+
)}
|
|
241
|
+
</div>
|
|
242
|
+
);
|
|
243
|
+
};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// https://plnkr.co/edit/QTNwBb2VEn81lf4t?open=index.tsx
|
|
2
|
+
import React, {useRef, useCallback} from 'react';
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
import {AgGridReact} from 'ag-grid-react'; // the AG Grid React Component
|
|
5
|
+
import {ColDef, GridOptions} from 'ag-grid-community';
|
|
6
|
+
import {basicIntFormatter} from './DFViewerParts/Displayer';
|
|
7
|
+
import {DFMeta} from './WidgetTypes';
|
|
8
|
+
import {BuckarooOptions} from './WidgetTypes';
|
|
9
|
+
import {BuckarooState, BKeys} from './WidgetTypes';
|
|
10
|
+
export type setColumFunc = (newCol: string) => void;
|
|
11
|
+
|
|
12
|
+
const helpCell = function (params: any) {
|
|
13
|
+
return (
|
|
14
|
+
<a
|
|
15
|
+
href='https://buckaroo-data.readthedocs.io/en/latest/feature_reference.html'
|
|
16
|
+
target='_blank'
|
|
17
|
+
rel='noopener noreferrer'
|
|
18
|
+
>
|
|
19
|
+
?
|
|
20
|
+
</a>
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function StatusBar({
|
|
25
|
+
dfMeta,
|
|
26
|
+
buckarooState,
|
|
27
|
+
setBuckarooState,
|
|
28
|
+
buckarooOptions
|
|
29
|
+
}: {
|
|
30
|
+
dfMeta: DFMeta;
|
|
31
|
+
buckarooState: BuckarooState;
|
|
32
|
+
setBuckarooState: React.Dispatch<React.SetStateAction<BuckarooState>>;
|
|
33
|
+
buckarooOptions: BuckarooOptions;
|
|
34
|
+
}) {
|
|
35
|
+
/*
|
|
36
|
+
AgGridReact
|
|
37
|
+
rowData={rowData}
|
|
38
|
+
columnDefs={columns}
|
|
39
|
+
singleClickEdit={true}
|
|
40
|
+
stopEditingWhenCellsLoseFocus={true}
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
//console.log('initial buckarooState', buckarooState);
|
|
44
|
+
// const optionCycles = _.fromPairs(
|
|
45
|
+
// // _.map(buckarooOptions, (v: any, k) => [k, ( k==='df_display' ? v : _.concat([false], v) ) ])
|
|
46
|
+
// _.map(buckarooOptions, (v: any, k) => [k, ( k==='post_processing' ? v : _.concat([false], v) ) ])
|
|
47
|
+
|
|
48
|
+
// ) as Record<BKeys, any[]>;
|
|
49
|
+
const optionCycles = buckarooOptions;
|
|
50
|
+
const idxs = _.fromPairs(
|
|
51
|
+
_.map(_.keys(optionCycles), (k) => [
|
|
52
|
+
k,
|
|
53
|
+
_.indexOf(optionCycles[k as BKeys], buckarooState[k as BKeys])
|
|
54
|
+
])
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const nextIndex = (curIdx: number, arr: any[]) => {
|
|
58
|
+
if (curIdx === arr.length - 1) {
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
return curIdx + 1;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const newBuckarooState = (k: BKeys) => {
|
|
65
|
+
const arr = optionCycles[k];
|
|
66
|
+
const curIdx = idxs[k];
|
|
67
|
+
const nextIdx = nextIndex(curIdx, arr);
|
|
68
|
+
const newVal = arr[nextIdx];
|
|
69
|
+
const newState = _.clone(buckarooState);
|
|
70
|
+
newState[k] = newVal;
|
|
71
|
+
return newState;
|
|
72
|
+
};
|
|
73
|
+
const updateDict = (event: any) => {
|
|
74
|
+
const colName = event.column.getColId();
|
|
75
|
+
if (colName === 'quick_command_args' || colName === 'search') {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (_.includes(_.keys(buckarooState), colName)) {
|
|
79
|
+
const nbstate = newBuckarooState(colName as BKeys);
|
|
80
|
+
setBuckarooState(nbstate);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const handleCellChange = useCallback((params: {oldValue: any; newValue: any}) => {
|
|
85
|
+
const {oldValue, newValue} = params;
|
|
86
|
+
|
|
87
|
+
if (oldValue !== newValue && newValue !== null) {
|
|
88
|
+
//console.log('Edited cell:', newValue);
|
|
89
|
+
const newState = {
|
|
90
|
+
...buckarooState,
|
|
91
|
+
quick_command_args: {search: [newValue]}
|
|
92
|
+
};
|
|
93
|
+
//console.log('handleCellChange', buckarooState, newState);
|
|
94
|
+
setBuckarooState(newState);
|
|
95
|
+
}
|
|
96
|
+
}, []);
|
|
97
|
+
|
|
98
|
+
const columnDefs: ColDef[] = [
|
|
99
|
+
{
|
|
100
|
+
field: 'search',
|
|
101
|
+
headerName: 'search',
|
|
102
|
+
width: 200,
|
|
103
|
+
editable: true,
|
|
104
|
+
onCellValueChanged: handleCellChange
|
|
105
|
+
//hide: !showSearch,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
field: 'df_display',
|
|
109
|
+
headerName: 'Σ', //note the greek symbols instead of icons which require buildchain work
|
|
110
|
+
headerTooltip: 'Summary Stats',
|
|
111
|
+
width: 120
|
|
112
|
+
},
|
|
113
|
+
/*
|
|
114
|
+
{
|
|
115
|
+
field: 'auto_clean',
|
|
116
|
+
//headerName: 'Σ', //note the greek symbols instead of icons which require buildchain work
|
|
117
|
+
headerName: 'auto cleaning',
|
|
118
|
+
headerTooltip: 'Auto Cleaning config',
|
|
119
|
+
width: 120,
|
|
120
|
+
},
|
|
121
|
+
*/
|
|
122
|
+
{
|
|
123
|
+
field: 'post_processing',
|
|
124
|
+
// headerName: "Θ",
|
|
125
|
+
headerName: 'post processing',
|
|
126
|
+
headerTooltip: 'post process method',
|
|
127
|
+
width: 100
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
field: 'show_commands',
|
|
131
|
+
headerName: 'λ',
|
|
132
|
+
headerTooltip: 'Show Commands',
|
|
133
|
+
width: 30
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
{field: 'sampled', headerName: 'Ξ', headerTooltip: 'Sampled', width: 30},
|
|
137
|
+
{
|
|
138
|
+
field: 'help',
|
|
139
|
+
headerName: '?',
|
|
140
|
+
headerTooltip: 'Help',
|
|
141
|
+
width: 30,
|
|
142
|
+
cellRenderer: helpCell
|
|
143
|
+
},
|
|
144
|
+
{field: 'total_rows', width: 100},
|
|
145
|
+
{field: 'filtered_rows', headerName: 'filtered', width: 85},
|
|
146
|
+
{field: 'rows_shown', headerName: 'displayed', width: 85},
|
|
147
|
+
{field: 'columns', width: 75}
|
|
148
|
+
];
|
|
149
|
+
|
|
150
|
+
const searchArg = buckarooState.quick_command_args?.search;
|
|
151
|
+
const searchStr = searchArg && searchArg.length === 1 ? searchArg[0] : '';
|
|
152
|
+
|
|
153
|
+
const rowData = [
|
|
154
|
+
{
|
|
155
|
+
total_rows: basicIntFormatter.format(dfMeta.total_rows),
|
|
156
|
+
columns: dfMeta.columns,
|
|
157
|
+
rows_shown: basicIntFormatter.format(dfMeta.rows_shown),
|
|
158
|
+
sampled: buckarooState.sampled || '0',
|
|
159
|
+
auto_clean: buckarooState.auto_clean || '0',
|
|
160
|
+
df_display: buckarooState.df_display,
|
|
161
|
+
filtered_rows: basicIntFormatter.format(dfMeta.filtered_rows),
|
|
162
|
+
post_processing: buckarooState.post_processing,
|
|
163
|
+
show_commands: buckarooState.show_commands || '0',
|
|
164
|
+
search: searchStr
|
|
165
|
+
}
|
|
166
|
+
];
|
|
167
|
+
|
|
168
|
+
const gridOptions: GridOptions = {
|
|
169
|
+
suppressRowClickSelection: true
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const gridRef = useRef<AgGridReact<unknown>>(null);
|
|
173
|
+
const defaultColDef = {
|
|
174
|
+
cellStyle: {textAlign: 'left'}
|
|
175
|
+
};
|
|
176
|
+
return (
|
|
177
|
+
<div className='statusBar'>
|
|
178
|
+
<div style={{height: 50}} className='theme-hanger ag-theme-alpine-dark'>
|
|
179
|
+
<AgGridReact
|
|
180
|
+
ref={gridRef}
|
|
181
|
+
onCellClicked={updateDict}
|
|
182
|
+
gridOptions={gridOptions}
|
|
183
|
+
defaultColDef={defaultColDef}
|
|
184
|
+
rowData={rowData}
|
|
185
|
+
columnDefs={columnDefs}
|
|
186
|
+
></AgGridReact>
|
|
187
|
+
</div>
|
|
188
|
+
</div>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface DFMeta {
|
|
2
|
+
// static,
|
|
3
|
+
total_rows: number;
|
|
4
|
+
columns: number;
|
|
5
|
+
filtered_rows: number;
|
|
6
|
+
rows_shown: number;
|
|
7
|
+
}
|
|
8
|
+
export interface BuckarooOptions {
|
|
9
|
+
sampled: string[];
|
|
10
|
+
auto_clean: string[];
|
|
11
|
+
post_processing: string[];
|
|
12
|
+
df_display: string[]; // keys into Into df_display_args
|
|
13
|
+
show_commands: string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type QuickAtom = number | string;
|
|
17
|
+
export type QuickArg = QuickAtom[];
|
|
18
|
+
export interface BuckarooState {
|
|
19
|
+
sampled: string | false;
|
|
20
|
+
auto_clean: string | false;
|
|
21
|
+
quick_command_args: Record<string, QuickArg>;
|
|
22
|
+
post_processing: string | false;
|
|
23
|
+
df_display: string; //at least one dataframe must always be displayed
|
|
24
|
+
show_commands: string | false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type BKeys = keyof BuckarooOptions;
|
|
28
|
+
|
|
29
|
+
// df_dict: Record<string, DFWhole>;
|
|
30
|
+
// df_meta: DFMeta;
|
|
31
|
+
/*
|
|
32
|
+
|
|
33
|
+
df_dict: Record<string, DFWhole>;
|
|
34
|
+
df_meta: DFMeta;
|
|
35
|
+
operations: Operation[];
|
|
36
|
+
on_operations: (ops: Operation[]) => void;
|
|
37
|
+
operation_results: OperationResult;
|
|
38
|
+
commandConfig: CommandConfigT;
|
|
39
|
+
buckaroo_state: BuckarooState;
|
|
40
|
+
on_buckaroo_state: React.Dispatch<React.SetStateAction<BuckarooState>>;
|
|
41
|
+
buckaroo_options: BuckarooOptions;
|
|
42
|
+
*/
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {OperationDefaultArgs} from './OperationUtils';
|
|
2
|
+
import {sym} from './utils';
|
|
3
|
+
import {symDf, CommandConfigT, bakedArgSpecs} from './CommandUtils';
|
|
4
|
+
|
|
5
|
+
export const bakedOperationDefaults: OperationDefaultArgs = {
|
|
6
|
+
dropcol: [sym('dropcol'), symDf, 'col'],
|
|
7
|
+
fillna: [sym('fillna'), symDf, 'col', 8],
|
|
8
|
+
resample: [sym('resample'), symDf, 'col', 'monthly', {}]
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const bakedCommandConfig: CommandConfigT = {
|
|
12
|
+
argspecs: bakedArgSpecs,
|
|
13
|
+
defaultArgs: bakedOperationDefaults
|
|
14
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import {DFWhole} from './DFViewerParts/DFWhole';
|
|
3
|
+
import {ColDef} from 'ag-grid-community';
|
|
4
|
+
|
|
5
|
+
export type setDFFunc = (newDf: DFWhole) => void;
|
|
6
|
+
|
|
7
|
+
export const requestDf = (url: string, setCallBack: setDFFunc) => {
|
|
8
|
+
const retPromise = fetch(url).then(async (response) => {
|
|
9
|
+
const tableDf = await response.json();
|
|
10
|
+
setCallBack(tableDf);
|
|
11
|
+
});
|
|
12
|
+
return retPromise;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const sym = (symbolName: string) => {
|
|
16
|
+
return {symbol: symbolName};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function replaceInArr<T>(arr: T[], old: T, subst: T): T[] {
|
|
20
|
+
return arr.map((item: T) => (item === old ? subst : item));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function replaceAtIdx<T>(arr: T[], idx: number, subst: T): T[] {
|
|
24
|
+
return arr.map((item: T, innerIdx: number) => (innerIdx === idx ? subst : item));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function replaceAtKey<T>(obj: Record<string, T>, key: string, subst: T): Record<string, T> {
|
|
28
|
+
const objCopy = _.clone(obj);
|
|
29
|
+
objCopy[key] = subst;
|
|
30
|
+
return objCopy;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const objWithoutNull = (obj: Record<string, string>, extraStrips: string[] = []) =>
|
|
34
|
+
_.pickBy(obj, (x) => ![null, undefined, ...extraStrips].includes(x));
|
|
35
|
+
export const updateAtMatch = (
|
|
36
|
+
cols: ColDef[],
|
|
37
|
+
key: string,
|
|
38
|
+
subst: Partial<ColDef>,
|
|
39
|
+
negative: Partial<ColDef>
|
|
40
|
+
) => {
|
|
41
|
+
const retColumns = cols.map((x) => {
|
|
42
|
+
if (x.field === key) {
|
|
43
|
+
return {...x, ...subst};
|
|
44
|
+
} else {
|
|
45
|
+
return {...x, ...negative};
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return retColumns;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const replaceAtMatch = (cols: ColDef[], key: string, subst: Partial<ColDef>) => {
|
|
52
|
+
const retColumns = cols.map((x) => {
|
|
53
|
+
if (x.field === key) {
|
|
54
|
+
return {...x, ...subst};
|
|
55
|
+
} else {
|
|
56
|
+
return {...x};
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return retColumns;
|
|
60
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
// Entry point for the notebook bundle containing custom model definitions.
|
|
5
|
+
//
|
|
6
|
+
// Setup notebook base URL
|
|
7
|
+
//
|
|
8
|
+
// Some static assets may be required by the custom widget javascript. The base
|
|
9
|
+
// url for the notebook is not known at build time and is therefore computed
|
|
10
|
+
// dynamically.
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
(window as any).__webpack_public_path__ =
|
|
13
|
+
document.querySelector('body')!.getAttribute('data-base-url') + 'nbextensions/buckaroo';
|
|
14
|
+
|
|
15
|
+
export * from './index';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Copyright (c) Bloomberg
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import {ColumnsEditor, ColumnsEditorEx} from './components/ColumnsEditor';
|
|
5
|
+
import {WidgetDCFCellExample} from './components/DCFCell';
|
|
6
|
+
import {DFViewer, DFViewerEx} from './components/DFViewerParts/DFViewer';
|
|
7
|
+
import {HistogramCell} from './components/DFViewerParts/HistogramCell';
|
|
8
|
+
import {DependentTabs} from './components/DependentTabs';
|
|
9
|
+
import {OperationViewer} from './components/Operations';
|
|
10
|
+
//import { DFData, DFViewerConfig } from './components/DFViewerParts/DFWhole';
|
|
11
|
+
import {StatusBar} from './components/StatusBar';
|
|
12
|
+
|
|
13
|
+
// In case of classic Jupyter Notebook and embed, we provide the PhosphorJS CSS
|
|
14
|
+
|
|
15
|
+
export * as bakedData from './baked_data/staticData';
|
|
16
|
+
|
|
17
|
+
export const extraComponents = {
|
|
18
|
+
ColumnsEditor,
|
|
19
|
+
DependentTabs,
|
|
20
|
+
OperationViewer,
|
|
21
|
+
WidgetDCFCellExample,
|
|
22
|
+
ColumnsEditorEx,
|
|
23
|
+
DFViewer,
|
|
24
|
+
DFViewerEx,
|
|
25
|
+
StatusBar,
|
|
26
|
+
HistogramCell
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
export const typing = {
|
|
31
|
+
DFData,
|
|
32
|
+
DFViewerConfig
|
|
33
|
+
};
|
|
34
|
+
*/
|