Skip to content

Commit c94cd45

Browse files
committed
Build with custom palette
1 parent ceee51d commit c94cd45

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

build/jsroot.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const version_id = 'dev',
1414

1515
/** @summary version date
1616
* @desc Release date in format day/month/year like '14/04/2022' */
17-
version_date = '2/02/2026',
17+
version_date = '4/02/2026',
1818

1919
/** @summary version id and date
2020
* @desc Produced by concatenation of {@link version_id} and {@link version_date}
@@ -8524,10 +8524,28 @@ function createGrayPalette() {
85248524
return new ColorPalette(palette);
85258525
}
85268526

8527+
/** @summary Set list of colors for specified color palette
8528+
* @desc One also can redefine existing palette
8529+
* Array should contain several colors in RGB format like `rgb(10,10,10)` or `#ff00ff`
8530+
* @private */
8531+
8532+
const customPalettes = {};
8533+
8534+
function setColorPalette(id, colors) {
8535+
if (!Number.isInteger(id) || (id < 0) || !colors?.length)
8536+
return false;
8537+
8538+
customPalettes[id] = colors;
8539+
return true;
8540+
}
8541+
85278542
/** @summary Create color palette
85288543
* @private */
85298544
function getColorPalette(id, grayscale) {
85308545
id = id || settings.Palette;
8546+
if (customPalettes[id])
8547+
return new ColorPalette(customPalettes[id], grayscale);
8548+
85318549
if ((id > 0) && (id < 10))
85328550
return createGrayPalette();
85338551
if (id < 51)
@@ -9619,6 +9637,10 @@ async function svgToImage(svg, image_format, args) {
96199637
is_rgba = image_format === 'rgba';
96209638

96219639
if (isNodeJs()) {
9640+
if (image_format === 'jpeg') {
9641+
console.log('JPEG image format not supported in node.js, use PNG');
9642+
return null;
9643+
}
96229644
svg = encodeURIComponent(doctype + svg);
96239645
svg = svg.replace(/%([0-9A-F]{2})/g, (match, p1) => {
96249646
const c = String.fromCharCode('0x' + p1);
@@ -185138,6 +185160,7 @@ exports.getAbsPosInCanvas = getAbsPosInCanvas;
185138185160
exports.getActivePad = getActivePad;
185139185161
exports.getBoxDecorations = getBoxDecorations;
185140185162
exports.getColor = getColor;
185163+
exports.getColorPalette = getColorPalette;
185141185164
exports.getDocument = getDocument;
185142185165
exports.getDomCanvasPainter = getDomCanvasPainter;
185143185166
exports.getElementCanvPainter = getElementCanvPainter;
@@ -185197,6 +185220,7 @@ exports.registerMethods = registerMethods;
185197185220
exports.resize = resize;
185198185221
exports.selectActivePad = selectActivePad;
185199185222
exports.setBatchMode = setBatchMode;
185223+
exports.setColorPalette = setColorPalette;
185200185224
exports.setDefaultDrawOpt = setDefaultDrawOpt;
185201185225
exports.setHPainter = setHPainter;
185202185226
exports.setHistogramTitle = setHistogramTitle;

modules/core.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const version_id = 'dev',
66

77
/** @summary version date
88
* @desc Release date in format day/month/year like '14/04/2022' */
9-
version_date = '2/02/2026',
9+
version_date = '4/02/2026',
1010

1111
/** @summary version id and date
1212
* @desc Produced by concatenation of {@link version_id} and {@link version_date}

0 commit comments

Comments
 (0)