Add hideOnRoot option to Component.Graph

This commit is contained in:
josh-sanders 2025-03-13 23:34:16 +10:00
parent 95823ec855
commit b1fb710229
3 changed files with 19 additions and 8 deletions

View File

@ -142,5 +142,6 @@ Customization of the home page can be achieved by conditionally hiding or unhidi
- [[Breadcrumbs]] are hidden by default, to unhide them the configuration looks like: `Component.Breadcrumbs({ hideOnRoot: false }){:ts}` - [[Breadcrumbs]] are hidden by default, to unhide them the configuration looks like: `Component.Breadcrumbs({ hideOnRoot: false }){:ts}`
- Date and reading time are shown by default, to hide them the configuration looks like: `Component.ContentMeta({ hideOnRoot: true }){:ts}` - Date and reading time are shown by default, to hide them the configuration looks like: `Component.ContentMeta({ hideOnRoot: true }){:ts}`
- [[Explorer]] is shown by default, to hide it the configuration looks like: `Component.Explorer({ hideOnRoot: true }){:ts}` - [[Explorer]] is shown by default, to hide it the configuration looks like: `Component.Explorer({ hideOnRoot: true }){:ts}`
- [[Graph view]] is shown by default, to hide it the configuration looks like: `Component.Graph({ hideOnRoot: true }){:ts}`
A differnet method is used to configure the comment box on the home page, see [[Comments#Conditionally display comments|conditionally display comments]]. A differnet method is used to configure the comment box on the home page, see [[Comments#Conditionally display comments|conditionally display comments]].

View File

@ -23,7 +23,7 @@ Most configuration can be done by passing in options to `Component.Graph()`.
For example, here's what the default configuration looks like: For example, here's what the default configuration looks like:
```typescript title="quartz.layout.ts" ```typescript title="quartz.layout.ts"
Component.Graph({ const defaultOptions: GraphOptions = {
localGraph: { localGraph: {
drag: true, // whether to allow panning the view around drag: true, // whether to allow panning the view around
zoom: true, // whether to allow zooming in and out zoom: true, // whether to allow zooming in and out
@ -34,8 +34,9 @@ Component.Graph({
linkDistance: 30, // how long should the links be by default? linkDistance: 30, // how long should the links be by default?
fontSize: 0.6, // what size should the node labels be? fontSize: 0.6, // what size should the node labels be?
opacityScale: 1, // how quickly do we fade out the labels when zooming out? opacityScale: 1, // how quickly do we fade out the labels when zooming out?
removeTags: [], // what tags to remove from the graph
showTags: true, // whether to show tags in the graph showTags: true, // whether to show tags in the graph
removeTags: [], // what tags to remove from the graph
focusOnHover: false,
enableRadial: false, // whether to constrain the graph, similar to Obsidian enableRadial: false, // whether to constrain the graph, similar to Obsidian
}, },
globalGraph: { globalGraph: {
@ -44,15 +45,17 @@ Component.Graph({
depth: -1, depth: -1,
scale: 0.9, scale: 0.9,
repelForce: 0.5, repelForce: 0.5,
centerForce: 0.3, centerForce: 0.2,
linkDistance: 30, linkDistance: 30,
fontSize: 0.6, fontSize: 0.6,
opacityScale: 1, opacityScale: 1,
removeTags: [], // what tags to remove from the graph showTags: true,
showTags: true, // whether to show tags in the graph removeTags: [],
enableRadial: true, // whether to constrain the graph, similar to Obsidian focusOnHover: true,
enableRadial: true,
}, },
}) hideOnRoot: false
}
``` ```
When passing in your own options, you can omit any or all of these fields if you'd like to keep the default value for that field. When passing in your own options, you can omit any or all of these fields if you'd like to keep the default value for that field.

View File

@ -24,6 +24,7 @@ export interface D3Config {
interface GraphOptions { interface GraphOptions {
localGraph: Partial<D3Config> | undefined localGraph: Partial<D3Config> | undefined
globalGraph: Partial<D3Config> | undefined globalGraph: Partial<D3Config> | undefined
hideOnRoot: boolean
} }
const defaultOptions: GraphOptions = { const defaultOptions: GraphOptions = {
@ -57,10 +58,16 @@ const defaultOptions: GraphOptions = {
focusOnHover: true, focusOnHover: true,
enableRadial: true, enableRadial: true,
}, },
hideOnRoot: false
} }
export default ((opts?: Partial<GraphOptions>) => { export default ((opts?: Partial<GraphOptions>) => {
const Graph: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => { const Graph: QuartzComponent = ({ displayClass, fileData, cfg }: QuartzComponentProps) => {
// Hide graph on root if enabled
if (opts?.hideOnRoot && fileData.slug === "index") {
return null
}
const localGraph = { ...defaultOptions.localGraph, ...opts?.localGraph } const localGraph = { ...defaultOptions.localGraph, ...opts?.localGraph }
const globalGraph = { ...defaultOptions.globalGraph, ...opts?.globalGraph } const globalGraph = { ...defaultOptions.globalGraph, ...opts?.globalGraph }
return ( return (