GithubHelp home page GithubHelp logo

Comments (5)

leeoniya avatar leeoniya commented on June 26, 2024

i added an option to disable palette sorting, by default it is ordered by highest to lowest occurrence counts: .palette(tuples, noSort). you can get the palette histogram like this, for example:

var pal = quant.palette(false, true);

var palHist = [];
quant.idxi32.forEach(function(i32) {
    palHist.push({color: quant.i32rgb[i32], count: quant.histogram[i32]});
});

console.log(palHist);

or

// called with no arguments (auto-sorted)
var pal = quant.palette();

var palHist = [];
quant.idxi32.forEach(function(i32) {
    palHist.push({color: quant.i32rgb[i32], count: quant.histogram[i32]});
});

// sort it yourself
palHist.sort(function(a,b) {
    return a.count == b.count ? 0 : a.count < b.count ? 1 : -1;
});

console.log(palHist);

fixed by a397b7e

from rgbquant.js.

frankred avatar frankred commented on June 26, 2024

Ah ok I didn't know that the color output palette is ordered. Thank you very much!

Edit: I just want to say that the output is not sorted. Here is an example that is in my code:

[
    {
        "color": [
            255,
            255,
            255
        ],
        "count": 630611
    },
    {
        "color": [
            207,
            201,
            188
        ],
        "count": 1170
    },
    {
        "color": [
            30,
            37,
            63
        ],
        "count": 3
    },
    {
        "color": [
            81,
            98,
            118
        ],
        "count": 95290
    }
]

This isn't ordered... but now I know how to order it, thank you...

from rgbquant.js.

leeoniya avatar leeoniya commented on June 26, 2024

since last commit, it should be ordered by counts if you disable sorting by using quant.palette(false, true) instead of quant.palette()

it will still sort by default if you did not change the way the palette generation is called.

from rgbquant.js.

frankred avatar frankred commented on June 26, 2024

Ok thank you!

from rgbquant.js.

leeoniya avatar leeoniya commented on June 26, 2024

in your case it may be quant.palette(true, true), if you're wanting ordered tuples.

from rgbquant.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.