@seedtactics/insight-client 16.4.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/README.md +37 -0
- package/dist/cell-status/buffers.d.ts +36 -0
- package/dist/cell-status/buffers.js +127 -0
- package/dist/cell-status/current-status.d.ts +30 -0
- package/dist/cell-status/current-status.js +200 -0
- package/dist/cell-status/estimated-cycle-times.d.ts +41 -0
- package/dist/cell-status/estimated-cycle-times.js +257 -0
- package/dist/cell-status/inspections.d.ts +55 -0
- package/dist/cell-status/inspections.js +213 -0
- package/dist/cell-status/loading.d.ts +26 -0
- package/dist/cell-status/loading.js +112 -0
- package/dist/cell-status/material-details.d.ts +116 -0
- package/dist/cell-status/material-details.js +422 -0
- package/dist/cell-status/material-summary.d.ts +52 -0
- package/dist/cell-status/material-summary.js +312 -0
- package/dist/cell-status/names.d.ts +19 -0
- package/dist/cell-status/names.js +134 -0
- package/dist/cell-status/pallet-cycles.d.ts +24 -0
- package/dist/cell-status/pallet-cycles.js +78 -0
- package/dist/cell-status/rebookings.d.ts +30 -0
- package/dist/cell-status/rebookings.js +139 -0
- package/dist/cell-status/scheduled-jobs.d.ts +18 -0
- package/dist/cell-status/scheduled-jobs.js +94 -0
- package/dist/cell-status/sim-day-usage.d.ts +14 -0
- package/dist/cell-status/sim-day-usage.js +54 -0
- package/dist/cell-status/sim-production.d.ts +22 -0
- package/dist/cell-status/sim-production.js +91 -0
- package/dist/cell-status/sim-station-use.d.ts +25 -0
- package/dist/cell-status/sim-station-use.js +71 -0
- package/dist/cell-status/station-cycles.d.ts +34 -0
- package/dist/cell-status/station-cycles.js +145 -0
- package/dist/cell-status/tool-replacements.d.ts +44 -0
- package/dist/cell-status/tool-replacements.js +155 -0
- package/dist/cell-status/tool-usage.d.ts +25 -0
- package/dist/cell-status/tool-usage.js +95 -0
- package/dist/components/App.d.ts +15 -0
- package/dist/components/App.js +549 -0
- package/dist/components/AxisAndGrid.d.ts +51 -0
- package/dist/components/AxisAndGrid.js +47 -0
- package/dist/components/BarcodeScanning.d.ts +6 -0
- package/dist/components/BarcodeScanning.js +150 -0
- package/dist/components/ChartTooltip.d.ts +28 -0
- package/dist/components/ChartTooltip.js +95 -0
- package/dist/components/ChooseMode.d.ts +18 -0
- package/dist/components/ChooseMode.js +136 -0
- package/dist/components/ChooseOperator.d.ts +1 -0
- package/dist/components/ChooseOperator.js +93 -0
- package/dist/components/ErrorsAndLoading.d.ts +9 -0
- package/dist/components/ErrorsAndLoading.js +55 -0
- package/dist/components/LoadingIcon.d.ts +1 -0
- package/dist/components/LoadingIcon.js +48 -0
- package/dist/components/LogEntry.d.ts +16 -0
- package/dist/components/LogEntry.js +365 -0
- package/dist/components/ManualSerialEntry.d.ts +5 -0
- package/dist/components/ManualSerialEntry.js +91 -0
- package/dist/components/MonthSelect.d.ts +6 -0
- package/dist/components/MonthSelect.js +67 -0
- package/dist/components/Navigation.d.ts +23 -0
- package/dist/components/Navigation.js +120 -0
- package/dist/components/VerboseLogging.d.ts +1 -0
- package/dist/components/VerboseLogging.js +47 -0
- package/dist/components/analysis/AnalysisSelectToolbar.d.ts +1 -0
- package/dist/components/analysis/AnalysisSelectToolbar.js +55 -0
- package/dist/components/analysis/BufferChart.d.ts +1 -0
- package/dist/components/analysis/BufferChart.js +139 -0
- package/dist/components/analysis/CostPerPiece.d.ts +2 -0
- package/dist/components/analysis/CostPerPiece.js +175 -0
- package/dist/components/analysis/CycleChart.d.ts +42 -0
- package/dist/components/analysis/CycleChart.js +281 -0
- package/dist/components/analysis/DataTable.d.ts +83 -0
- package/dist/components/analysis/DataTable.js +215 -0
- package/dist/components/analysis/EfficiencyPage.d.ts +2 -0
- package/dist/components/analysis/EfficiencyPage.js +138 -0
- package/dist/components/analysis/HeatChart.d.ts +22 -0
- package/dist/components/analysis/HeatChart.js +161 -0
- package/dist/components/analysis/InspectionDataTable.d.ts +10 -0
- package/dist/components/analysis/InspectionDataTable.js +148 -0
- package/dist/components/analysis/InspectionSankey.d.ts +12 -0
- package/dist/components/analysis/InspectionSankey.js +140 -0
- package/dist/components/analysis/PalletCycleCards.d.ts +1 -0
- package/dist/components/analysis/PalletCycleCards.js +137 -0
- package/dist/components/analysis/PartCycleCards.d.ts +2 -0
- package/dist/components/analysis/PartCycleCards.js +331 -0
- package/dist/components/analysis/QualityPage.d.ts +1 -0
- package/dist/components/analysis/QualityPage.js +49 -0
- package/dist/components/analysis/ScheduleHistory.d.ts +3 -0
- package/dist/components/analysis/ScheduleHistory.js +108 -0
- package/dist/components/analysis/StationDataTable.d.ts +25 -0
- package/dist/components/analysis/StationDataTable.js +246 -0
- package/dist/components/analysis/ToolReplacements.d.ts +1 -0
- package/dist/components/analysis/ToolReplacements.js +370 -0
- package/dist/components/operations/AllMaterial.d.ts +5 -0
- package/dist/components/operations/AllMaterial.js +267 -0
- package/dist/components/operations/ChartRangeEdit.d.ts +4 -0
- package/dist/components/operations/ChartRangeEdit.js +148 -0
- package/dist/components/operations/CloseoutReport.d.ts +2 -0
- package/dist/components/operations/CloseoutReport.js +172 -0
- package/dist/components/operations/CompletedParts.d.ts +2 -0
- package/dist/components/operations/CompletedParts.js +286 -0
- package/dist/components/operations/CurrentWorkorders.d.ts +3 -0
- package/dist/components/operations/CurrentWorkorders.js +368 -0
- package/dist/components/operations/Dashboard.d.ts +2 -0
- package/dist/components/operations/Dashboard.js +90 -0
- package/dist/components/operations/OEEChart.d.ts +10 -0
- package/dist/components/operations/OEEChart.js +173 -0
- package/dist/components/operations/Outliers.d.ts +4 -0
- package/dist/components/operations/Outliers.js +69 -0
- package/dist/components/operations/ProgramHighlight.d.ts +1 -0
- package/dist/components/operations/ProgramHighlight.js +9 -0
- package/dist/components/operations/Programs.d.ts +5 -0
- package/dist/components/operations/Programs.js +363 -0
- package/dist/components/operations/Rebookings.d.ts +1 -0
- package/dist/components/operations/Rebookings.js +213 -0
- package/dist/components/operations/RecentCycleChart.d.ts +4 -0
- package/dist/components/operations/RecentCycleChart.js +240 -0
- package/dist/components/operations/RecentProduction.d.ts +2 -0
- package/dist/components/operations/RecentProduction.js +213 -0
- package/dist/components/operations/RecentSchedules.d.ts +12 -0
- package/dist/components/operations/RecentSchedules.js +180 -0
- package/dist/components/operations/RecentStationCycles.d.ts +4 -0
- package/dist/components/operations/RecentStationCycles.js +159 -0
- package/dist/components/operations/ShiftSettings.d.ts +6 -0
- package/dist/components/operations/ShiftSettings.js +134 -0
- package/dist/components/operations/SimDayUsage.d.ts +1 -0
- package/dist/components/operations/SimDayUsage.js +133 -0
- package/dist/components/operations/ToolReport.d.ts +3 -0
- package/dist/components/operations/ToolReport.js +233 -0
- package/dist/components/operations/WorkorderGantt.d.ts +1 -0
- package/dist/components/operations/WorkorderGantt.js +124 -0
- package/dist/components/quality/QualityMaterial.d.ts +2 -0
- package/dist/components/quality/QualityMaterial.js +169 -0
- package/dist/components/quality/QualityPaths.d.ts +1 -0
- package/dist/components/quality/QualityPaths.js +53 -0
- package/dist/components/quality/RecentFailedInspections.d.ts +1 -0
- package/dist/components/quality/RecentFailedInspections.js +123 -0
- package/dist/components/routes.d.ts +170 -0
- package/dist/components/routes.js +301 -0
- package/dist/components/station-monitor/BulkRawMaterial.d.ts +11 -0
- package/dist/components/station-monitor/BulkRawMaterial.js +251 -0
- package/dist/components/station-monitor/Closeout.d.ts +5 -0
- package/dist/components/station-monitor/Closeout.js +162 -0
- package/dist/components/station-monitor/CustomStationMonitorDialog.d.ts +1 -0
- package/dist/components/station-monitor/CustomStationMonitorDialog.js +55 -0
- package/dist/components/station-monitor/Inspection.d.ts +8 -0
- package/dist/components/station-monitor/Inspection.js +164 -0
- package/dist/components/station-monitor/InvalidateCycle.d.ts +33 -0
- package/dist/components/station-monitor/InvalidateCycle.js +262 -0
- package/dist/components/station-monitor/JobDetails.d.ts +7 -0
- package/dist/components/station-monitor/JobDetails.js +108 -0
- package/dist/components/station-monitor/LoadStation.d.ts +10 -0
- package/dist/components/station-monitor/LoadStation.js +450 -0
- package/dist/components/station-monitor/Material.d.ts +77 -0
- package/dist/components/station-monitor/Material.js +489 -0
- package/dist/components/station-monitor/MoveMaterialArrows.d.ts +11 -0
- package/dist/components/station-monitor/MoveMaterialArrows.js +118 -0
- package/dist/components/station-monitor/PrintedLabel.d.ts +29 -0
- package/dist/components/station-monitor/PrintedLabel.js +166 -0
- package/dist/components/station-monitor/QuarantineButton.d.ts +4 -0
- package/dist/components/station-monitor/QuarantineButton.js +184 -0
- package/dist/components/station-monitor/Queues.d.ts +23 -0
- package/dist/components/station-monitor/Queues.js +312 -0
- package/dist/components/station-monitor/QueuesAddMaterial.d.ts +30 -0
- package/dist/components/station-monitor/QueuesAddMaterial.js +248 -0
- package/dist/components/station-monitor/SelectInspType.d.ts +2 -0
- package/dist/components/station-monitor/SelectInspType.js +99 -0
- package/dist/components/station-monitor/SelectWorkorder.d.ts +4 -0
- package/dist/components/station-monitor/SelectWorkorder.js +100 -0
- package/dist/components/station-monitor/StationToolbar.d.ts +3 -0
- package/dist/components/station-monitor/StationToolbar.js +168 -0
- package/dist/components/station-monitor/SystemOverview.d.ts +46 -0
- package/dist/components/station-monitor/SystemOverview.js +439 -0
- package/dist/components/station-monitor/Whiteboard.d.ts +10 -0
- package/dist/components/station-monitor/Whiteboard.js +67 -0
- package/dist/data/all-material-bins.d.ts +45 -0
- package/dist/data/all-material-bins.js +224 -0
- package/dist/data/chart-times.d.ts +20 -0
- package/dist/data/chart-times.js +99 -0
- package/dist/data/cost-per-piece.d.ts +32 -0
- package/dist/data/cost-per-piece.js +183 -0
- package/dist/data/current-cycles.d.ts +13 -0
- package/dist/data/current-cycles.js +144 -0
- package/dist/data/inspection-sankey.d.ts +15 -0
- package/dist/data/inspection-sankey.js +147 -0
- package/dist/data/move-arrows.d.ts +48 -0
- package/dist/data/move-arrows.js +217 -0
- package/dist/data/operators.d.ts +2 -0
- package/dist/data/operators.js +44 -0
- package/dist/data/part-summary.d.ts +17 -0
- package/dist/data/part-summary.js +107 -0
- package/dist/data/path-lookup.d.ts +13 -0
- package/dist/data/path-lookup.js +107 -0
- package/dist/data/queue-material.d.ts +46 -0
- package/dist/data/queue-material.js +256 -0
- package/dist/data/results.bufferchart.d.ts +10 -0
- package/dist/data/results.bufferchart.js +90 -0
- package/dist/data/results.completed-parts.d.ts +26 -0
- package/dist/data/results.completed-parts.js +181 -0
- package/dist/data/results.cycles.d.ts +86 -0
- package/dist/data/results.cycles.js +454 -0
- package/dist/data/results.inspection.d.ts +36 -0
- package/dist/data/results.inspection.js +188 -0
- package/dist/data/results.oee.d.ts +40 -0
- package/dist/data/results.oee.js +330 -0
- package/dist/data/results.schedules.d.ts +23 -0
- package/dist/data/results.schedules.js +157 -0
- package/dist/data/tools-programs.d.ts +78 -0
- package/dist/data/tools-programs.js +376 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +60 -0
- package/dist/network/api.d.ts +1390 -0
- package/dist/network/api.js +4971 -0
- package/dist/network/backend-mock.d.ts +11 -0
- package/dist/network/backend-mock.js +512 -0
- package/dist/network/backend.d.ts +57 -0
- package/dist/network/backend.js +77 -0
- package/dist/network/load-specific-month.d.ts +13 -0
- package/dist/network/load-specific-month.js +77 -0
- package/dist/network/server-settings.d.ts +12 -0
- package/dist/network/server-settings.js +92 -0
- package/dist/network/websocket.d.ts +4 -0
- package/dist/network/websocket.js +165 -0
- package/dist/renderer.d.ts +8 -0
- package/dist/renderer.js +55 -0
- package/dist/seedtactics-logo.d.ts +2 -0
- package/dist/seedtactics-logo.js +4 -0
- package/dist/util/chart-colors.d.ts +1 -0
- package/dist/util/chart-colors.js +116 -0
- package/dist/util/chart-helpers.d.ts +3 -0
- package/dist/util/chart-helpers.js +51 -0
- package/dist/util/parseISODuration.d.ts +4 -0
- package/dist/util/parseISODuration.js +40 -0
- package/docs/client-efficiency.md +355 -0
- package/docs/client-engineering.md +54 -0
- package/docs/client-launch.md +55 -0
- package/docs/client-operations.md +88 -0
- package/docs/client-quality.md +74 -0
- package/docs/client-sales.md +61 -0
- package/docs/client-scanners.md +41 -0
- package/docs/client-station-monitor.md +149 -0
- package/docs/client-tools-programs.md +74 -0
- package/docs/improve-fms.md +141 -0
- package/docs/makino.md +40 -0
- package/docs/material-quarantine.md +82 -0
- package/docs/material-tracking.md +236 -0
- package/docs/mazak.md +115 -0
- package/docs/niigata.md +228 -0
- package/docs/operator-procedures.md +106 -0
- package/docs/part-instructions.md +63 -0
- package/docs/screenshots/insight-all-material.png +0 -0
- package/docs/screenshots/insight-analysis-pallets.png +0 -0
- package/docs/screenshots/insight-analysis-part-completed.png +0 -0
- package/docs/screenshots/insight-analysis-sankey.png +0 -0
- package/docs/screenshots/insight-analysis-station-oee.png +0 -0
- package/docs/screenshots/insight-buffer-occupancy.png +0 -0
- package/docs/screenshots/insight-choose-analysis-month.png +0 -0
- package/docs/screenshots/insight-closeout.png +0 -0
- package/docs/screenshots/insight-cost-percentages.png +0 -0
- package/docs/screenshots/insight-dashboard.png +0 -0
- package/docs/screenshots/insight-event-custom-view.jpg +0 -0
- package/docs/screenshots/insight-event-viewer.jpg +0 -0
- package/docs/screenshots/insight-inspection.png +0 -0
- package/docs/screenshots/insight-load-station-details.png +0 -0
- package/docs/screenshots/insight-load-station.png +0 -0
- package/docs/screenshots/insight-loadcycle-graph.png +0 -0
- package/docs/screenshots/insight-loadstation-small.jpg +0 -0
- package/docs/screenshots/insight-machinecycle-graph.png +0 -0
- package/docs/screenshots/insight-machinecycle-table.png +0 -0
- package/docs/screenshots/insight-machinecycles.png +0 -0
- package/docs/screenshots/insight-machinehours.png +0 -0
- package/docs/screenshots/insight-machineoutliers.png +0 -0
- package/docs/screenshots/insight-monthly-schedules.png +0 -0
- package/docs/screenshots/insight-operations-material.png +0 -0
- package/docs/screenshots/insight-operations-overview.png +0 -0
- package/docs/screenshots/insight-operations-reports.png +0 -0
- package/docs/screenshots/insight-part-cost.png +0 -0
- package/docs/screenshots/insight-program-report.png +0 -0
- package/docs/screenshots/insight-quality-material-details.png +0 -0
- package/docs/screenshots/insight-quality-material.png +0 -0
- package/docs/screenshots/insight-quality-quarantine.png +0 -0
- package/docs/screenshots/insight-quality-sankey.png +0 -0
- package/docs/screenshots/insight-quality-similar-paths.png +0 -0
- package/docs/screenshots/insight-queue-details.png +0 -0
- package/docs/screenshots/insight-queues-jobs-table.png +0 -0
- package/docs/screenshots/insight-queues.png +0 -0
- package/docs/screenshots/insight-sim-day-usage.png +0 -0
- package/docs/screenshots/insight-station-system-overview-buttons.png +0 -0
- package/docs/screenshots/insight-station-system-overview.png +0 -0
- package/docs/screenshots/insight-system-overview.png +0 -0
- package/docs/screenshots/insight-tool-replacements.png +0 -0
- package/docs/screenshots/insight-tool-report.png +0 -0
- package/docs/screenshots/insight-toolbar-btns.png +0 -0
- package/docs/screenshots/insight-workorder-gantt.png +0 -0
- package/docs/screenshots/insight-workorders.png +0 -0
- package/docs/security.md +131 -0
- package/docs/server-config.md +56 -0
- package/docs/server-errors.md +44 -0
- package/package.json +90 -0
- package/src/index.ts +65 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/* Copyright (c) 2022, John Lenz
|
|
3
|
+
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
* Redistributions of source code must retain the above copyright
|
|
10
|
+
notice, this list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
* Redistributions in binary form must reproduce the above
|
|
13
|
+
copyright notice, this list of conditions and the following
|
|
14
|
+
disclaimer in the documentation and/or other materials provided
|
|
15
|
+
with the distribution.
|
|
16
|
+
|
|
17
|
+
* Neither the name of John Lenz, Black Maple Software, SeedTactics,
|
|
18
|
+
nor the names of other contributors may be used to endorse or
|
|
19
|
+
promote products derived from this software without specific
|
|
20
|
+
prior written permission.
|
|
21
|
+
|
|
22
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
23
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
24
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
25
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
26
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
27
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
28
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
29
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
30
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
31
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
32
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
33
|
+
*/
|
|
34
|
+
import { useMemo, memo, useState, useCallback } from "react";
|
|
35
|
+
import { Dialog, DialogContent, DialogActions, TextField, IconButton, Button, styled, ToggleButton, Stack, } from "@mui/material";
|
|
36
|
+
import { ZoomIn } from "@mui/icons-material";
|
|
37
|
+
import { seriesColor } from "../../util/chart-colors.js";
|
|
38
|
+
import { grey } from "@mui/material/colors";
|
|
39
|
+
import { scaleLinear, scaleTime } from "d3-scale";
|
|
40
|
+
import { ChartWithTooltip } from "../ChartTooltip.js";
|
|
41
|
+
import { AxisBottom, AxisLeft, ChartGrid } from "../AxisAndGrid.js";
|
|
42
|
+
import { useSpring, useSprings, animated } from "@react-spring/web";
|
|
43
|
+
import { HashSet, LazySeq } from "@seedtactics/immutable-collections";
|
|
44
|
+
import { atom, useSetAtom } from "jotai";
|
|
45
|
+
import { localPoint } from "../../util/chart-helpers.js";
|
|
46
|
+
function useDataToPlot({ points, stats, partCntPerPoint }) {
|
|
47
|
+
const series = useMemo(() => {
|
|
48
|
+
return (LazySeq.of(points)
|
|
49
|
+
// need to sort first so the color indices are correct
|
|
50
|
+
.toSortedArray(([k]) => k)
|
|
51
|
+
.map(([seriesName, seriesPoints], idx) => ({
|
|
52
|
+
name: seriesName,
|
|
53
|
+
color: seriesColor(idx, points.size),
|
|
54
|
+
points: seriesPoints ?? [],
|
|
55
|
+
})));
|
|
56
|
+
}, [points]);
|
|
57
|
+
const median = useMemo(() => {
|
|
58
|
+
if (stats) {
|
|
59
|
+
const low = (partCntPerPoint ?? 1) * (stats.medianMinutesForSingleMat - stats.MAD_belowMinutes);
|
|
60
|
+
const high = (partCntPerPoint ?? 1) * (stats.medianMinutesForSingleMat + stats.MAD_aboveMinutes);
|
|
61
|
+
return { low, high };
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}, [stats, partCntPerPoint]);
|
|
67
|
+
return { series, median };
|
|
68
|
+
}
|
|
69
|
+
const marginLeft = 50;
|
|
70
|
+
const marginBottom = 30;
|
|
71
|
+
const marginTop = 10;
|
|
72
|
+
const marginRight = 2;
|
|
73
|
+
function useScales({ points, yZoom, default_date_range, current_date_zoom, containerWidth, containerHeight, }) {
|
|
74
|
+
const width = containerWidth === 0 ? 400 : containerWidth;
|
|
75
|
+
const height = containerHeight === 0 ? 400 : containerHeight;
|
|
76
|
+
const xMax = width - marginLeft - marginRight;
|
|
77
|
+
const yMax = height - marginTop - marginBottom;
|
|
78
|
+
const xScale = useMemo(() => {
|
|
79
|
+
if (current_date_zoom) {
|
|
80
|
+
return scaleTime().domain([current_date_zoom.start, current_date_zoom.end]).range([0, xMax]);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return scaleTime().domain([default_date_range[0], default_date_range[1]]).range([0, xMax]);
|
|
84
|
+
}
|
|
85
|
+
}, [current_date_zoom, default_date_range, xMax]);
|
|
86
|
+
const maxYVal = useMemo(() => {
|
|
87
|
+
if (points.size === 0)
|
|
88
|
+
return 60;
|
|
89
|
+
const m = LazySeq.of(points)
|
|
90
|
+
.flatMap(([, pts]) => pts.map((p) => p.y))
|
|
91
|
+
.maxBy((y) => y) ?? 1;
|
|
92
|
+
// round up to nearest 5
|
|
93
|
+
return Math.ceil(m / 5) * 5;
|
|
94
|
+
}, [points]);
|
|
95
|
+
const yScale = useMemo(() => {
|
|
96
|
+
if (yZoom) {
|
|
97
|
+
return scaleLinear().domain([yZoom.y_low, yZoom.y_high]).range([yMax, 0]);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
return scaleLinear().domain([0, maxYVal]).range([yMax, 0]);
|
|
101
|
+
}
|
|
102
|
+
}, [yMax, yZoom, maxYVal]);
|
|
103
|
+
return { height, width, xScale, yScale };
|
|
104
|
+
}
|
|
105
|
+
const AxisAndGrid = memo(function AxisAndGrid({ xScale, yScale }) {
|
|
106
|
+
return (_jsxs(_Fragment, { children: [_jsx(AxisBottom, { scale: xScale, top: yScale.range()[0] }), _jsx(AxisLeft, { scale: yScale, left: xScale.range()[0], label: "Minutes" }), _jsx(ChartGrid, { width: xScale.range()[1] - xScale.range()[0], height: yScale.range()[0] - yScale.range()[1], xScale: xScale, yScale: yScale })] }));
|
|
107
|
+
});
|
|
108
|
+
const SetYZoomButton = memo(function SetYZoomButton(props) {
|
|
109
|
+
const [low, setLow] = useState();
|
|
110
|
+
const [high, setHigh] = useState();
|
|
111
|
+
const [open, setOpen] = useState(false);
|
|
112
|
+
function close() {
|
|
113
|
+
setOpen(false);
|
|
114
|
+
setLow(undefined);
|
|
115
|
+
setHigh(undefined);
|
|
116
|
+
}
|
|
117
|
+
return (_jsxs(_Fragment, { children: [_jsx(IconButton, { size: "small", onClick: () => setOpen(true), children: _jsx(ZoomIn, { fontSize: "inherit" }) }), _jsxs(Dialog, { open: open, onClose: close, children: [_jsxs(DialogContent, { children: [_jsx("div", { style: { marginBottom: "1em" }, children: _jsx(TextField, { type: "number", label: "Y Low", value: low !== undefined ? (isNaN(low) ? "" : low) : (props.yZoom?.y_low ?? ""), onChange: (e) => setLow(parseFloat(e.target.value)), onBlur: () => {
|
|
118
|
+
if (low) {
|
|
119
|
+
props.setZoom((z) => (z ? { ...z, y_low: low } : { y_low: low, y_high: 60 }));
|
|
120
|
+
}
|
|
121
|
+
} }) }), _jsx("div", { style: { marginBottom: "1em" }, children: _jsx(TextField, { type: "number", label: "Y High", value: high !== undefined ? (isNaN(high) ? "" : high) : (props.yZoom?.y_high ?? ""), onChange: (e) => setHigh(parseFloat(e.target.value)), onBlur: () => {
|
|
122
|
+
if (high) {
|
|
123
|
+
props.setZoom((z) => (z ? { ...z, y_high: high } : { y_low: 0, y_high: high }));
|
|
124
|
+
}
|
|
125
|
+
} }) })] }), _jsx(DialogActions, { children: _jsx(Button, { onClick: close, children: "Close" }) })] })] }));
|
|
126
|
+
});
|
|
127
|
+
const StatsSeries = memo(function StatsSeries({ median, plannedMinutes, xScale, yScale, }) {
|
|
128
|
+
const medianSpring = useSpring({
|
|
129
|
+
to: {
|
|
130
|
+
x: xScale.range()[0],
|
|
131
|
+
y: median ? yScale(median.high) : yScale.range()[0],
|
|
132
|
+
width: xScale.range()[1] - xScale.range()[0],
|
|
133
|
+
height: median ? yScale(median.low) - yScale(median.high) : 0,
|
|
134
|
+
},
|
|
135
|
+
from: {
|
|
136
|
+
x: xScale.range()[0],
|
|
137
|
+
y: yScale.range()[0],
|
|
138
|
+
width: xScale.range()[1] - xScale.range()[0],
|
|
139
|
+
height: 0,
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
const plannedSpring = useSpring({
|
|
143
|
+
to: { y: plannedMinutes ? yScale(plannedMinutes) : yScale.range()[0] },
|
|
144
|
+
from: { y: yScale.range()[0] },
|
|
145
|
+
});
|
|
146
|
+
return (_jsxs("g", { children: [median ? (_jsx(animated.rect, { x: medianSpring.x, y: medianSpring.y, width: medianSpring.width, height: medianSpring.height, fill: grey[700], opacity: 0.2, pointerEvents: "none" })) : undefined, plannedMinutes ? (_jsx(animated.line, { stroke: "black", x1: xScale.range()[0], x2: xScale.range()[1], y1: plannedSpring.y, y2: plannedSpring.y })) : undefined] }));
|
|
147
|
+
});
|
|
148
|
+
const SingleSeries = memo(function SingleSeries({ seriesName, points, color, xScale, yScale, showTooltip, }) {
|
|
149
|
+
const show = useCallback((e) => {
|
|
150
|
+
const p = localPoint(e);
|
|
151
|
+
if (p === null)
|
|
152
|
+
return;
|
|
153
|
+
const idxS = e.target.dataset.idx;
|
|
154
|
+
if (idxS === undefined)
|
|
155
|
+
return;
|
|
156
|
+
showTooltip({
|
|
157
|
+
left: p.x,
|
|
158
|
+
top: p.y,
|
|
159
|
+
pt: points[parseInt(idxS)],
|
|
160
|
+
seriesName,
|
|
161
|
+
});
|
|
162
|
+
}, [showTooltip, points, seriesName]);
|
|
163
|
+
const springs = useSprings(points.length, points.map((pt) => ({
|
|
164
|
+
from: { x: xScale(pt.x), y: yScale.range()[0] + 15 },
|
|
165
|
+
to: { x: xScale(pt.x), y: yScale(pt.y) },
|
|
166
|
+
})));
|
|
167
|
+
return (_jsx("g", { children: springs.map((pt, idx) => (_jsx(animated.circle, { className: "bms-cycle-chart-pt", fill: color, r: 5, cx: pt.x, cy: pt.y, "data-idx": idx, onClick: show }, idx))) }));
|
|
168
|
+
});
|
|
169
|
+
const AllPointsSeries = memo(function AllPointsSeries({ series, xScale, yScale, showTooltip, disabledSeries, }) {
|
|
170
|
+
return (_jsx("g", { children: series
|
|
171
|
+
.filter((s) => !disabledSeries.has(s.name))
|
|
172
|
+
.map((s) => (_jsx(SingleSeries, { points: s.points, seriesName: s.name, color: s.color, xScale: xScale, yScale: yScale, showTooltip: showTooltip }, s.name))) }));
|
|
173
|
+
});
|
|
174
|
+
const Legend = memo(function Legend({ series, disabledSeries, adjustDisabled, }) {
|
|
175
|
+
return (_jsx("div", { style: { marginTop: "1em", display: "flex", flexWrap: "wrap", justifyContent: "space-around" }, children: series.map((s) => (_jsx(ToggleButton, { selected: !disabledSeries.has(s.name), value: s, onChange: () => adjustDisabled((b) => (b.has(s.name) ? b.delete(s.name) : b.add(s.name))), children: _jsxs("div", { style: { display: "flex", alignItems: "center" }, children: [_jsx("div", { style: { width: "14px", height: "14px", backgroundColor: s.color } }), _jsx("div", { style: { marginLeft: "1em" }, children: s.name })] }) }, s.name))) }));
|
|
176
|
+
});
|
|
177
|
+
const NoPointerEvents = styled("g", { shouldForwardProp: (prop) => prop.toString()[0] !== "$" })(({ $noPtrEvents }) => $noPtrEvents
|
|
178
|
+
? {
|
|
179
|
+
"& .bms-cycle-chart-pt": {
|
|
180
|
+
pointerevents: "none",
|
|
181
|
+
},
|
|
182
|
+
}
|
|
183
|
+
: undefined);
|
|
184
|
+
const ChartMouseEvents = memo(function ChartMouseEvents({ setYZoom, setXZoom, setTooltip, xScale, yScale, highlightStart, setHighlightStart, }) {
|
|
185
|
+
// mouse click and drag zooms
|
|
186
|
+
const [curHighlight, setCurrent] = useState(null);
|
|
187
|
+
const pointerDown = useCallback((e) => {
|
|
188
|
+
const p = localPoint(e);
|
|
189
|
+
if (p === null)
|
|
190
|
+
return;
|
|
191
|
+
setCurrent(null);
|
|
192
|
+
setHighlightStart({ x: p.x - marginLeft, y: p.y - marginTop, nowMS: Date.now() });
|
|
193
|
+
setTooltip(null);
|
|
194
|
+
}, [setHighlightStart, setTooltip]);
|
|
195
|
+
const pointerMove = useCallback((e) => {
|
|
196
|
+
const p = localPoint(e);
|
|
197
|
+
if (p === null)
|
|
198
|
+
return;
|
|
199
|
+
setCurrent({ x: p.x - marginLeft, y: p.y - marginTop });
|
|
200
|
+
}, [setCurrent]);
|
|
201
|
+
const pointerUp = useCallback((e) => {
|
|
202
|
+
if (highlightStart === null)
|
|
203
|
+
return;
|
|
204
|
+
if (Date.now() - highlightStart.nowMS > 500) {
|
|
205
|
+
const p = localPoint(e);
|
|
206
|
+
if (p !== null) {
|
|
207
|
+
const time1 = xScale.invert(highlightStart.x);
|
|
208
|
+
const time2 = xScale.invert(p.x - marginLeft);
|
|
209
|
+
const y1 = yScale.invert(highlightStart.y);
|
|
210
|
+
const y2 = yScale.invert(p.y - marginTop);
|
|
211
|
+
setYZoom(y1 < y2 ? { y_low: y1, y_high: y2 } : { y_low: y2, y_high: y1 });
|
|
212
|
+
setXZoom?.({
|
|
213
|
+
zoom: time1.getTime() < time2.getTime() ? { start: time1, end: time2 } : { start: time2, end: time1 },
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
setHighlightStart(null);
|
|
218
|
+
setCurrent(null);
|
|
219
|
+
}, [highlightStart, setHighlightStart, setCurrent, setXZoom, setYZoom, xScale, yScale]);
|
|
220
|
+
return (_jsxs("g", { children: [_jsx("rect", { x: 0, y: 0, width: xScale.range()[1], height: yScale.range()[0], fill: "transparent", onPointerDown: pointerDown, onPointerMove: highlightStart !== null ? pointerMove : undefined, onPointerUp: highlightStart !== null ? pointerUp : undefined }), highlightStart !== null && curHighlight !== null ? (_jsx("rect", { x: Math.min(highlightStart.x, curHighlight.x), y: Math.min(highlightStart.y, curHighlight.y), width: Math.abs(highlightStart.x - curHighlight.x), height: Math.abs(highlightStart.y - curHighlight.y), color: "red", pointerEvents: "none", opacity: 0.3 })) : undefined] }));
|
|
221
|
+
});
|
|
222
|
+
const ChartZoomButtons = memo(function ChartZoomButtons({ set_date_zoom_range, current_date_zoom, yZoom, setYZoom, median, }) {
|
|
223
|
+
return (_jsxs("div", { children: [set_date_zoom_range && (current_date_zoom || yZoom) ? (_jsxs(_Fragment, { children: [_jsx(Button, { size: "small", onClick: () => {
|
|
224
|
+
set_date_zoom_range?.({ zoom: undefined });
|
|
225
|
+
setYZoom(null);
|
|
226
|
+
}, children: "Reset Zoom" }), _jsx(SetYZoomButton, { yZoom: yZoom, setZoom: setYZoom })] })) : undefined, set_date_zoom_range && !current_date_zoom && !yZoom ? (_jsxs("span", { style: { color: "#6b6b76" }, children: ["Zoom via mouse drag", median ? (_jsxs(_Fragment, { children: [_jsx("span", { children: " or " }), _jsx(Button, { size: "small", onClick: () => {
|
|
227
|
+
const high = median.high;
|
|
228
|
+
const low = median.low;
|
|
229
|
+
const extra = 0.2 * (high - low);
|
|
230
|
+
setYZoom({ y_low: low - extra, y_high: high + extra });
|
|
231
|
+
}, children: "Zoom To Inliers" })] })) : undefined, _jsx(SetYZoomButton, { yZoom: yZoom, setZoom: setYZoom })] })) : undefined] }));
|
|
232
|
+
});
|
|
233
|
+
const CycleChartTooltip = memo(function CycleChartTooltip({ tooltip, extraTooltip, seriesLabel, }) {
|
|
234
|
+
if (tooltip === null)
|
|
235
|
+
return null;
|
|
236
|
+
return (_jsxs(Stack, { direction: "column", spacing: 0.6, children: [_jsxs("div", { children: ["Time:", " ", tooltip.pt.x.toLocaleString(undefined, {
|
|
237
|
+
month: "short",
|
|
238
|
+
day: "numeric",
|
|
239
|
+
year: "numeric",
|
|
240
|
+
hour: "numeric",
|
|
241
|
+
minute: "2-digit",
|
|
242
|
+
})] }), _jsxs("div", { children: [seriesLabel, ": ", tooltip.seriesName] }), _jsxs("div", { children: ["Cycle Time: ", tooltip.pt.y.toFixed(1), " minutes"] }), extraTooltip
|
|
243
|
+
? extraTooltip(tooltip.pt).map((e, idx) => (_jsxs("div", { children: [e.title, ":", " ", e.link ? (_jsx("a", { style: {
|
|
244
|
+
color: "white",
|
|
245
|
+
pointerEvents: "auto",
|
|
246
|
+
cursor: "pointer",
|
|
247
|
+
borderBottom: "1px solid",
|
|
248
|
+
}, onClick: e.link, children: e.value })) : (_jsx("span", { children: "e.value" }))] }, idx)))
|
|
249
|
+
: undefined] }));
|
|
250
|
+
});
|
|
251
|
+
function CycleChartSvg(props) {
|
|
252
|
+
// computed scales and values
|
|
253
|
+
const { width, height, xScale, yScale } = useScales({
|
|
254
|
+
points: props.points,
|
|
255
|
+
yZoom: props.yZoom,
|
|
256
|
+
setYZoom: props.setYZoom,
|
|
257
|
+
default_date_range: props.default_date_range,
|
|
258
|
+
current_date_zoom: props.current_date_zoom,
|
|
259
|
+
set_date_zoom_range: props.set_date_zoom_range,
|
|
260
|
+
containerWidth: props.containerWidth,
|
|
261
|
+
containerHeight: props.containerHeight,
|
|
262
|
+
});
|
|
263
|
+
return (_jsx("svg", { width: width, height: height, children: _jsxs("g", { transform: `translate(${marginLeft}, ${marginTop})`, children: [_jsx(AxisAndGrid, { xScale: xScale, yScale: yScale }), _jsx(StatsSeries, { median: props.median, plannedMinutes: props.plannedTimeMinutes, xScale: xScale, yScale: yScale }), _jsx(ChartMouseEvents, { setYZoom: props.setYZoom, setXZoom: props.set_date_zoom_range, xScale: xScale, setTooltip: props.showTooltip, yScale: yScale, highlightStart: props.highlightStart, setHighlightStart: props.setHighlightStart }), _jsx(NoPointerEvents, { "$noPtrEvents": props.highlightStart !== null, children: _jsx(AllPointsSeries, { series: props.series, disabledSeries: props.disabledSeries, xScale: xScale, yScale: yScale, showTooltip: props.showTooltip }) })] }) }));
|
|
264
|
+
}
|
|
265
|
+
export const CycleChart = memo(function CycleChart(props) {
|
|
266
|
+
// the state of the chart
|
|
267
|
+
const tooltipAtom = useMemo(() => atom(null), []);
|
|
268
|
+
const setTooltip = useSetAtom(tooltipAtom);
|
|
269
|
+
const [disabledSeries, setDisabled] = useState(HashSet.empty());
|
|
270
|
+
const [highlightStart, setHighlightStart] = useState(null);
|
|
271
|
+
const { series, median } = useDataToPlot({
|
|
272
|
+
points: props.points,
|
|
273
|
+
stats: props.stats,
|
|
274
|
+
partCntPerPoint: props.partCntPerPoint,
|
|
275
|
+
});
|
|
276
|
+
const pointerLeave = useCallback(() => {
|
|
277
|
+
setTooltip(null);
|
|
278
|
+
setHighlightStart(null);
|
|
279
|
+
}, [setTooltip, setHighlightStart]);
|
|
280
|
+
return (_jsxs("div", { onPointerLeave: pointerLeave, children: [_jsx(ChartWithTooltip, { sx: { height: { xs: "calc(100vh - 320px)", md: "calc(100vh - 280px)", xl: "calc(100vh - 220px)" } }, tooltipAtom: tooltipAtom, TooltipContent: ({ tooltip }) => (_jsx(CycleChartTooltip, { tooltip: tooltip, seriesLabel: props.series_label, extraTooltip: props.extra_tooltip })), chart: ({ width, height }) => (_jsx(CycleChartSvg, { ...props, containerHeight: height, containerWidth: width, series: series, median: median, yZoom: props.yZoom, setYZoom: props.setYZoom, highlightStart: highlightStart, setHighlightStart: setHighlightStart, showTooltip: setTooltip, disabledSeries: disabledSeries })) }), _jsxs("div", { style: { display: "flex", flexWrap: "wrap" }, children: [_jsx("div", { style: { color: "#6b6b76" }, children: "Click on a point for details" }), _jsx("div", { style: { flexGrow: 1 } }), _jsx(ChartZoomButtons, { set_date_zoom_range: props.set_date_zoom_range, current_date_zoom: props.current_date_zoom, yZoom: props.yZoom, setYZoom: props.setYZoom, median: median })] }), _jsx(Legend, { series: series, disabledSeries: disabledSeries, adjustDisabled: setDisabled })] }));
|
|
281
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ComponentType, SetStateAction, MouseEvent, ReactNode, PureComponent } from "react";
|
|
2
|
+
import { ToComparable, ToComparableBase } from "@seedtactics/immutable-collections";
|
|
3
|
+
import { SelectedAnalysisPeriod } from "../../network/load-specific-month.js";
|
|
4
|
+
import { WritableAtom } from "jotai";
|
|
5
|
+
export type Column<Id, Row> = {
|
|
6
|
+
readonly id: Id;
|
|
7
|
+
readonly numeric: boolean;
|
|
8
|
+
readonly label: string;
|
|
9
|
+
readonly getDisplay: (c: Row) => string;
|
|
10
|
+
readonly getForSort?: ToComparableBase<Row>;
|
|
11
|
+
readonly getForExport?: (c: Row) => string;
|
|
12
|
+
readonly Cell?: ComponentType<{
|
|
13
|
+
readonly row: Row;
|
|
14
|
+
}>;
|
|
15
|
+
readonly expanded?: boolean;
|
|
16
|
+
readonly ignoreDuringExport?: boolean;
|
|
17
|
+
readonly openFilterDialog?: WritableAtom<unknown, [boolean], unknown>;
|
|
18
|
+
};
|
|
19
|
+
export type ColSort<Id, Row> = {
|
|
20
|
+
readonly orderBy: Id;
|
|
21
|
+
readonly order: "asc" | "desc";
|
|
22
|
+
readonly sortOn: ToComparable<Row>;
|
|
23
|
+
readonly handleRequestSort: (property: Id) => void;
|
|
24
|
+
};
|
|
25
|
+
export type TablePage = {
|
|
26
|
+
readonly page: number;
|
|
27
|
+
readonly rowsPerPage: number;
|
|
28
|
+
readonly setPage: (p: number) => void;
|
|
29
|
+
readonly setRowsPerPage: (r: SetStateAction<number>) => void;
|
|
30
|
+
};
|
|
31
|
+
export type DataTableActionZoomIntoRange = {
|
|
32
|
+
readonly type: "ZoomIntoRange";
|
|
33
|
+
readonly default_date_range: Date[];
|
|
34
|
+
readonly current_date_zoom: {
|
|
35
|
+
start: Date;
|
|
36
|
+
end: Date;
|
|
37
|
+
} | undefined;
|
|
38
|
+
readonly set_date_zoom_range: (p: {
|
|
39
|
+
start: Date;
|
|
40
|
+
end: Date;
|
|
41
|
+
} | undefined) => void;
|
|
42
|
+
};
|
|
43
|
+
export type DataTableActionZoom = {
|
|
44
|
+
readonly type: "Last30Days";
|
|
45
|
+
readonly set_days_back: (numDaysBack: number | null) => void;
|
|
46
|
+
} | DataTableActionZoomIntoRange | {
|
|
47
|
+
readonly type: "ExtendDays";
|
|
48
|
+
readonly curStart: Date;
|
|
49
|
+
readonly curEnd: Date;
|
|
50
|
+
readonly extend: (numDays: number) => void;
|
|
51
|
+
};
|
|
52
|
+
export type TableZoom = {
|
|
53
|
+
readonly zoomRange: {
|
|
54
|
+
readonly start: Date;
|
|
55
|
+
readonly end: Date;
|
|
56
|
+
} | undefined;
|
|
57
|
+
readonly zoom: DataTableActionZoom | undefined;
|
|
58
|
+
};
|
|
59
|
+
export declare function DataTableHead<Id extends string | number, Row>(props: {
|
|
60
|
+
readonly sort: ColSort<Id, Row>;
|
|
61
|
+
readonly columns: ReadonlyArray<Column<Id, Row>>;
|
|
62
|
+
readonly showDetailsCol: boolean;
|
|
63
|
+
readonly copyToClipboardRows?: Iterable<Row>;
|
|
64
|
+
}): ReactNode;
|
|
65
|
+
export declare const DataTableActions: import("react").NamedExoticComponent<{
|
|
66
|
+
readonly tpage: TablePage;
|
|
67
|
+
readonly count: number;
|
|
68
|
+
readonly zoom?: DataTableActionZoom;
|
|
69
|
+
}>;
|
|
70
|
+
export declare class DataTableBody<Id extends string | number, Row> extends PureComponent<{
|
|
71
|
+
readonly pageData: Iterable<Row>;
|
|
72
|
+
readonly columns: ReadonlyArray<Column<Id, Row>>;
|
|
73
|
+
readonly onClickDetails?: (event: MouseEvent, r: Row) => void;
|
|
74
|
+
readonly rowsPerPage?: number;
|
|
75
|
+
readonly emptyMessage?: string;
|
|
76
|
+
}> {
|
|
77
|
+
render(): ReactNode;
|
|
78
|
+
}
|
|
79
|
+
export declare function useTableZoomForPeriod(period: SelectedAnalysisPeriod): TableZoom;
|
|
80
|
+
export declare function useTablePage(): TablePage;
|
|
81
|
+
export declare function useColSort<Id, Row>(defSortCol: Id, cols: ReadonlyArray<Column<Id, Row>>, defOrder?: "asc" | "desc"): ColSort<Id, Row>;
|
|
82
|
+
export declare function buildClipboardTableAsString<Id, Row>(columns: ReadonlyArray<Column<Id, Row>>, rows: Iterable<Row>): string;
|
|
83
|
+
export declare function copyTableToClipboard<Id, Row>(columns: ReadonlyArray<Column<Id, Row>>, rows: Iterable<Row>): void;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/* Copyright (c) 2025, John Lenz
|
|
3
|
+
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
* Redistributions of source code must retain the above copyright
|
|
10
|
+
notice, this list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
* Redistributions in binary form must reproduce the above
|
|
13
|
+
copyright notice, this list of conditions and the following
|
|
14
|
+
disclaimer in the documentation and/or other materials provided
|
|
15
|
+
with the distribution.
|
|
16
|
+
|
|
17
|
+
* Neither the name of John Lenz, Black Maple Software, SeedTactics,
|
|
18
|
+
nor the names of other contributors may be used to endorse or
|
|
19
|
+
promote products derived from this software without specific
|
|
20
|
+
prior written permission.
|
|
21
|
+
|
|
22
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
23
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
24
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
25
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
26
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
27
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
28
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
29
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
30
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
31
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
32
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
33
|
+
*/
|
|
34
|
+
import { useState, memo, useMemo, PureComponent, } from "react";
|
|
35
|
+
import { Dialog, DialogActions, DialogContent, DialogTitle, styled, TableBody, TableCell, TableHead, TableRow, TableSortLabel, Tooltip, IconButton, Toolbar, Typography, Select, InputBase, MenuItem, Button, } from "@mui/material";
|
|
36
|
+
import { Calendar } from "react-calendar";
|
|
37
|
+
import { MoreHoriz, FirstPage as FirstPageIcon, KeyboardArrowLeft, KeyboardArrowRight, LastPage as LastPageIcon, ZoomOut as ZoomOutIcon, ZoomIn as ZoomInIcon, SkipPrevious as SkipPrevIcon, SkipNext as SkipNextIcon, ImportExport, FilterList, } from "@mui/icons-material";
|
|
38
|
+
import copy from "copy-to-clipboard";
|
|
39
|
+
import { addDays, addHours, addMonths } from "date-fns";
|
|
40
|
+
import { useSetAtom } from "jotai";
|
|
41
|
+
const DataCell = styled(TableCell, { shouldForwardProp: (p) => p !== "expand" })(({ expand }) => ({
|
|
42
|
+
width: expand ? "100%" : undefined,
|
|
43
|
+
}));
|
|
44
|
+
function OpenFilterButton({ open }) {
|
|
45
|
+
const setOpen = useSetAtom(open);
|
|
46
|
+
return (_jsx(Tooltip, { title: "Filter", enterDelay: 300, children: _jsx(IconButton, { onClick: () => setOpen(true), size: "small", children: _jsx(FilterList, {}) }) }));
|
|
47
|
+
}
|
|
48
|
+
export function DataTableHead(props) {
|
|
49
|
+
const clipboardRows = props.copyToClipboardRows;
|
|
50
|
+
return (_jsx(TableHead, { children: _jsxs(TableRow, { children: [props.columns.map((col) => (_jsxs(DataCell, { align: col.numeric ? "right" : "left", expand: col.expanded, sortDirection: props.sort.orderBy === col.id ? props.sort.order : false, children: [_jsx(Tooltip, { title: "Sort", placement: col.numeric ? "bottom-end" : "bottom-start", enterDelay: 300, children: _jsx(TableSortLabel, { active: props.sort.orderBy === col.id, direction: props.sort.order, onClick: () => props.sort.handleRequestSort(col.id), children: col.label }) }), col.openFilterDialog ? _jsx(OpenFilterButton, { open: col.openFilterDialog }) : undefined] }, col.id))), props.showDetailsCol ? (_jsx(DataCell, { padding: "checkbox", children: clipboardRows ? (_jsx(Tooltip, { title: "Copy to Clipboard", children: _jsx(IconButton, { style: { height: "25px", paddingTop: 0, paddingBottom: 0 }, onClick: () => copyTableToClipboard(props.columns, clipboardRows), size: "large", children: _jsx(ImportExport, {}) }) })) : undefined })) : undefined] }) }));
|
|
51
|
+
}
|
|
52
|
+
const dateFormat = new Intl.DateTimeFormat([], { year: "numeric", month: "short", day: "numeric" });
|
|
53
|
+
const monthFormat = new Intl.DateTimeFormat([], { year: "numeric", month: "long" });
|
|
54
|
+
const StyledCalendar = styled(Calendar)(({ theme }) => ({
|
|
55
|
+
width: "350px",
|
|
56
|
+
"& .react-calendar__month-view__weekdays": {
|
|
57
|
+
textAlign: "center",
|
|
58
|
+
textTransform: "uppercase",
|
|
59
|
+
fontWeight: "bold",
|
|
60
|
+
},
|
|
61
|
+
"& .react-calendar__tile": {
|
|
62
|
+
textAlign: "center",
|
|
63
|
+
padding: ".75em .5em",
|
|
64
|
+
margin: 0,
|
|
65
|
+
border: 0,
|
|
66
|
+
background: "none",
|
|
67
|
+
outline: "none",
|
|
68
|
+
cursor: "pointer",
|
|
69
|
+
"&:hover": {
|
|
70
|
+
backgroundColor: "rgb(230, 230, 230)",
|
|
71
|
+
},
|
|
72
|
+
"&--active": {
|
|
73
|
+
backgroundColor: theme.palette.primary.light,
|
|
74
|
+
"&:hover": {
|
|
75
|
+
backgroundColor: theme.palette.primary.dark,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
// react-calendar__tile--hover is when selecting range of days.
|
|
80
|
+
"&.react-calendar--selectRange .react-calendar__tile--hover": {
|
|
81
|
+
backgroundColor: "rgb(230, 230, 230)",
|
|
82
|
+
},
|
|
83
|
+
}));
|
|
84
|
+
function SelectDateRange(props) {
|
|
85
|
+
const [open, setOpen] = useState(false);
|
|
86
|
+
const start = props.zoom.current_date_zoom
|
|
87
|
+
? props.zoom.current_date_zoom.start
|
|
88
|
+
: props.zoom.default_date_range[0];
|
|
89
|
+
const end = addDays(props.zoom.current_date_zoom ? props.zoom.current_date_zoom.end : props.zoom.default_date_range[1], -1);
|
|
90
|
+
function onChange(d) {
|
|
91
|
+
props.zoom.set_date_zoom_range({
|
|
92
|
+
start: d[0],
|
|
93
|
+
end: addDays(d[1], 1),
|
|
94
|
+
});
|
|
95
|
+
setOpen(false);
|
|
96
|
+
}
|
|
97
|
+
// @types/react-calendar has the wrong type for onChange
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
|
|
99
|
+
const matchingOnChange = onChange;
|
|
100
|
+
return (_jsxs(_Fragment, { children: [_jsxs("span", { children: [dateFormat.format(props.zoom.current_date_zoom?.start ?? props.zoom.default_date_range[0]), " -", " ", dateFormat.format(props.zoom.current_date_zoom?.end ?? props.zoom.default_date_range[1])] }), _jsx(Tooltip, { title: "Zoom To Date Range", children: _jsx(IconButton, { onClick: () => setOpen(true), size: "large", children: _jsx(ZoomInIcon, {}) }) }), _jsx(Tooltip, { title: "Reset Date Range", children: _jsx(IconButton, { onClick: () => props.zoom.set_date_zoom_range(undefined), size: "large", children: _jsx(ZoomOutIcon, {}) }) }), _jsxs(Dialog, { open: open, onClose: () => setOpen(false), children: [_jsxs(DialogTitle, { children: ["Select Date Range ", monthFormat.format(props.zoom.default_date_range[0])] }), _jsx(DialogContent, { children: _jsx(StyledCalendar, { minDate: props.zoom.default_date_range[0], maxDate: props.zoom.default_date_range[1], calendarType: "gregory", selectRange: true, showNavigation: false, showNeighboringMonth: false, value: [start, end], onChange: matchingOnChange }) }), _jsx(DialogActions, { children: _jsx(Button, { onClick: () => setOpen(false), children: "Close" }) })] })] }));
|
|
101
|
+
}
|
|
102
|
+
export const DataTableActions = memo(function DataTableActions({ zoom, tpage, count, }) {
|
|
103
|
+
let zoomCtrl;
|
|
104
|
+
if (zoom && zoom.type === "Last30Days") {
|
|
105
|
+
zoomCtrl = (_jsxs(_Fragment, { children: [_jsx(Tooltip, { title: "Last 24 hours", children: _jsx(Button, { onClick: () => zoom.set_days_back(1), style: { color: "rgba(0, 0, 0, 0.54)" }, children: "24h" }) }), _jsx(Tooltip, { title: "Last 2 days", children: _jsx(Button, { onClick: () => zoom.set_days_back(2), style: { color: "rgba(0, 0, 0, 0.54)" }, children: "2d" }) }), _jsx(Tooltip, { title: "Last 3 days", children: _jsx(Button, { onClick: () => zoom.set_days_back(3), style: { color: "rgba(0, 0, 0, 0.54)" }, children: "3d" }) }), _jsx(Tooltip, { title: "Last 4 days", children: _jsx(Button, { onClick: () => zoom.set_days_back(4), style: { color: "rgba(0, 0, 0, 0.54)" }, children: "4d" }) }), _jsx(Tooltip, { title: "Last 5 days", children: _jsx(Button, { onClick: () => zoom.set_days_back(5), style: { color: "rgba(0, 0, 0, 0.54)" }, children: "5d" }) }), _jsx(Tooltip, { title: "Last 6 days", children: _jsx(Button, { onClick: () => zoom.set_days_back(6), style: { color: "rgba(0, 0, 0, 0.54)" }, children: "6d" }) }), _jsx(Tooltip, { title: "Last 1 week", children: _jsx(Button, { onClick: () => zoom.set_days_back(7), style: { color: "rgba(0, 0, 0, 0.54)" }, children: "1w" }) }), _jsx(Tooltip, { title: "Last 2 weeks", children: _jsx(Button, { onClick: () => zoom.set_days_back(7 * 2), style: { color: "rgba(0, 0, 0, 0.54)" }, children: "2w" }) }), _jsx(Tooltip, { title: "Last 3 weeks", children: _jsx(Button, { onClick: () => zoom.set_days_back(7 * 3), style: { color: "rgba(0, 0, 0, 0.54)" }, children: "3w" }) }), _jsx(Tooltip, { title: "Last 30 days", children: _jsx(Button, { onClick: () => zoom.set_days_back(null), style: { color: "rgba(0, 0, 0, 0.54)" }, children: "30d" }) })] }));
|
|
106
|
+
}
|
|
107
|
+
else if (zoom && zoom.type === "ZoomIntoRange") {
|
|
108
|
+
zoomCtrl = _jsx(SelectDateRange, { zoom: zoom });
|
|
109
|
+
}
|
|
110
|
+
else if (zoom && zoom.type === "ExtendDays") {
|
|
111
|
+
zoomCtrl = (_jsxs(_Fragment, { children: [_jsx(Tooltip, { title: "Extend 1 day previous", children: _jsx(IconButton, { onClick: () => zoom.extend(-1), size: "large", children: _jsx(SkipPrevIcon, {}) }) }), _jsx(Typography, { variant: "caption", children: zoom.curStart.toLocaleDateString() + " to " + zoom.curEnd.toLocaleDateString() }), _jsx(Tooltip, { title: "Extend 1 day", children: _jsx(IconButton, { onClick: () => zoom.extend(1), size: "large", children: _jsx(SkipNextIcon, {}) }) })] }));
|
|
112
|
+
}
|
|
113
|
+
return (_jsxs(Toolbar, { children: [_jsx(Typography, { color: "textSecondary", variant: "caption", children: "Rows per page:" }), _jsx(Select, { style: { marginLeft: 8, marginRight: "1em" }, value: tpage.rowsPerPage, SelectDisplayProps: { style: { color: "rgba(0, 0, 0, 0.54)" } }, input: _jsx(InputBase, {}), onChange: (evt) => {
|
|
114
|
+
tpage.setRowsPerPage(evt.target.value);
|
|
115
|
+
const maxPage = Math.ceil(count / evt.target.value) - 1;
|
|
116
|
+
if (tpage.page > maxPage) {
|
|
117
|
+
tpage.setPage(maxPage);
|
|
118
|
+
}
|
|
119
|
+
}, children: [10, 15, 20, 50].map((rowsPerPageOption) => (_jsx(MenuItem, { value: rowsPerPageOption, children: rowsPerPageOption }, rowsPerPageOption))) }), _jsx(Typography, { color: "textSecondary", variant: "caption", children: `${count === 0 ? 0 : tpage.page * tpage.rowsPerPage + 1}-${Math.min(count, (tpage.page + 1) * tpage.rowsPerPage)} of ${count}` }), _jsx(IconButton, { onClick: () => tpage.setPage(0), disabled: tpage.page === 0, "aria-label": "First Page", size: "large", children: _jsx(FirstPageIcon, {}) }), _jsx(IconButton, { onClick: () => tpage.setPage(tpage.page - 1), disabled: tpage.page === 0, "aria-label": "Previous Page", size: "large", children: _jsx(KeyboardArrowLeft, {}) }), _jsx(IconButton, { onClick: () => tpage.setPage(tpage.page + 1), disabled: tpage.page >= Math.ceil(count / tpage.rowsPerPage) - 1, "aria-label": "Next Page", size: "large", children: _jsx(KeyboardArrowRight, {}) }), _jsx(IconButton, { onClick: () => tpage.setPage(Math.max(0, Math.ceil(count / tpage.rowsPerPage) - 1)), disabled: tpage.page >= Math.ceil(count / tpage.rowsPerPage) - 1, "aria-label": "Last Page", size: "large", children: _jsx(LastPageIcon, {}) }), zoom ? (_jsxs(_Fragment, { children: [_jsx("div", { style: { flexGrow: 1 } }), zoomCtrl] })) : undefined] }));
|
|
120
|
+
});
|
|
121
|
+
// This is a class component because memo of a function component doesn't infer the column/row
|
|
122
|
+
// types correctly.
|
|
123
|
+
export class DataTableBody extends PureComponent {
|
|
124
|
+
render() {
|
|
125
|
+
const onClickDetails = this.props.onClickDetails;
|
|
126
|
+
const rows = [...this.props.pageData];
|
|
127
|
+
const emptyRows = this.props.rowsPerPage !== undefined ? Math.max(0, this.props.rowsPerPage - rows.length) : 0;
|
|
128
|
+
return (_jsxs(TableBody, { children: [rows.map((row, idx) => (_jsxs(TableRow, { children: [this.props.columns.map((col) => (_jsx(DataCell, { align: col.numeric ? "right" : "left", expand: col.expanded, children: col.Cell ? _jsx(col.Cell, { row: row }) : col.getDisplay(row) }, col.id))), onClickDetails ? (_jsx(DataCell, { padding: "checkbox", children: _jsx(IconButton, { onClick: (e) => onClickDetails(e, row), size: "large", children: _jsx(MoreHoriz, {}) }) })) : undefined] }, idx))), emptyRows > 0 ? (_jsx(TableRow, { style: { height: 53 * emptyRows }, children: _jsx(TableCell, { colSpan: this.props.columns.length + (this.props.onClickDetails ? 1 : 0), style: { textAlign: "center" }, children: rows.length === 0 ? this.props.emptyMessage : undefined }) })) : undefined] }));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
export function useTableZoomForPeriod(period) {
|
|
132
|
+
const [curZoom, setCurZoom] = useState(undefined);
|
|
133
|
+
return useMemo(() => {
|
|
134
|
+
let zoom;
|
|
135
|
+
if (period.type === "Last30") {
|
|
136
|
+
zoom = {
|
|
137
|
+
type: "Last30Days",
|
|
138
|
+
set_days_back: (numDaysBack) => {
|
|
139
|
+
if (numDaysBack) {
|
|
140
|
+
const now = new Date();
|
|
141
|
+
setCurZoom({ start: addDays(now, -numDaysBack), end: addHours(now, 1) });
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
setCurZoom(undefined);
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
zoom = {
|
|
151
|
+
type: "ZoomIntoRange",
|
|
152
|
+
default_date_range: [period.month, addMonths(period.month, 1)],
|
|
153
|
+
current_date_zoom: curZoom,
|
|
154
|
+
set_date_zoom_range: setCurZoom,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
return { zoom, zoomRange: curZoom };
|
|
158
|
+
}, [period, curZoom, setCurZoom]);
|
|
159
|
+
}
|
|
160
|
+
export function useTablePage() {
|
|
161
|
+
const [page, setPage] = useState(0);
|
|
162
|
+
const [rowsPerPage, setRowsPerPage] = useState(10);
|
|
163
|
+
return useMemo(() => ({ page, setPage, rowsPerPage, setRowsPerPage }), [page, setPage, rowsPerPage, setRowsPerPage]);
|
|
164
|
+
}
|
|
165
|
+
export function useColSort(defSortCol, cols, defOrder) {
|
|
166
|
+
const [orderBy, setOrderBy] = useState(defSortCol);
|
|
167
|
+
const [order, setOrder] = useState(defOrder ?? "asc");
|
|
168
|
+
return useMemo(() => {
|
|
169
|
+
function handleRequestSort(property) {
|
|
170
|
+
if (orderBy === property) {
|
|
171
|
+
setOrder(order === "asc" ? "desc" : "asc");
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
setOrderBy(property);
|
|
175
|
+
setOrder("asc");
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
let sortOn = {
|
|
179
|
+
asc: cols[0].getForSort ?? cols[0].getDisplay,
|
|
180
|
+
};
|
|
181
|
+
for (const col of cols) {
|
|
182
|
+
if (col.id === orderBy && order === "asc") {
|
|
183
|
+
sortOn = { asc: col.getForSort ?? col.getDisplay };
|
|
184
|
+
}
|
|
185
|
+
else if (col.id === orderBy) {
|
|
186
|
+
sortOn = { desc: col.getForSort ?? col.getDisplay };
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return { orderBy, order, sortOn, handleRequestSort };
|
|
190
|
+
}, [orderBy, setOrderBy, order, setOrder, cols]);
|
|
191
|
+
}
|
|
192
|
+
export function buildClipboardTableAsString(columns, rows) {
|
|
193
|
+
let table = "<table>\n<thead><tr>";
|
|
194
|
+
for (const col of columns) {
|
|
195
|
+
if (!col.ignoreDuringExport) {
|
|
196
|
+
table += "<th>" + col.label + "</th>";
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
table += "</tr></thead>\n<tbody>\n";
|
|
200
|
+
for (const row of rows) {
|
|
201
|
+
table += "<tr>";
|
|
202
|
+
for (const col of columns) {
|
|
203
|
+
if (!col.ignoreDuringExport) {
|
|
204
|
+
const val = col.getForExport ? col.getForExport(row) : col.getDisplay(row);
|
|
205
|
+
table += "<td>" + val + "</td>";
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
table += "</tr>\n";
|
|
209
|
+
}
|
|
210
|
+
table += "</tbody>\n</table>";
|
|
211
|
+
return table;
|
|
212
|
+
}
|
|
213
|
+
export function copyTableToClipboard(columns, rows) {
|
|
214
|
+
copy(buildClipboardTableAsString(columns, rows));
|
|
215
|
+
}
|