Skip to content

Commit

Permalink
add GraphQL queries and components for PlotViews; update routing and …
Browse files Browse the repository at this point in the history
…create PlotViewCard and List components
  • Loading branch information
jhnnsrs committed Feb 24, 2025
1 parent 7907c8f commit a3eadc2
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 27 deletions.
6 changes: 6 additions & 0 deletions graphql/kraph/queries/plot_view.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ query LatestPlotViews {
}
}

query ListPlotViews {
plotViews {
...ListPlotView
}
}

query SearchPlotViews($search: String, $values: [ID!]) {
options: plotViews(
filters: { search: $search, ids: $values }
Expand Down
4 changes: 4 additions & 0 deletions src/kraph/KraphModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import NodePage from "./pages/NodePage";
import GraphViewPage from "./pages/GraphViewPage";
import NodeViewPage from "./pages/NodeViewPage";
import PlotViewPage from "./pages/PlotViewPage";
import GraphQueryPage from "./pages/GraphQueryPage";
import PlotViewsPage from "./pages/PlotViewsPage";
interface Props {}

export const KraphModule: React.FC<Props> = (props) => {
Expand All @@ -37,6 +39,8 @@ export const KraphModule: React.FC<Props> = (props) => {
<Route path="graphs" element={<GraphsPage />} />
<Route path="graphs/:id" element={<GraphPage />} />
<Route path="graphviews/:id" element={<GraphViewPage />} />
<Route path="graphqueries/:id" element={<GraphQueryPage />} />
<Route path="plotviews" element={<PlotViewsPage />} />
<Route path="plotviews/:id" element={<PlotViewPage />} />
<Route path="nodeviews/:id" element={<NodeViewPage />} />
<Route path="graphs/:id/view/:viewid" element={<GraphPage />} />
Expand Down
39 changes: 39 additions & 0 deletions src/kraph/api/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2642,6 +2642,11 @@ export type LatestPlotViewsQueryVariables = Exact<{ [key: string]: never; }>;

export type LatestPlotViewsQuery = { __typename?: 'Query', plotViews: Array<{ __typename?: 'PlotView', id: string, name: string, view: { __typename?: 'GraphView', id: string, label: string, render: { __typename?: 'Pairs' } | { __typename?: 'Path' } | { __typename?: 'Table', rows: Array<any>, columns: Array<{ __typename?: 'Column', name: string, kind: ColumnKind, valueKind?: MeasurementKind | null, description?: string | null, label?: string | null }>, graph: { __typename?: 'Graph', id: string, ageName: string } } }, plot: { __typename?: 'ScatterPlot', id: string, name: string, description?: string | null, xColumn: string, yColumn: string, colorColumn?: string | null, sizeColumn?: string | null } }> };

export type ListPlotViewsQueryVariables = Exact<{ [key: string]: never; }>;


export type ListPlotViewsQuery = { __typename?: 'Query', plotViews: Array<{ __typename?: 'PlotView', id: string, name: string, plot: { __typename?: 'ScatterPlot', id: string, name: string, description?: string | null, xColumn: string, yColumn: string, colorColumn?: string | null, sizeColumn?: string | null } }> };

export type SearchPlotViewsQueryVariables = Exact<{
search?: InputMaybe<Scalars['String']['input']>;
values?: InputMaybe<Array<Scalars['ID']['input']> | Scalars['ID']['input']>;
Expand Down Expand Up @@ -4899,6 +4904,40 @@ export function useLatestPlotViewsLazyQuery(baseOptions?: ApolloReactHooks.LazyQ
export type LatestPlotViewsQueryHookResult = ReturnType<typeof useLatestPlotViewsQuery>;
export type LatestPlotViewsLazyQueryHookResult = ReturnType<typeof useLatestPlotViewsLazyQuery>;
export type LatestPlotViewsQueryResult = Apollo.QueryResult<LatestPlotViewsQuery, LatestPlotViewsQueryVariables>;
export const ListPlotViewsDocument = gql`
query ListPlotViews {
plotViews {
...ListPlotView
}
}
${ListPlotViewFragmentDoc}`;

/**
* __useListPlotViewsQuery__
*
* To run a query within a React component, call `useListPlotViewsQuery` and pass it any options that fit your needs.
* When your component renders, `useListPlotViewsQuery` returns an object from Apollo Client that contains loading, error, and data properties
* you can use to render your UI.
*
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
*
* @example
* const { data, loading, error } = useListPlotViewsQuery({
* variables: {
* },
* });
*/
export function useListPlotViewsQuery(baseOptions?: ApolloReactHooks.QueryHookOptions<ListPlotViewsQuery, ListPlotViewsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return ApolloReactHooks.useQuery<ListPlotViewsQuery, ListPlotViewsQueryVariables>(ListPlotViewsDocument, options);
}
export function useListPlotViewsLazyQuery(baseOptions?: ApolloReactHooks.LazyQueryHookOptions<ListPlotViewsQuery, ListPlotViewsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return ApolloReactHooks.useLazyQuery<ListPlotViewsQuery, ListPlotViewsQueryVariables>(ListPlotViewsDocument, options);
}
export type ListPlotViewsQueryHookResult = ReturnType<typeof useListPlotViewsQuery>;
export type ListPlotViewsLazyQueryHookResult = ReturnType<typeof useListPlotViewsLazyQuery>;
export type ListPlotViewsQueryResult = Apollo.QueryResult<ListPlotViewsQuery, ListPlotViewsQueryVariables>;
export const SearchPlotViewsDocument = gql`
query SearchPlotViews($search: String, $values: [ID!]) {
options: plotViews(
Expand Down
29 changes: 29 additions & 0 deletions src/kraph/components/cards/PlotViewCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Card } from "@/components/ui/card";
import { KraphGraph, KraphOntology, KraphPlotView } from "@/linkers";
import { MateFinder } from "@/mates/types";
import { ListGraphFragment, ListOntologyFragment, ListPlotViewFragment } from "../../api/graphql";

interface Props {
item: ListPlotViewFragment;
mates?: MateFinder[];
}

const TheCard = ({ item, mates }: Props) => {
return (
<KraphPlotView.Smart object={item?.id} mates={mates}>
<Card className="px-2 py-2 h-20 transition-all ease-in-out duration-200 truncate">
<KraphPlotView.DetailLink
className={({ isActive } /* */) =>
"z-10 font-bold text-md mb-2 cursor-pointer " +
(isActive ? "text-primary-300" : "")
}
object={item.id}
>
{item?.name}
</KraphPlotView.DetailLink>
</Card>
</KraphPlotView.Smart>
);
};

export default TheCard;
37 changes: 37 additions & 0 deletions src/kraph/components/lists/PlotViewList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ListRender } from "@/components/layout/ListRender";
import { KraphPlotView, MikroDataset } from "@/linkers";
import {
OffsetPaginationInput,
OntologyFilter,
useListGraphsQuery,
useListOntologiesQuery,
useListPlotViewsQuery,
} from "../../api/graphql";
import OntologyCard from "../cards/OntologyCard";
import GraphCard from "../cards/GraphCard";
import PlotViewCard from "../cards/PlotViewCard";

export type Props = {
filters?: OntologyFilter;
pagination?: OffsetPaginationInput;
};

const List = ({ filters, pagination }: Props) => {
const { data, error, subscribeToMore, refetch } = useListPlotViewsQuery({
variables: { filters, pagination },
});

return (
<ListRender
array={data?.plotViews}
title={
<KraphPlotView.ListLink className="flex-0">Views</KraphPlotView.ListLink>
}
refetch={refetch}
>
{(ex, index) => <PlotViewCard key={index} item={ex} mates={[]} />}
</ListRender>
);
};

export default List;
38 changes: 12 additions & 26 deletions src/kraph/pages/GraphQueryPage.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { asDetailQueryRoute } from "@/app/routes/DetailQueryRoute";
import { MultiSidebar } from "@/components/layout/MultiSidebar";
import { Button } from "@/components/ui/button";
import { KraphGraph, KraphGraphQuery, KraphGraphView } from "@/linkers";
import { KraphGraph, KraphGraphQuery, KraphGraphView, KraphOntology } from "@/linkers";
import { useGetGraphQueryQuery } from "../api/graphql";

import { PathGraph } from "../components/renderers/graph/KnowledgeGraph";
import { GraphTable } from "../components/renderers/table/GraphTable";

import ScatterPlot from "../components/charts/scatterplot/ScatterPlot";
import { CypherSidebar } from "../components/sidebars/CypherSidebar";
import { CypherEditor } from "../components/cypher/CypherEditor";
import { Card } from "@/components/ui/card";

export default asDetailQueryRoute(useGetGraphQueryQuery, ({ data, refetch }) => {
return (
Expand Down Expand Up @@ -43,38 +45,22 @@ export default asDetailQueryRoute(useGetGraphQueryQuery, ({ data, refetch }) =>
<div className="grid md:grid-cols-12 gap-4 md:gap-8 xl:gap-20 md:items-center px-6 py-2">
<div className="col-span-5">
<h1 className="scroll-m-20 text-4xl font-extrabold tracking-tight lg:text-5xl">
{data.graphView.label}
{data.graphQuery.name}
</h1>
<p className="mt-3 text-xl text-muted-foreground">
<KraphGraph.DetailLink object={data.graphView.graph.id}>
{data.graphView.graph.name}
</KraphGraph.DetailLink>
<KraphOntology.DetailLink object={data.graphQuery.ontology.id}>
{data.graphQuery.ontology.name}
</KraphOntology.DetailLink>
</p>
</div>
</div>
<Card className="p-6 h-96">
<CypherEditor cypher={data.graphQuery.query} />
</Card>



<div className="p-6 h-full">
{data.graphView.render.__typename === "Pairs" && (
<div>Pair Rendering</div>
)}

{data.graphView.render.__typename === "Path" && (
<PathGraph path={data.graphView.render} />
)}


{data.graphView.render.__typename === "Table" && (
<>
<div className="p-6">
{data.graphView.query.scatterPlots.map((scatterPlot) => (
<ScatterPlot scatterPlot={scatterPlot} table={data.graphView.render}/>
))}
</div>
<GraphTable table={data.graphView.render} /></>

)}
</div>

</KraphGraphQuery.ModelPage>
);
});
65 changes: 65 additions & 0 deletions src/kraph/pages/PlotViewsPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { PageLayout } from "@/components/layout/PageLayout";
import { Card } from "@/components/ui/card";
import { FormDialogAction } from "@/components/ui/form-dialog-action";
import { KraphGraph } from "@/linkers";
import { PlusIcon } from "lucide-react";
import React from "react";
import { useNavigate } from "react-router-dom";
import GraphList from "../components/lists/GraphList";
import CreateGraphForm from "../forms/CreateGraphForm";
import PlotViewList from "../components/lists/PlotViewList";

export type IRepresentationScreenProps = {};

const Page: React.FC<IRepresentationScreenProps> = () => {
const navigate = useNavigate();

return (
<PageLayout
title="Graphs"
pageActions={
<div className="flex flex-row gap-2">
<>
<FormDialogAction
variant={"outline"}
size={"sm"}
label="Create"
description="Create a new Graph"
buttonChildren={
<>
<PlusIcon className="h-4 w-4 mr-2" />
Create
</>
}
onSubmit={(item) => {
console.log(item);
navigate(KraphGraph.linkBuilder(item.createGraph.id));
}}
>
<CreateGraphForm />
</FormDialogAction>
</>
</div>
}
>
<div className="p-6">
<div className="col-span-4 grid md:grid-cols-2 gap-4 md:gap-8 xl:gap-20 md:items-center mb-4">
<div>
<h1 className="scroll-m-20 text-4xl font-extrabold tracking-tight lg:text-5xl">
Your views
</h1>
<p className="mt-3 text-xl text-muted-foreground">
Graphs represent ways to organize your knowledge that you have
extracted from your data.
</p>
</div>
<Card className="w-full h-full flex-row relative"></Card>
</div>

<PlotViewList pagination={{ limit: 30 }} />
</div>
</PageLayout>
);
};

export default Page;
2 changes: 1 addition & 1 deletion src/kraph/panes/StandardPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const NavigationPane = (props: {}) => {
Graphs
</DroppableNavLink>
<DroppableNavLink
to="/kraph/renderedplots"
to="/kraph/plotviews"
className="flex flex-row w-full gap-3 rounded-lg text-muted-foreground transition-all hover:text-primary"
>
<FaChartArea className="h-4 w-4" />
Expand Down

0 comments on commit a3eadc2

Please sign in to comment.