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

Plots.jl click fails #4

Open
schlichtanders opened this issue Oct 1, 2021 · 14 comments
Open

Plots.jl click fails #4

schlichtanders opened this issue Oct 1, 2021 · 14 comments

Comments

@schlichtanders
Copy link

Please check https://fonsp.com/disorganised-mess/plotclicktracker%20drag.html

breaks for me in very first cell with

MethodError: no method matching getindex(::Nothing, ::UnitRange{Int64})

linepoint(::Nothing)@Other: 3
macro [email protected]:1444[inlined]
top-level scope@Local: 34
@mmikhasenko
Copy link

I get the same error
image

The plot appears for a short moment with @initilize argument, then, disappears on the second update.

I suppose something in JS side is failing, but, frankly, I do not fully understand how the plotclicktracker works.

@mmikhasenko
Copy link

What could get wrong in this chunk of code?

	HTML("""<script id="hello">

		const body = $(PlutoRunner.publish_to_js(plot_render))
		const mime = "image/svg+xml"


		const img = this ?? document.createElement("img")


		let url = URL.createObjectURL(new Blob([body], { type: mime }))

		img.type = mime
		img.src = url
		img.draggable = false
		
		const clamp = (x,a,b) => Math.min(Math.max(x, a), b)
		img.transform = f => [
			clamp(f[0] * $(r.x_scale) + $(r.x_offset), $(r.x_min), $(r.x_max)),
			clamp(f[1] * $(r.y_scale) + $(r.y_offset), $(r.y_min), $(r.y_max)),
		]
		img.fired = false
		
		const val = {current: undefined }
		


		# if(this == null) {

		# Object.defineProperty(img, "value", {
		# 	get: () => val.current,
		# 	set: () => {},
		# })
		
		# const handle_mouse = (e) => {
		# 	const svgrect = img.getBoundingClientRect()
		# 	const f = [
		# 		(e.clientX - svgrect.left) / svgrect.width, 
		# 		(e.clientY - svgrect.top) / svgrect.height
		# 	]
		# console.log(f)
		# 	if(img.fired === false){
		# 		img.fired = true
		# 		val.current = img.transform(f)
		# 		img.dispatchEvent(new CustomEvent("input"), {})
		# 	}
		# }



		# img.addEventListener("click", onclick)

		# img.addEventListener("pointerdown", e => {
		# 	if($(draggable)){
		# 		img.addEventListener("pointermove", handle_mouse);
		# 	}
		# 	handle_mouse(e);
		# });
		# const mouseup = e => {
		# 	console.log(e)
		# 	img.removeEventListener("pointermove", handle_mouse);
		# };
		# document.addEventListener("pointerup", mouseup);
		# document.addEventListener("pointerleave", mouseup);
		# }



		return img
		</script>""")

somehow x0 gets nothing

@fonsp
Copy link
Owner

fonsp commented Mar 13, 2023

@mmikhasenko Did you get an error in the chrome dev tools? (Is it because you used # instead of //?)

@mmikhasenko
Copy link

I run Pluto in Chrome on Windows. I did not use dev tools for anything in this notebook.

What do you mean exactly?

@fonsp
Copy link
Owner

fonsp commented Mar 13, 2023

Take a look at https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Tools_and_setup/What_are_browser_developer_tools . Also make sure that you read through https://featured.plutojl.org/web/javascript , understanding this notebook will save you a lot of time!

@mmikhasenko
Copy link

mmikhasenko commented Mar 26, 2023

Thanks for the links, I educated myself about JavaScript a little bit.
The exercises are very useful.

or in the chrome dev tools? (Is it because you used # instead

There are no errors in the DevTools, when JavaScript is executed.

A cell with

plotclicktracker(linepoint([5,5]))

works. The coordinate values [.., ..] are printed in devtools.

Btw, there are errors that are present in all notebooks
image
might be related to chrome.

@fonsp
Copy link
Owner

fonsp commented Mar 28, 2023

(Those extra errors are probably because of a chrome extension, click on the source (commons.js) to find out)

@fonsp
Copy link
Owner

fonsp commented Mar 28, 2023

@mmikhasenko Could you share a short notebook that demonstrates what works, and what doesn't work? You used Julia comments (#) in JavaScript, did this not cause an issue?

@mmikhasenko
Copy link

no, sorry, ignore the #. That was a failed attempt to debug. I just copied wrong code to the message.
Yes, the original notebook does not work. I can just insert url to the pluto open-file window..

Can try now with bing

@fonsp
Copy link
Owner

fonsp commented Mar 28, 2023

Okay! But could you please make a single notebook file that demonstrates what works (#4 (comment) ) and what doesn't?

@mmikhasenko
Copy link

Same Julia error with Microsoft Bing

no, sorry, ignore the #. That was a failed attempt to debug. I just copied wrong code to the message. Yes, the original notebook does not work. I can just insert url to the pluto open-file window..

Can try now with bing

@mmikhasenko
Copy link

mmikhasenko commented Mar 28, 2023

Okay! But could you please make a single notebook file that demonstrates what works (#4 (comment) ) and what doesn't?

https://gist.github.com/mmikhasenko/9ab5fbe4e9abd28057b44a15e31e0b6e#file-plotclicktracker-drag-jl

@mmikhasenko
Copy link

Just made the code work by replacing

const val = {current: undefined}

by

const val = {current: [1,1] }

in the javascript.

@mmikhasenko
Copy link

@fonsp do you see the same twinkles?

drag

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

No branches or pull requests

3 participants