Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

openchemlib-utils

Package Overview
Dependencies
Maintainers
4
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openchemlib-utils - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

src/db/utils/appendColor.js

7

CHANGELOG.md
# Changelog
## [1.5.0](https://www.github.com/cheminfo/openchemlib-utils/compare/v1.4.0...v1.5.0) (2021-08-04)
### Features
* add appendColor in MoleculesDB ([bde1b8f](https://www.github.com/cheminfo/openchemlib-utils/commit/bde1b8faccf6c047807c1e27da824475e1653983))
## [1.4.0](https://www.github.com/cheminfo/openchemlib-utils/compare/v1.3.0...v1.4.0) (2021-08-03)

@@ -4,0 +11,0 @@

@@ -1127,2 +1127,78 @@ 'use strict';

function appendColor(moleculesDB, options = {}) {
const {
dataLabel,
propertyLabel,
minValue,
maxValue,
minHue = 0,
maxHue = 360,
saturation = 65,
lightness = 65,
colorLabel = 'color',
} = options;
const db = moleculesDB.getDB();
let values;
if (dataLabel) {
values = db
.map((result) =>
result.data.map((datum) => ({ value: datum[dataLabel], data: datum })),
)
.flat();
} else if (propertyLabel) {
values = db
.map((result) =>
result.data.map((datum) => ({
value: result.properties[propertyLabel],
data: datum,
})),
)
.flat();
} else {
values = db
.map((result) =>
result.data.map((datum) => ({ value: undefined, data: datum })),
)
.flat();
}
if (minValue !== undefined) {
values = values.forEach((value) => {
if (value.value !== undefined && value.value < minValue) {
value.value = minValue;
}
});
}
if (maxValue !== undefined) {
values = values.forEach((value) => {
if (value.value !== undefined && value.value > maxValue) {
value.value = maxValue;
}
});
}
const definedValues = values.filter((value) => value.value !== undefined);
const min = Math.min(...definedValues.map((value) => value.value));
const max = Math.max(...definedValues.map((value) => value.value));
for (let value of values) {
if (value.value !== undefined) {
value.data[colorLabel] =
`hsl(${
Math.floor(
((value.value - min) / (max - min)) * (maxHue - minHue) + minHue,
)
},${
saturation
}%,${
lightness
}%)`;
} else {
value.data.color = 'black';
}
}
}
async function appendSDF(moleculesDB, sdf, options = {}) {

@@ -1514,2 +1590,19 @@ const { onStep } = options;

}
/**
* Append the property `data.color` to each entry based on a data or property label
* {object} [options={}]
* {string} [options.dataLabel] name of the property from `data` to use
* {string} [options.propertyLabel] name of the property from `properties` to use
* {number} [options.colorLabel='color'] name of the property to add in data that will contain the color
* {number} [options.minValue]
* {number} [options.maxValue]
* {number} [options.minHue=0]
* {number} [options.maxHue=360]
* {number} [options.saturation=65] percent of color saturation
* {number} [options.lightness=65] percent of color lightness
*/
appendColor(options) {
appendColor(this, options);
}
}

@@ -1516,0 +1609,0 @@

2

package.json
{
"name": "openchemlib-utils",
"version": "1.4.0",
"version": "1.5.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

import appendCSV from './utils/appendCSV';
import appendColor from './utils/appendColor';
import appendSDF from './utils/appendSDF';

@@ -123,2 +124,19 @@ import appendSmilesList from './utils/appendSmilesList';

}
/**
* Append the property `data.color` to each entry based on a data or property label
* {object} [options={}]
* {string} [options.dataLabel] name of the property from `data` to use
* {string} [options.propertyLabel] name of the property from `properties` to use
* {number} [options.colorLabel='color'] name of the property to add in data that will contain the color
* {number} [options.minValue]
* {number} [options.maxValue]
* {number} [options.minHue=0]
* {number} [options.maxHue=360]
* {number} [options.saturation=65] percent of color saturation
* {number} [options.lightness=65] percent of color lightness
*/
appendColor(options) {
appendColor(this, options);
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc