Git Product home page Git Product logo

Comments (6)

bgrins avatar bgrins commented on August 21, 2024

I wonder if we would be better served by providing a custom callback with the paletteTemplate function, or even just an event like onPaletteDrawn that passes that element in. Then you could do whatever you wanted as far as display logic in the palette. In this case, you could keep that map of names to colors in your program then write out the needed attributes. Would this cover what you are looking to do?

from spectrum.

beporter avatar beporter commented on August 21, 2024

That would work, but in my use case I'm using the following settings combination:

    showPaletteOnly: true,
    flat: true,
    palette: extensivePaletteArrayWithFiftyPlusValues,

With a large palette, depending on how you implement this there could be many callbacks being fired. (Are you thinking one callback per palette array element, or one callback for the entire palette??)

Without knowing the internals of Spectrum all that well, I have to believe it would be more efficient to process a list of attributes once (along with the necessary hex values) during setup. A callback approach means I also have to leave a large chunk of "intestines" vital for Spectrum's operation outside of its "body", so to speak.

That said, obviously I'm being selfish and want Spectrum to do it for me, but I can't deny that your approach would solve my (relatively minor) problem.

from spectrum.

bgrins avatar bgrins commented on August 21, 2024

As for performance, that callback is happening anyway (internally in the plugin), and it is no big deal (since it is just dealing with string concatenation at the moment). I was suggesting that we could allow it to be overridden with a custom templating function in case you wanted to do something extra.

It would be more efficient to process the list of attributes as you suggested, but the only issue I have with implementing it directly is that I think if we were more flexible it would help more people. I see the need to customize the palette beyond the defaults, but I think everyone may have different goals (possibly wanting to change more than just the title - for instance, I could imagine wanting to make a certain swatch or row of swatches smaller than others or something).

Here is the current template function used internally in the plugin: https://github.com/bgrins/spectrum/blob/master/spectrum.js#L102. It is called once for each palette row. Obviously it would be nice for users to not have to reimplement that whole function (but that would be the easiest way to allow you to get custom behavior) - I'm trying to think of a different way to organize it. Possibly I can create a DOM element of the swatch and pass it into your custom callback, in which you could modify it however you wanted. That may not be good for performance as you mentioned, but it probably wouldn't be that bad.

from spectrum.

cmrockwell avatar cmrockwell commented on August 21, 2024

While this is an old thread, I'm facing the same issue as OP. Would like to add title attributes to name the colors. The link seems to point to HTML. What would your current recommendation be?

from spectrum.

bgrins avatar bgrins commented on August 21, 2024

@cmrockwell incidentally we were just discussing what sounds like the same request today in #407. I think the first option in #407 (comment) should work

from spectrum.

cmrockwell avatar cmrockwell commented on August 21, 2024

Yep, that works! Thanks much for the response

from spectrum.

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.