Skip to content

Commit

Permalink
fix: prefer sysinfo over cpuplot name in vars
Browse files Browse the repository at this point in the history
  • Loading branch information
oneirocosm committed Oct 17, 2024
1 parent ee292ac commit eb64c34
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
12 changes: 7 additions & 5 deletions frontend/app/block/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { getWaveObjectAtom, makeORef, useWaveObjectValue } from "@/store/wos";
import { focusedBlockId, getElemAsStr } from "@/util/focusutil";
import { isBlank } from "@/util/util";
import { CpuPlotView, CpuPlotViewModel, makeCpuPlotViewModel } from "@/view/cpuplot/cpuplot";
import { SysinfoView, SysinfoViewModel, makeSysinfoViewModel } from "@/view/cpuplot/cpuplot";
import { HelpView, HelpViewModel, makeHelpViewModel } from "@/view/helpview/helpview";
import { QuickTipsView, QuickTipsViewModel } from "@/view/quicktipsview/quicktipsview";
import { TermViewModel, TerminalView, makeTerminalModel } from "@/view/term/term";
Expand Down Expand Up @@ -47,8 +47,9 @@ function makeViewModel(blockId: string, blockView: string, nodeModel: NodeModel)
if (blockView === "waveai") {
return makeWaveAiViewModel(blockId);
}
if (blockView === "cpuplot") {
return makeCpuPlotViewModel(blockId);
if (blockView === "cpuplot" || blockView == "sysinfo") {
// "cpuplot" is for backwards compatibility with already-opened widgets
return makeSysinfoViewModel(blockId, blockView);
}
if (blockView === "help") {
return makeHelpViewModel(blockId, nodeModel);
Expand Down Expand Up @@ -89,8 +90,9 @@ function getViewElem(
if (blockView === "waveai") {
return <WaveAi key={blockId} blockId={blockId} model={viewModel as WaveAiModel} />;
}
if (blockView === "cpuplot") {
return <CpuPlotView key={blockId} blockId={blockId} model={viewModel as CpuPlotViewModel} />;
if (blockView === "cpuplot" || blockView === "sysinfo") {
// "cpuplot" is for backwards compatibility with already opened widgets
return <SysinfoView key={blockId} blockId={blockId} model={viewModel as SysinfoViewModel} />;
}
if (blockView == "help") {
return <HelpView key={blockId} model={viewModel as HelpViewModel} />;
Expand Down
29 changes: 14 additions & 15 deletions frontend/app/view/cpuplot/cpuplot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { OverlayScrollbarsComponent, OverlayScrollbarsComponentRef } from "overl
import "./cpuplot.less";

const DefaultNumPoints = 120;
type LineType = "default" | "title" | "sparkline";

type DataItem = {
ts: number;
Expand Down Expand Up @@ -87,7 +86,7 @@ function convertWaveEventToDataItem(event: WaveEvent): DataItem {
return dataItem;
}

class CpuPlotViewModel {
class SysinfoViewModel {
viewType: string;
blockAtom: jotai.Atom<Block>;
termMode: jotai.Atom<string>;
Expand All @@ -109,8 +108,8 @@ class CpuPlotViewModel {
endIconButtons: jotai.Atom<IconButtonDecl[]>;
plotTypeSelectedAtom: jotai.Atom<string>;

constructor(blockId: string) {
this.viewType = "cpuplot";
constructor(blockId: string, viewType: string) {
this.viewType = viewType;
this.blockId = blockId;
this.blockAtom = WOS.getWaveObjectAtom<Block>(`block:${blockId}`);
this.addDataAtom = jotai.atom(null, (get, set, points) => {
Expand All @@ -127,7 +126,7 @@ class CpuPlotViewModel {
const newData = [...data.slice(points.length), ...points];
set(this.dataAtom, newData);
} catch (e) {
console.log("Error adding data to cpuplot", e);
console.log("Error adding data to sysinfo", e);
}
});
this.plotMetaAtom = jotai.atom(new Map(Object.entries(DefaultPlotMeta)));
Expand Down Expand Up @@ -213,7 +212,7 @@ class CpuPlotViewModel {
newData.splice(newData.length - initialDataItems.length, initialDataItems.length, ...initialDataItems);
globalStore.set(this.addDataAtom, newData);
} catch (e) {
console.log("Error loading initial data for cpuplot", e);
console.log("Error loading initial data for sysinfo", e);
} finally {
globalStore.set(this.loadingAtom, false);
}
Expand Down Expand Up @@ -271,16 +270,16 @@ class CpuPlotViewModel {
}
}

function makeCpuPlotViewModel(blockId: string): CpuPlotViewModel {
const cpuPlotViewModel = new CpuPlotViewModel(blockId);
return cpuPlotViewModel;
function makeSysinfoViewModel(blockId: string, viewType: string): SysinfoViewModel {
const sysinfoViewModel = new SysinfoViewModel(blockId, viewType);
return sysinfoViewModel;
}

const plotColors = ["#58C142", "#FFC107", "#FF5722", "#2196F3", "#9C27B0", "#00BCD4", "#FFEB3B", "#795548"];

type CpuPlotViewProps = {
type SysinfoViewProps = {
blockId: string;
model: CpuPlotViewModel;
model: SysinfoViewModel;
};

function resolveDomainBound(value: number | string, dataItem: DataItem): number | undefined {
Expand All @@ -293,7 +292,7 @@ function resolveDomainBound(value: number | string, dataItem: DataItem): number
}
}

function CpuPlotView({ model, blockId }: CpuPlotViewProps) {
function SysinfoView({ model, blockId }: SysinfoViewProps) {
const connName = jotai.useAtomValue(model.connection);
const lastConnName = React.useRef(connName);
const connStatus = jotai.useAtomValue(model.connStatus);
Expand Down Expand Up @@ -333,7 +332,7 @@ function CpuPlotView({ model, blockId }: CpuPlotViewProps) {
if (loading) {
return null;
}
return <CpuPlotViewInner key={connStatus?.connection ?? "local"} blockId={blockId} model={model} />;
return <SysinfoViewInner key={connStatus?.connection ?? "local"} blockId={blockId} model={model} />;
}

type SingleLinePlotProps = {
Expand Down Expand Up @@ -458,7 +457,7 @@ function SingleLinePlot({
return <div ref={containerRef} className="sysinfo-plot-content" />;
}

const CpuPlotViewInner = React.memo(({ model }: CpuPlotViewProps) => {
const SysinfoViewInner = React.memo(({ model }: SysinfoViewProps) => {
const plotData = jotai.useAtomValue(model.dataAtom);
const yvals = jotai.useAtomValue(model.metrics);
const plotMeta = jotai.useAtomValue(model.plotMetaAtom);
Expand Down Expand Up @@ -493,4 +492,4 @@ const CpuPlotViewInner = React.memo(({ model }: CpuPlotViewProps) => {
);
});

export { CpuPlotView, CpuPlotViewModel, makeCpuPlotViewModel };
export { makeSysinfoViewModel, SysinfoView, SysinfoViewModel };
6 changes: 3 additions & 3 deletions pkg/wconfig/defaultconfig/defaultwidgets.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
}
}
},
"defwidget@cpuplot": {
"defwidget@sysinfo": {
"display:order": 5,
"icon": "chart-line",
"label": "cpu",
"label": "sysinfo",
"blockdef": {
"meta": {
"view": "cpuplot"
"view": "sysinfo"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/wlayout/wlayout.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func GetStarterLayout() PortableLayout {
}, Focused: true},
{IndexArr: []int{1}, BlockDef: &waveobj.BlockDef{
Meta: waveobj.MetaMapType{
waveobj.MetaKey_View: "cpuplot",
waveobj.MetaKey_View: "sysinfo",
},
}},
{IndexArr: []int{1, 1}, BlockDef: &waveobj.BlockDef{
Expand Down
4 changes: 2 additions & 2 deletions pkg/wshrpc/wshserver/wshserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func MakePlotData(ctx context.Context, blockId string) error {
return err
}
viewName := block.Meta.GetString(waveobj.MetaKey_View, "")
if viewName != "cpuplot" {
if viewName != "cpuplot" && viewName != "sysinfo" {
return fmt.Errorf("invalid view type: %s", viewName)
}
return filestore.WFS.MakeFile(ctx, blockId, "cpuplotdata", nil, filestore.FileOptsType{})
Expand All @@ -95,7 +95,7 @@ func SavePlotData(ctx context.Context, blockId string, history string) error {
return err
}
viewName := block.Meta.GetString(waveobj.MetaKey_View, "")
if viewName != "cpuplot" {
if viewName != "cpuplot" && viewName != "sysinfo" {
return fmt.Errorf("invalid view type: %s", viewName)
}
// todo: interpret the data being passed
Expand Down

0 comments on commit eb64c34

Please sign in to comment.