@@ -15,8 +15,10 @@ import type {
1515 FunctionPlotOptions ,
1616} from "function-plot/dist/types" ;
1717
18+ // TODO make change to returned object reflect in input
1819export function toFunctionPlotOptions (
19- options : PlotInputs
20+ options : PlotInputs ,
21+ target : HTMLElement
2022) : FunctionPlotOptions {
2123 function functionInputsToFunctionPlotDatum (
2224 inputs : FunctionInputs
@@ -34,8 +36,7 @@ export function toFunctionPlotOptions(
3436 : undefined ,
3537 offset :
3638 inputs . fnType === "vector" &&
37- ( inputs . offset ?. x !== undefined ||
38- inputs . offset ?. y !== undefined ) //TODO work here offset is [undef, undef]
39+ ( inputs . offset ?. x !== undefined || inputs . offset ?. y !== undefined ) //TODO work here offset is [undef, undef]
3940 ? [ inputs . offset . x ?? 0 , inputs . offset . y ?? 0 ]
4041 : undefined ,
4142 r : inputs . fnType === "polar" ? inputs . r : undefined ,
@@ -47,7 +48,7 @@ export function toFunctionPlotOptions(
4748 inputs . range . max ?? FALLBACK_FUNCTION_INPUTS . range . max ,
4849 ]
4950 : undefined ,
50- nSamples : inputs . nSamples ,
51+ nSamples : Math . min ( inputs . nSamples , 999 ) ,
5152 closed : inputs . closed ,
5253 skipTip : inputs . skipTip ,
5354 } ;
@@ -68,7 +69,8 @@ export function toFunctionPlotOptions(
6869 }
6970
7071 const output : FunctionPlotOptions = {
71- target : options . target ,
72+ //id: options.id, //used by funcitonplot to identify the plot for updating
73+ target : target ,
7274 data : options . data
7375 . filter ( hasFunction )
7476 . map ( functionInputsToFunctionPlotDatum ) ,
@@ -137,14 +139,16 @@ export function insertParagraphAtCursor(
137139 * @param plugin A reference to the plugin (accessed for settings)
138140 * @returns The chart object of the created plot
139141 */
140- export function renderPlot ( options : PlotInputs , plugin : ObsidianFunctionPlot ) {
141- if ( options . target === null ) return ;
142+ export function renderPlot (
143+ options : PlotInputs ,
144+ target : HTMLElement ,
145+ plugin : ObsidianFunctionPlot
146+ ) {
147+ if ( target === null ) return ;
142148 const stylingPlugin = createStylingPlugin ( plugin ) ;
143- console . log ( "reloading plot" ) ;
144- console . log ( toFunctionPlotOptions ( options ) ) ;
145149 try {
146150 functionPlot (
147- Object . assign ( { } , toFunctionPlotOptions ( options ) , {
151+ Object . assign ( { } , toFunctionPlotOptions ( options , target ) , {
148152 plugins : [ stylingPlugin ] ,
149153 } )
150154 ) ;
@@ -182,7 +186,7 @@ export async function insertPlotAsImage(
182186 options : PlotInputs
183187) {
184188 const target = document . createElement ( "div" ) ;
185- renderPlot ( Object . assign ( options , { target } ) , plugin ) ;
189+ renderPlot ( options , target , plugin ) ;
186190 const dataURL = await toPng ( target ) ;
187191 if ( dataURL === "data:," ) {
188192 new Error ( "Data URL is empty" ) ;
@@ -226,8 +230,8 @@ export function parseYAMLCodeBlock(content: string): PlotInputs {
226230 . filter ( ( line ) => line . length > 0 ) ;
227231
228232 return {
229- target : null ,
230233 renderer : null ,
234+ constants : { } ,
231235 title : header . title ?? DEFAULT_PLOT_INPUTS . title ,
232236 xAxis : {
233237 label : header . xLabel ?? DEFAULT_PLOT_INPUTS . xAxis . label ,
0 commit comments