-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any chance of an API? #10
Comments
or a javascript library, then you could always just spawn a node process that generates your pallette from command line arguments. |
I see what you did there. You are of course right and I'm certainly being lazy, but I haven't yet cracked calling javascript from R. I also did look at the source code but it seemed a bit too complicated to port.. |
I think I could take a crack at answering this on StackOverflow if you would like to ask it there. |
That's jolly helpful Eric, thanks I'll do that tomorrow |
My curiosity got the better of me. First, copy chroma.js and chroma.palette-gen.js into a directory. You need to modify chroma.js and remove the first and last line. "(function(){" and "}).call(this);" Then, make a new file called something like "generatePalette.js" like this: var fs = require('fs');
eval(fs.readFileSync('./chroma.js', 'utf8'));
eval(fs.readFileSync('./chroma.palette-gen.js', 'utf8'));
// defaults
var hmin = 0,
hmax = 360,
cmin = 0,
cmax = 3,
lmin = 0,
lmax = 1.5,
q = 50,
useFV = false, // Force vector or kMeans
colorsCount = 7;
// if you want to set more variables from the command line arguments, this is where you'd do it.
// I will just set the colorsCount.
if(process.argv.length > 2) {
colorsCount = parseInt(process.argv[2], 10);
}
var hcondition = hmin < hmax ?
function(hcl){return hcl[0]>=hmin && hcl[0]<=hmax} :
function(hcl){return hcl[0]>=hmin || hcl[0]<=hmax};
var ccondition = function(hcl){return hcl[1]>=cmin && hcl[1]<=cmax};
var lcondition = function(hcl){return hcl[2]>=lmin && hcl[2]<=lmax};
function colorspaceSelector(color) {
var hcl = color.hcl();
return hcondition(hcl) && ccondition(hcl) && lcondition(hcl);
};
var colors = paletteGenerator.generate(colorsCount, colorspaceSelector, useFV, q);
colors = paletteGenerator.diffSort(colors);
colors = colors.map( function( color ){
return { color:color, hex:color.hex(), hcl:color.hcl(), lab:color.lab() }
});
colors.forEach(function(color){
console.log(color.hex);
}); Now you can run it like
So the second part is to run this from R or Python, then you can use the output. |
Btw this is slow so for perf you should pre-generate your palettes and store them as constants. I plan to generate sets of size 1 to 20. I don't imagine I'll ever have more than 20 series' in a chart. And if you are running this script by hand then you don't really need the R / Python integration right? |
I created a simple package to generate an Iwanthue palette in R: https://github.com/hoesler/rwantshue |
(edited) Very nice work guys. Eric, I now see your method to implement arguments as per colorsCount.. @hoesler does your library implement arguments for hue, chomra or lightness? IWantHue-class page makes no mention. Do you need an updated |
Indeed, the feature was missing. I added a color_space argument and the list of presets as defined on the iwanthue webpage. Am 22.01.2015 um 13:01 schrieb Robin Edwards [email protected]:
|
Forked this project and stripped it down to the color palette generator. You can find the package on npm. If you use npm and require.js in your project, using iWantHueAPI is pretty easy. From your command line:
Then include it in your project:
More documentation is on the Github repo. |
This is such a useful tool I find myself using it regularly. Is there any chance of an API so we could automate the process for non-javascript applications, or perhaps a R / Python version? I suspect most real data science happens off-browser..
The text was updated successfully, but these errors were encountered: