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

Is there any documentation for using this package? #1

Open
SamedhG opened this issue Sep 10, 2024 · 17 comments
Open

Is there any documentation for using this package? #1

SamedhG opened this issue Sep 10, 2024 · 17 comments

Comments

@SamedhG
Copy link

SamedhG commented Sep 10, 2024

Firstly, I just started integrating annotorious into my project and am really happy with the project. Thanks for creating this!

I was looking for documentation on adding the ellipse plugin. I imagine we just need to call mountPlugin, but I'm having trouble even importing this library into my react project.

Thanks!

@rsimon
Copy link
Member

rsimon commented Sep 10, 2024

Thanks for the feedback! Yep, the documentation website is currently a work in progress. Plugin documentation is still missing entirely. The gist: there's a plugin helper component in the @annotorious/react package that will handle the plumbing for you:

import { AnnotoriousPlugin } from '@annotorious/react';
import { mountPlugin as ToolsPlugin } from '@annotorious/plugin-tools';

//...

<AnnotoriousPlugin plugin={ToolsPlugin} />

Things got changed and renamed a bit recently - I still need to test for regressions. But here's a full example of how I've used the ellipse tool in React myself. (Note that this code still uses the old package/function names!).

https://github.com/rsimon/immarkus/blob/main/src/pages/annotate/WorkspaceSection/AnnotatableImage.tsx

Let me know if you get it working this way.

@technbuzz
Copy link

i wanted to use the vanilla version in angular project, is there any guideline to add circle as drawing tool?

@rsimon
Copy link
Member

rsimon commented Sep 26, 2024

Unfortunately, there is no special support for Angular (yet). So you'd need to follow the vanilla JS pattern. Also, there's no documentation for the plugin ;-) But it should be fairly straightforward. See the vanilla JS example here:

https://github.com/annotorious/annotorious-plugin-tools/blob/main/test/index.html#L35-L55

@technbuzz
Copy link

I think that will be enough, i don't see any problem using the vanilla version with angular as long it doesn't have unnecessary dependencies.

But i see the ellipse editor is create in svelte. how it would work with vanilla version?

@technbuzz
Copy link

looks like it's an early stage of development, just some feedback
No release yet assigned and i am getting type error

[ERROR] TS2307: Cannot find module '@annotorious/plugin-tools' or its corresponding type declarations. [plugin angular-compiler]

@rsimon
Copy link
Member

rsimon commented Sep 27, 2024

Oops. Indeed - I renamed the package recently, and managed to mess up some config in the package.json. Fixed now. New release 1.0.1 is out and should work now.

@rsimon rsimon closed this as completed Sep 27, 2024
@rsimon
Copy link
Member

rsimon commented Sep 27, 2024

Oops. Indeed - I renamed the package recently, and managed to mess up some config in the package.json. Fixed now. New release 1.0.1 is out and should work now.

@rsimon rsimon reopened this Sep 27, 2024
@dennys
Copy link

dennys commented Oct 16, 2024

I can build a toolbar to annotate now, the following is my code.

    <div id="toolbar">
      <button class="btn" id="rectangle">Rectangle</button>
      <button class="btn" id="polygon">Polygon</button>
    </div>

    <img id="my-image" src="d:/p.jpg" />

    <script>
      window.onload = function() {
		
        var anno = Annotorious.createImageAnnotator('my-image', {
			style: { fill: "#ffff00", fillOpacity: 0.4 }
		});
		
        document.getElementById('rectangle').addEventListener('click', function() {
          anno.setDrawingTool('rectangle');
        });

        document.getElementById('polygon').addEventListener('click', function() {
          anno.setDrawingTool('polygon');
        });
      };
    </script>

I want to use ellipse, but how to add this line to my code?

import { mountPlugin as mountToolsPlugin } from '../src';

After the above code, I think I can use the following code to draw ellipse.

mountToolsPlugin(anno);
anno.setDrawingTool('ellipse');

@rsimon
Copy link
Member

rsimon commented Oct 16, 2024

Sorry, I didn't have the time to make the tools plugin available for script import yet.

@dennys
Copy link

dennys commented Oct 17, 2024

Got it, still thank you for your awesome tool. I'll try to study the possibility to migrate my product to typescript.

@rsimon
Copy link
Member

rsimon commented Oct 17, 2024

The library should be ready for script import, so it might just be a matter of tweaking the build config. I'll try to look into it over the weekend if I get the chance.

@rsimon
Copy link
Member

rsimon commented Oct 20, 2024

I tweaked the build and published a new version. I think this should now work for script import. The CDN URLs are:

@dennys
Copy link

dennys commented Oct 20, 2024

Thanks, I think I need to import this plugin before execute mountToolsPlugin(anno);,
can you tell me how to load it by javascript?

@rsimon
Copy link
Member

rsimon commented Oct 20, 2024

If you import via the script tag, you'll get a global variable in your page. It should be window.AnnotoriousTools. You can log this object to confirm it's there. Then you can use the methods through that object. AnnotoriousTools.mountPlugin. (It's the standard difference between script imported stuff and ES6 imports.)

@dennys
Copy link

dennys commented Oct 20, 2024

This is my code, I want to build a small annotation tool on my page.
I'm not sure, do you mean I should run anno.mountToolsPlugin(); ? But it doesn't work.

    <script>
      window.onload = function() {
		
        var anno = Annotorious.createImageAnnotator('my-image', {
		style: { fill: "#ffff00", fillOpacity: 0.4 }
	});
	anno.mountToolsPlugin();
		
        // Event listeners for the toolbar buttons
        document.getElementById('rectangle').addEventListener('click', function() {
          anno.setDrawingTool('rectangle');
        });

        document.getElementById('polygon').addEventListener('click', function() {
          anno.setDrawingTool('polygon');
        });

        document.getElementById('ellipse').addEventListener('click', function() {
          anno.setDrawingTool('ellipse');
        });

        document.getElementById('clear').addEventListener('click', function() {
          anno.clearAnnotations();
        });

      };
    </script>

@rsimon
Copy link
Member

rsimon commented Oct 20, 2024

AnnotoriousTools.mountPlugin(anno);

@dennys
Copy link

dennys commented Oct 20, 2024

It works, thanks.

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

4 participants