Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canvas Support #927

Open
ohmygaugh-crypto opened this issue Feb 25, 2024 · 19 comments
Open

Canvas Support #927

ohmygaugh-crypto opened this issue Feb 25, 2024 · 19 comments
Labels
enhancement New feature or request

Comments

@ohmygaugh-crypto
Copy link

Is your feature request related to a problem? Please describe.
Just want to be able to present my digital garden in a canvas format for coding tutorials.

Describe the solution you'd like
Support Obsidian.canvas files

Describe alternatives you've considered
BrainPress

Obsidian-webpage-export

Additional context
image

I might just utilize the aforementioned plugin in conjunction with quartz.

@ohmygaugh-crypto ohmygaugh-crypto added the enhancement New feature or request label Feb 25, 2024
@ahmed2m
Copy link

ahmed2m commented Mar 11, 2024

Obsidian just released the JSON canvas blog post and the spec.

However no word yet if they are going to release their own renderer for it.

@saberzero1
Copy link
Collaborator

Obsidian canvas type definitions:

https://github.com/obsidianmd/obsidian-api/blob/master/canvas.d.ts

I'll see if I can throw something together.

@metruzanca
Copy link

Been using quartz for a while now, very pleased. With jsoncanvas spec being open sourced and very little things being made with it so far, it seems so fresh and fun to make something cool with it.

@saberzero1 I would also be interested in helping with this feature. Though I'm not sure what is exactly feasible with quartz; beyond plugins, I've not really looked into its internals too much (I just patched a few things for personal use).

In obsidian the canvas is a full page thing (that can of course like other pages, be embedded). In quartz, AFAIK, there's currently only a markdown renderer, so I believe to add canvas support we'd need to add a different type of page that can be rendered.

@saberzero1
Copy link
Collaborator

Been using quartz for a while now, very pleased. With jsoncanvas spec being open sourced and very little things being made with it so far, it seems so fresh and fun to make something cool with it.

@saberzero1 I would also be interested in helping with this feature. Though I'm not sure what is exactly feasible with quartz; beyond plugins, I've not really looked into its internals too much (I just patched a few things for personal use).

In obsidian the canvas is a full page thing (that can of course like other pages, be embedded). In quartz, AFAIK, there's currently only a markdown renderer, so I believe to add canvas support we'd need to add a different type of page that can be rendered.

I'm working on a proof of concept for now. I have a very barebones version that turns the JSON content inside a .canvas files into basic html. Then, parses that html to a Element tree. It then adds that to the data as canvas. Then, I present it to the Obsidian Flavored Markdown renderer as markdown, which will render it as a "canvas" pages if data.canvas !== undefined.

I'll open a draft pull request later to keep track of progress and to allow feedback. The goal for now is not to get it all perfect. It's just to see how feasible it is. Once we have a working proof of concept, then we can discuss semantics/styling/etc.

@jackyzha0
Copy link
Owner

@saberzero1 how are you displaying it on the web side? just HTML elements or are you doing something with D3 or canvas?

@saberzero1
Copy link
Collaborator

@saberzero1 how are you displaying it on the web side? just HTML elements or are you doing something with D3 or canvas?

Currently in plain html with absolute positioning html elements. The canvas specification gives x and y coordinates as well as width and height, all in pixels. I'll have to look some more into connecting the elements with lines similar as canvas.

D3 is an option, as well as canvas, but I am unsure about the performance of a larger/populated canvas. Obsidian's implementation in-app is based on plain html and four anchor points on every element. Every connection has a four values: the source node, the target node, the side to start from (up, down, left, or right) on the source node, and the side to connect in the target.

Furthermore, we might want some changes on the sidebar displays when in canvas, especially on mobile. But that is something we'll tackle when we get there I guess.

@jackyzha0
Copy link
Owner

Does the Obsidian Canvas implementation allow panning and zooming of the canvas? If not, perfectly happy going down the HTML route

@saberzero1
Copy link
Collaborator

Does the Obsidian Canvas implementation allow panning and zooming of the canvas? If not, perfectly happy going down the HTML route

Sort of.

Obsidian canvas is not exactly a canvas, although it behaves as one. Obsidian's canvas allows panning and zooming, but it is all divs, no <canvas> element.

They achieve this by applying css transforms: translates for the panning and scale for zooming. This give the illusion of a canvas, but with the performance of plain html.

@jackyzha0
Copy link
Owner

<canvas> is actually much more performant for large boards so the perf tradeoff is a bit weird there (though I doubt people have enough things on their canvas where it matters anyways)

@saberzero1
Copy link
Collaborator

<canvas> is actually much more performant for large boards so the perf tradeoff is a bit weird there (though I doubt people have enough things on their canvas where it matters anyways)

I guess another consideration is that Obsidian allows markdown embedding inside nodes. As in, transcluding markdown files, as well as websites (as iframe). A html-based approach would allow for more familiar Quartz functionality (popovers mostly), while keeping behavior consistent with Obsidian.

I'll look more into the canvas element after I have a basic implementation of the full Obsidian Canvas specification down.

@saberzero1
Copy link
Collaborator

There is an ongoing discussion inside the JSON Canvas specification repository about a proper JSON schema specification for JSON Canvas.

obsidianmd/jsoncanvas#10

@jackyzha0 Obsidian has an implementation of (a part) of their JSON Canvas specification inside their documentation. It looks promising. I could propose an implementation in Quartz based on their implementation, but theirs is Javascript-based, not Typescript-based. There are several pull request in the same repository aimed at a full JSON schema, which would allow for proper Typescript typings. I feel like it would be wise to wait for a consensus on the JSON schema specification before fully integrating in Quartz. What are your thoughts on this?

https://github.com/obsidianmd/jsoncanvas/blob/main/assets/canvas.js

https://github.com/obsidianmd/jsoncanvas/blob/main/.layouts/canvas.html

@franciscoabenza
Copy link

how can I find your branch @saberzero1 ?

@ThatTakashi
Copy link

This would be a great feature to see as part of quartz!

@zkhan96
Copy link

zkhan96 commented Oct 23, 2024

Whats the current workaround to rendering canvases?

@saberzero1
Copy link
Collaborator

Whats the current workaround to rendering canvases?

https://github.com/KosmosisDire/obsidian-webpage-export

Quartz currently does not support JSON Canvas. I want to eventually implement this, but there are several large milestones that I am currently focusing on first and the full specification for JSON Canvas has still not been fully decided on.

@cyber-arsenull
Copy link

cyber-arsenull commented Oct 27, 2024

Is there any tutorial around or resource on how to integrate a canvas exported through https://github.com/KosmosisDire/obsidian-webpage-export into quartz?

Edit:
I was able to get pretty far with:

  1. Generating HTML file using obsidian-webpage-export plugin from a canvas file
  2. Copying the HTML file to the same path in the contents/
  3. Copying over the lib folder generated by the plugin into contents/
  4. Put an iframe referencing the HTML file in a markdown file

The only issue is that I can't get the links in the canvas to correctly open in the browser rather than the iframe.
Even with target="_parent" in the <a> tag that has the link.

@gracchen
Copy link

any updates?

@franciscoabenza
Copy link

franciscoabenza commented Feb 23, 2025 via email

@DeanLemans
Copy link

bump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests