Extras

Random color

Use a utility function to generate a random color for the border of the NNC and the elements of the MBS.

// randomColor.js
export default () => `#${Math.floor(Math.random() * 0x1000000).toString(16).padStart(6, 0)}`;

Import it in index.js.

// ...
import randomColor from './randomColor';

Use it for both NNC and MBS.

  // ...
  nncElement.style.borderColor = randomColor();
  // ...
  // ...
  // Associate one class to one color
  const classColorMap = {};

  const onClassification = (classifiedObjects) => classifiedObjects.forEach((classifiedObject) => {
    let color = classColorMap[classifiedObject.classTag];

    if (!color) {
      color = randomColor();
      classColorMap[classifiedObject.classTag] = color;
    }

    handleObjectClassified(classifiedObject, color);
  });
  // ...

End result:

Last updated

Was this helpful?