DylanHojnoski / obsidian-graphs

Plugin for Obsidian that renders interactive graphs from YAML.
GNU General Public License v3.0
26 stars 1 forks source link

Question about x-axis bounds #18

Open Eneswar opened 2 weeks ago

Eneswar commented 2 weeks ago

Lets say I have this graph:

bounds: [-2,7,7,-2]
elements: [
    {type: "point", def: [4,5], att: {withLabel: false}},
    {type: "arrow", def: [[0,0],"e0"], att: {strokeColor: "red", fillOpacity: 1, name: "(a, b)", withLabel: true}},
    {type: "point", def: [6,0], att: {withLabel: false}},
    {type: "arrow", def: [[0,0],[6,0]], att: {strokeColor: "blue", fillOpacity: 1, name: "x", withLabel: true}},
    {type: "point", def: [0,5], att: {withLabel: false}},
    {type: "arrow", def: [[0,0],[0,5]], att: {strokeColor: "blue", fillOpacity: 1, name: "b", withLabel: true}},
    {type: "point", def: [4,0], att: {withLabel: false}},
    {type: "arrow", def: [[0,0],[4,0]], att: {strokeColor: "yellow", fillOpacity: 1, name: "a", withLabel: true}},
    {type: "segment", def: ["e0", ["f:e0.X()", 0]], att: {dash: 2}, att: {dash: 3, name: "x", withLabel: false}},
    {type: "segment", def: ["e0", [0,"f:e0.Y()"]], att: {dash: 3, name: "y", withLabel: false}},
]

image

As you can clearly see the x-axis is stretched out. Is that always ment to happen? It seems no matter how I change the bounds the x-axis always seems to be this stretched out or am I missing something?

DylanHojnoski commented 2 weeks ago

You can set the setting keepAspectRatio: true so that the x-axis is not stretched.

I also just released settings for the height and width of the graph so you can control the size in pixels it is within your notes. So if you set it up to be a square like height: 300 width: 300 the axis won't be stretched.

bounds: [-2,7,7,-2]
keepAspectRatio: true
elements: [
    {type: "point", def: [4,5], att: {withLabel: false}},
    {type: "arrow", def: [[0,0],"e0"], att: {strokeColor: "red", fillOpacity: 1, name: "(a, b)", withLabel: true}},
    {type: "point", def: [6,0], att: {withLabel: false}},
    {type: "arrow", def: [[0,0],[6,0]], att: {strokeColor: "blue", fillOpacity: 1, name: "x", withLabel: true}},
    {type: "point", def: [0,5], att: {withLabel: false}},
    {type: "arrow", def: [[0,0],[0,5]], att: {strokeColor: "blue", fillOpacity: 1, name: "b", withLabel: true}},
    {type: "point", def: [4,0], att: {withLabel: false}},
    {type: "arrow", def: [[0,0],[4,0]], att: {strokeColor: "yellow", fillOpacity: 1, name: "a", withLabel: true}},
    {type: "segment", def: ["e0", ["f:e0.X()", 0]], att: {dash: 2}, att: {dash: 3, name: "x", withLabel: false}},
    {type: "segment", def: ["e0", [0,"f:e0.Y()"]], att: {dash: 3, name: "y", withLabel: false}},
]
Eneswar commented 2 weeks ago

That was a quick update, thank you very much, apprecaite it! Looks good now.

Eneswar commented 2 weeks ago

By the way something that keeps happening to me randomly is that sometimes when I open a note with a graph it doesnt show until I select the area where the graph is. The graph is between the two lines but its no show until I mark it. Im not sure why it happens.

image

image

DylanHojnoski commented 2 weeks ago

Are you using live preview or source mode?

Eneswar commented 2 weeks ago

This is all live preview.

DylanHojnoski commented 2 weeks ago

I can't seem to replicate this bug. How often is it happening?

Eneswar commented 2 weeks ago

Well it hasnt happened again since I posted about it so we might be good :P

Eneswar commented 1 week ago

I figured out why, or how, it happens, and it happens every time.

When I am in a note with a graph, and I go to another one, and then when I go back (not by clicking on the note, but by going back one step, example with my side mouse button) the graphs will not display.

Its not the biggest deal but I wanted to let you know.