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.
@@ -2058,18 +2058,24 @@ var BruceVariable;
2058
2058
  * Needs to become ["Test", "Test1"].
2059
2059
  * We need to cull this in admin-ui.
2060
2060
  * @param path
2061
- * @returns
2061
+ * @returns Possible paths this legacy one could mean.
2062
2062
  */
2063
2063
  function parseLegacyPath(path) {
2064
2064
  if (!path) {
2065
2065
  return [];
2066
2066
  }
2067
+ const paths = [];
2067
2068
  if (path.startsWith("${") && path.endsWith("}")) {
2068
2069
  path = path.replace("${", "");
2069
2070
  path = path.replace("}", "");
2070
- return PathUtils.ParseLegacy(path);
2071
- }
2072
- return PathUtils.Parse(path);
2071
+ // Split by dots.
2072
+ paths.push(PathUtils.ParseLegacy(path));
2073
+ // Take string as is.
2074
+ paths.push([path]);
2075
+ }
2076
+ // Split by backslashes.
2077
+ paths.push(PathUtils.Parse(path));
2078
+ return paths;
2073
2079
  }
2074
2080
  /**
2075
2081
  * Utility for calculating values from Bruce fields.
@@ -2266,43 +2272,46 @@ var Calculator;
2266
2272
  }
2267
2273
  Calculator.GetString = GetString;
2268
2274
  function GetMappingValue(value, entity) {
2269
- const attrPath = parseLegacyPath(value.field);
2270
- let eValue = Entity.GetValue({
2271
- entity: entity,
2272
- path: attrPath
2273
- });
2274
- const isValueNum = !isNaN(+eValue);
2275
- for (let i = 0; i < value.values.length; i++) {
2276
- const option = value.values[i];
2277
- const mapValue = option.fieldValue;
2278
- const isMapValueNum = !isNaN(+mapValue);
2279
- if (isValueNum && isMapValueNum) {
2280
- if (+mapValue == +eValue) {
2281
- return option.appliedValue;
2282
- }
2283
- const mapSplit = mapValue.split("-");
2284
- if (mapSplit.length == 2) {
2285
- const min = mapSplit[0];
2286
- const max = mapSplit[1];
2287
- if (min != "") {
2288
- if (+eValue < +min) {
2289
- continue;
2290
- }
2275
+ const attrPaths = parseLegacyPath(value.field);
2276
+ for (let i = 0; i < attrPaths.length; i++) {
2277
+ const attrPath = attrPaths[i];
2278
+ let eValue = Entity.GetValue({
2279
+ entity: entity,
2280
+ path: attrPath
2281
+ });
2282
+ const isValueNum = !isNaN(+eValue);
2283
+ for (let i = 0; i < value.values.length; i++) {
2284
+ const option = value.values[i];
2285
+ const mapValue = option.fieldValue;
2286
+ const isMapValueNum = !isNaN(+mapValue);
2287
+ if (isValueNum && isMapValueNum) {
2288
+ if (+mapValue == +eValue) {
2289
+ return option.appliedValue;
2291
2290
  }
2292
- if (max != "") {
2293
- if (+eValue > +max) {
2291
+ const mapSplit = mapValue.split("-");
2292
+ if (mapSplit.length == 2) {
2293
+ const min = mapSplit[0];
2294
+ const max = mapSplit[1];
2295
+ if (min != "") {
2296
+ if (+eValue < +min) {
2297
+ continue;
2298
+ }
2299
+ }
2300
+ if (max != "") {
2301
+ if (+eValue > +max) {
2302
+ continue;
2303
+ }
2304
+ }
2305
+ if (min == "" && max == "") {
2294
2306
  continue;
2295
2307
  }
2308
+ return option.appliedValue;
2296
2309
  }
2297
- if (min == "" && max == "") {
2298
- continue;
2299
- }
2300
- return option.appliedValue;
2301
2310
  }
2302
- }
2303
- else {
2304
- if (mapValue == eValue) {
2305
- return option.appliedValue;
2311
+ else {
2312
+ if (mapValue == eValue) {
2313
+ return option.appliedValue;
2314
+ }
2306
2315
  }
2307
2316
  }
2308
2317
  }
@@ -2310,31 +2319,34 @@ var Calculator;
2310
2319
  }
2311
2320
  Calculator.GetMappingValue = GetMappingValue;
2312
2321
  function GetGradientValue(value, entity) {
2313
- const attrPath = parseLegacyPath(value.field);
2314
- let eValue = Entity.GetValue({
2315
- entity: entity,
2316
- path: attrPath
2317
- });
2318
- eValue = Math.min(Math.max(eValue, value.min), value.max);
2319
- if (eValue < value.points[0].position) {
2320
- return Color.ColorFromStr(value.points[0].color);
2321
- }
2322
- for (let i = 0; i < value.points.length - 1; i++) {
2323
- const pointA = value.points[i];
2324
- const pointB = value.points[i + 1];
2325
- if (eValue >= pointA.position && eValue <= pointB.position) {
2326
- if (pointA.position == pointB.position) {
2327
- return Color.ColorFromStr(pointA.color);
2328
- }
2329
- const distance = (eValue - pointA.position) / (pointB.position - pointA.position);
2330
- const colorA = Color.ColorFromStr(pointA.color);
2331
- const colorB = Color.ColorFromStr(pointB.color);
2332
- return {
2333
- red: colorA.red + (colorB.red - colorA.red) * distance,
2334
- green: colorA.green + (colorB.green - colorA.green) * distance,
2335
- blue: colorA.blue + (colorB.blue - colorA.blue) * distance,
2336
- alpha: colorA.alpha + (colorB.alpha - colorA.alpha) * distance
2337
- };
2322
+ const attrPaths = parseLegacyPath(value.field);
2323
+ for (let i = 0; i < attrPaths.length; i++) {
2324
+ const attrPath = attrPaths[i];
2325
+ let eValue = Entity.GetValue({
2326
+ entity: entity,
2327
+ path: attrPath
2328
+ });
2329
+ eValue = Math.min(Math.max(eValue, value.min), value.max);
2330
+ if (eValue < value.points[0].position) {
2331
+ return Color.ColorFromStr(value.points[0].color);
2332
+ }
2333
+ for (let i = 0; i < value.points.length - 1; i++) {
2334
+ const pointA = value.points[i];
2335
+ const pointB = value.points[i + 1];
2336
+ if (eValue >= pointA.position && eValue <= pointB.position) {
2337
+ if (pointA.position == pointB.position) {
2338
+ return Color.ColorFromStr(pointA.color);
2339
+ }
2340
+ const distance = (eValue - pointA.position) / (pointB.position - pointA.position);
2341
+ const colorA = Color.ColorFromStr(pointA.color);
2342
+ const colorB = Color.ColorFromStr(pointB.color);
2343
+ return {
2344
+ red: colorA.red + (colorB.red - colorA.red) * distance,
2345
+ green: colorA.green + (colorB.green - colorA.green) * distance,
2346
+ blue: colorA.blue + (colorB.blue - colorA.blue) * distance,
2347
+ alpha: colorA.alpha + (colorB.alpha - colorA.alpha) * distance
2348
+ };
2349
+ }
2338
2350
  }
2339
2351
  }
2340
2352
  return Color.ColorFromStr(value.points[value.points.length - 1].color);