Giter Site home page Giter Site logo

Using custom formatters about recogito-js HOT 4 CLOSED

hbast avatar hbast commented on June 12, 2024
Using custom formatters

from recogito-js.

Comments (4)

rsimon avatar rsimon commented on June 12, 2024 1

You need to supply the formatter function as the argument (not a string). E.g:

// E.g. to give a different background color to annotations with multiple bodies
var myFormatterFunction = function(annotation) {
  return (annotation.bodies.length > 1) ? "has-multiple-bodies" : "";
}

// ...
var r = Recogito.init({
  //...
  formatter: myFormatterFunction
});

from recogito-js.

hbast avatar hbast commented on June 12, 2024 1

Obviously, you'd be a bit smarter & more efficient in reality, but you get the idea :-)

I wouldn't be so sure about that ;-)

I set the color code as a JSON value when creating the annotation and then send it to the backend. On reload, the customformatter function grabs the code and renders the annotation in the appropriate color.

from recogito-js.

hbast avatar hbast commented on June 12, 2024

Ah, my bad. Thanks for helping.

Actually, I am looking for a way to set the annotation color based on the author information. The W3C annotations support style information, but I'm not sure if recogito supports that. Otherwise I could add this information in the backend and use the formatter function to customize the rendering.

https://www.w3.org/TR/annotation-model/#styles
Like in example 34 or 35.

How would you solve this?

from recogito-js.

rsimon avatar rsimon commented on June 12, 2024

That's right. RecogitoJS doesn't support the W3C style props out of the box. (TBH, I always considered style to be more of an application concern, rather than a data model concern.) But, anyways: the formatter function receives the full annotation as the argument. So you can build the style using whatever annotation properties you want! E.g. if you want to style based on the author, you could simply do something like this:

var creatorFormatter = function(annotation) {
  if (annotation.creator === 'http://example.org/user1' {
    return { style: 'backgroundColor: red' };
  } else if (annotation.creator === 'http://example.org/user1' {
    return { style: 'backgroundColor: green' };
  } else {
    return { style: 'backgroundColor: green' };
  }
}

Obviously, you'd be a bit smarter & more efficient in reality, but you get the idea :-)

from recogito-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.