Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions core/blockly.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,15 @@ Blockly.isNumber = function(str) {
return /^\s*-?\d+(\.\d+)?\s*$/.test(str);
};

/**
* Convert a hue (HSV model) into an RGB hex triplet.
* @param {number} hue Hue on a colour wheel (0-360).
* @return {string} RGB code, e.g. '#5ba65b'.
*/
Blockly.hueToHex = function(hue) {
return Blockly.utils.colour.hsvToHex(
hue, Blockly.internalConstants.HSV_SATURATION,
Blockly.internalConstants.HSV_VALUE * 255);
};
// Add a getter for Blockly.hueToHex, for legacy reasons.
Object.defineProperty(Blockly, 'hueToHex', {
get: function() {
Blockly.utils.deprecation.warn(
'Blockly.hueToHex()', 'September 2021', 'September 2022',
'Blockly.utils.colour.hueToHex()');
return Blockly.utils.colour.hueToHex;
}
});

/**
* Set the parent container. This is the container element that the WidgetDiv,
Expand Down
2 changes: 1 addition & 1 deletion core/toolbox/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ ToolboxCategory.prototype.parseColour_ = function(colourValue) {
} else {
const hue = Number(colour);
if (!isNaN(hue)) {
return Blockly.hueToHex(hue);
return colourUtils.hueToHex(hue);
} else {
const hex = colourUtils.parse(colour);
if (hex) {
Expand Down
13 changes: 13 additions & 0 deletions core/utils/colour.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
goog.module('Blockly.utils.colour');
goog.module.declareLegacyNamespace();

const internalConstants = goog.require('Blockly.internalConstants');


/**
* Parses a colour from a string.
Expand Down Expand Up @@ -212,3 +214,14 @@ const names = {
'yellow': '#ffff00'
};
exports.names = names;

/**
* Convert a hue (HSV model) into an RGB hex triplet.
* @param {number} hue Hue on a colour wheel (0-360).
* @return {string} RGB code, e.g. '#5ba65b'.
*/
const hueToHex = function(hue) {
return hsvToHex(
hue, internalConstants.HSV_SATURATION, internalConstants.HSV_VALUE * 255);
};
exports.hueToHex = hueToHex;
3 changes: 2 additions & 1 deletion demos/blockfactory/workspacefactory/wfactory_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,8 @@ WorkspaceFactoryController.prototype.loadCategoryByName = function(name) {
}
if (!standardCategory.colour && standardCategory.hue !== undefined) {
// Calculate the hex colour based on the hue.
standardCategory.colour = Blockly.hueToHex(standardCategory.hue);
standardCategory.colour = Blockly.utils.colour.hueToHex(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually a breaking change in demos, at least until we check in an updated blockly_compressed.js. I'm running into this now with my similar change, and not sure if we should a) make the change anyway which breaks the demo but hope it works whenever we do check in blockly_compressed b) check in blockly_compressed now or c) hold off on making the change to demos until after we check in blockly_compressed

we've done option a here but not sure if that was intentional and if I should continue doing that with other changes. any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I made changes to the code demo to add JSON serialization I tested w/ compressed to make sure it worked, but didn't check it in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking at this from the perspective of it being easy to forget to backport these changes later, and assuming that we'll wind up needing to do a round of regression testing/fixing regardless. Happy to revert the changes to the files in demo if you think that's a better idea though!

standardCategory.hue);
}
// Transfers current flyout blocks to a category if it's the first category
// created.
Expand Down
2 changes: 1 addition & 1 deletion demos/blockfactory/workspacefactory/wfactory_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ WorkspaceFactoryInit.initColourPicker_ = function(controller) {
// Convert hue numbers to RRGGBB strings.
for (var i = 0; i < colours.length; i++) {
if (colours[i] !== '') {
colours[i] = Blockly.hueToHex(colours[i]).substring(1);
colours[i] = Blockly.utils.colour.hueToHex(colours[i]).substring(1);
}
}
// Convert to 2D array.
Expand Down
2 changes: 1 addition & 1 deletion tests/deps.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.