bruce-models 1.9.2 → 1.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2022,18 +2022,24 @@
2022
2022
  * Needs to become ["Test", "Test1"].
2023
2023
  * We need to cull this in admin-ui.
2024
2024
  * @param path
2025
- * @returns
2025
+ * @returns Possible paths this legacy one could mean.
2026
2026
  */
2027
2027
  function parseLegacyPath(path) {
2028
2028
  if (!path) {
2029
2029
  return [];
2030
2030
  }
2031
+ const paths = [];
2031
2032
  if (path.startsWith("${") && path.endsWith("}")) {
2032
2033
  path = path.replace("${", "");
2033
2034
  path = path.replace("}", "");
2034
- return exports.PathUtils.ParseLegacy(path);
2035
- }
2036
- return exports.PathUtils.Parse(path);
2035
+ // Split by dots.
2036
+ paths.push(exports.PathUtils.ParseLegacy(path));
2037
+ // Take string as is.
2038
+ paths.push([path]);
2039
+ }
2040
+ // Split by backslashes.
2041
+ paths.push(exports.PathUtils.Parse(path));
2042
+ return paths;
2037
2043
  }
2038
2044
  (function (Calculator) {
2039
2045
  let EValueType;
@@ -2225,43 +2231,46 @@
2225
2231
  }
2226
2232
  Calculator.GetString = GetString;
2227
2233
  function GetMappingValue(value, entity) {
2228
- const attrPath = parseLegacyPath(value.field);
2229
- let eValue = exports.Entity.GetValue({
2230
- entity: entity,
2231
- path: attrPath
2232
- });
2233
- const isValueNum = !isNaN(+eValue);
2234
- for (let i = 0; i < value.values.length; i++) {
2235
- const option = value.values[i];
2236
- const mapValue = option.fieldValue;
2237
- const isMapValueNum = !isNaN(+mapValue);
2238
- if (isValueNum && isMapValueNum) {
2239
- if (+mapValue == +eValue) {
2240
- return option.appliedValue;
2241
- }
2242
- const mapSplit = mapValue.split("-");
2243
- if (mapSplit.length == 2) {
2244
- const min = mapSplit[0];
2245
- const max = mapSplit[1];
2246
- if (min != "") {
2247
- if (+eValue < +min) {
2248
- continue;
2249
- }
2234
+ const attrPaths = parseLegacyPath(value.field);
2235
+ for (let i = 0; i < attrPaths.length; i++) {
2236
+ const attrPath = attrPaths[i];
2237
+ let eValue = exports.Entity.GetValue({
2238
+ entity: entity,
2239
+ path: attrPath
2240
+ });
2241
+ const isValueNum = !isNaN(+eValue);
2242
+ for (let i = 0; i < value.values.length; i++) {
2243
+ const option = value.values[i];
2244
+ const mapValue = option.fieldValue;
2245
+ const isMapValueNum = !isNaN(+mapValue);
2246
+ if (isValueNum && isMapValueNum) {
2247
+ if (+mapValue == +eValue) {
2248
+ return option.appliedValue;
2250
2249
  }
2251
- if (max != "") {
2252
- if (+eValue > +max) {
2250
+ const mapSplit = mapValue.split("-");
2251
+ if (mapSplit.length == 2) {
2252
+ const min = mapSplit[0];
2253
+ const max = mapSplit[1];
2254
+ if (min != "") {
2255
+ if (+eValue < +min) {
2256
+ continue;
2257
+ }
2258
+ }
2259
+ if (max != "") {
2260
+ if (+eValue > +max) {
2261
+ continue;
2262
+ }
2263
+ }
2264
+ if (min == "" && max == "") {
2253
2265
  continue;
2254
2266
  }
2267
+ return option.appliedValue;
2255
2268
  }
2256
- if (min == "" && max == "") {
2257
- continue;
2258
- }
2259
- return option.appliedValue;
2260
2269
  }
2261
- }
2262
- else {
2263
- if (mapValue == eValue) {
2264
- return option.appliedValue;
2270
+ else {
2271
+ if (mapValue == eValue) {
2272
+ return option.appliedValue;
2273
+ }
2265
2274
  }
2266
2275
  }
2267
2276
  }
@@ -2269,31 +2278,34 @@
2269
2278
  }
2270
2279
  Calculator.GetMappingValue = GetMappingValue;
2271
2280
  function GetGradientValue(value, entity) {
2272
- const attrPath = parseLegacyPath(value.field);
2273
- let eValue = exports.Entity.GetValue({
2274
- entity: entity,
2275
- path: attrPath
2276
- });
2277
- eValue = Math.min(Math.max(eValue, value.min), value.max);
2278
- if (eValue < value.points[0].position) {
2279
- return exports.Color.ColorFromStr(value.points[0].color);
2280
- }
2281
- for (let i = 0; i < value.points.length - 1; i++) {
2282
- const pointA = value.points[i];
2283
- const pointB = value.points[i + 1];
2284
- if (eValue >= pointA.position && eValue <= pointB.position) {
2285
- if (pointA.position == pointB.position) {
2286
- return exports.Color.ColorFromStr(pointA.color);
2287
- }
2288
- const distance = (eValue - pointA.position) / (pointB.position - pointA.position);
2289
- const colorA = exports.Color.ColorFromStr(pointA.color);
2290
- const colorB = exports.Color.ColorFromStr(pointB.color);
2291
- return {
2292
- red: colorA.red + (colorB.red - colorA.red) * distance,
2293
- green: colorA.green + (colorB.green - colorA.green) * distance,
2294
- blue: colorA.blue + (colorB.blue - colorA.blue) * distance,
2295
- alpha: colorA.alpha + (colorB.alpha - colorA.alpha) * distance
2296
- };
2281
+ const attrPaths = parseLegacyPath(value.field);
2282
+ for (let i = 0; i < attrPaths.length; i++) {
2283
+ const attrPath = attrPaths[i];
2284
+ let eValue = exports.Entity.GetValue({
2285
+ entity: entity,
2286
+ path: attrPath
2287
+ });
2288
+ eValue = Math.min(Math.max(eValue, value.min), value.max);
2289
+ if (eValue < value.points[0].position) {
2290
+ return exports.Color.ColorFromStr(value.points[0].color);
2291
+ }
2292
+ for (let i = 0; i < value.points.length - 1; i++) {
2293
+ const pointA = value.points[i];
2294
+ const pointB = value.points[i + 1];
2295
+ if (eValue >= pointA.position && eValue <= pointB.position) {
2296
+ if (pointA.position == pointB.position) {
2297
+ return exports.Color.ColorFromStr(pointA.color);
2298
+ }
2299
+ const distance = (eValue - pointA.position) / (pointB.position - pointA.position);
2300
+ const colorA = exports.Color.ColorFromStr(pointA.color);
2301
+ const colorB = exports.Color.ColorFromStr(pointB.color);
2302
+ return {
2303
+ red: colorA.red + (colorB.red - colorA.red) * distance,
2304
+ green: colorA.green + (colorB.green - colorA.green) * distance,
2305
+ blue: colorA.blue + (colorB.blue - colorA.blue) * distance,
2306
+ alpha: colorA.alpha + (colorB.alpha - colorA.alpha) * distance
2307
+ };
2308
+ }
2297
2309
  }
2298
2310
  }
2299
2311
  return exports.Color.ColorFromStr(value.points[value.points.length - 1].color);