Mischback / colorizer

A simple web-based colorscheme builder which focuses on contrast values.

Home Page:https://mischback.github.io/colorizer/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Drag'n'drop sorting of palette items

Mischback opened this issue · comments

Implementation Idea

  • ColorizerEngineInterface handles the actual dragging'n'dropping (with the help of an external library; see below)
    • the original / v1 implementation handles all drag'n'drop stuff natively
    • Idea: with a third-party Drag'n'Drop library it might be possible to delegate all the sorting to that library (just the frontend, without directly involving Colorizer) and then attach our palette management by one of the provided callback hooks.
  • ColorizerEngine makes the sorting persistent in the database and publishes updates (Observer pattern)
    • sorting is based on an attribute of ColorizerPaletteItem (sorting)
    • ColorizerDatabase establishes and maintains an index on that field
    • the original / v1 implementation has a sorting attribute as type number (integer) and always updates all PaletteItem instances on sorting, which is highly inefficient!
    • Idea: Instead of a number-based sorting / ordering, use lexicographical ordering. This could possibly reduce the required number of update operations to 1!
      • Requires all instances of ColorizerPaletteItem to be instantiated with a valid sorting value! Idea: Manage this in ColorizerPalette, as the only way to add new palette items should be through the ColorizerPalette instance
        • have a private nextSorting: LexoRank on ColorizerPalette
        • have this.nextSorting = new LexoRank("foobar"); in ColorizerPalette.constructor() Yeah, kind of...
        • have this.nextSorting = this.nextSorting.increment() in ColorizerPalette.add() Yeah, kind of...
        • have this.nextSorting = new LexoRank(this._palette[this._palette.length - 1]?.sorting).increment() in ColorizerPalette.synchronizePaletteFromDb()
      • get the new index of the item in the overall palette, use newIndex = LexoRank.between(this._palette[newIndex - 1], this._palette[newIndex + 1]);
      • requires sorting of this._palette, either with an overall sorting or a manual insertion at the desired position (the latter should be more efficient)

Resources

Possible Libraries