@splunk/visualizations 28.5.1 → 28.5.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.
package/NetworkGraph.js CHANGED
@@ -1673,7 +1673,7 @@ var Cover = styled_components_default.div`
1673
1673
  bottom: 0;
1674
1674
  `;
1675
1675
  var Blocker = styled_components_default.div.attrs({
1676
- "data-splunk-visualization-version": "28.5.1 - 617766eb3"
1676
+ "data-splunk-visualization-version": "28.5.3 - 657435b86"
1677
1677
  })`
1678
1678
  position: relative;
1679
1679
  width: 100%;
@@ -1784,7 +1784,7 @@ var withFixedSizeContainer = (Viz) => {
1784
1784
  FixSizeItem,
1785
1785
  {
1786
1786
  "data-test": "fix-size-item",
1787
- "data-splunk-visualization-version": "28.5.1 - 617766eb3",
1787
+ "data-splunk-visualization-version": "28.5.3 - 657435b86",
1788
1788
  width,
1789
1789
  height,
1790
1790
  backgroundColor
@@ -3996,6 +3996,20 @@ var MIN_NODE_CONTAINER_SIZE = DEFAULT_NODE_RADIUS * 2 + MIN_EDGE_LENGTH;
3996
3996
  var DEFAULT_NODE_HORIZONTAL_SPACING = 0;
3997
3997
  var DEFAULT_NODE_VERTICAL_SPACING = 0;
3998
3998
  var FORCE_NODE_PADDING = 24;
3999
+ var toFiniteNumber = (value) => {
4000
+ if (typeof value === "number") {
4001
+ return Number.isFinite(value) ? value : void 0;
4002
+ }
4003
+ if (typeof value === "string") {
4004
+ const numericValue = Number(value);
4005
+ return Number.isFinite(numericValue) ? numericValue : void 0;
4006
+ }
4007
+ return void 0;
4008
+ };
4009
+ var toFiniteNumberOrFallback = (value, fallback) => {
4010
+ const numericValue = toFiniteNumber(value);
4011
+ return numericValue != null ? numericValue : fallback;
4012
+ };
3999
4013
  var getIconRenderInfo = (icon) => {
4000
4014
  var _a;
4001
4015
  const isIconString = typeof icon === "string";
@@ -4065,7 +4079,7 @@ var getUniqueNodesVisual = ({
4065
4079
  color: getValidColor(nodeColors, i),
4066
4080
  icon: icons[i],
4067
4081
  iconColor: getValidColor(iconColors, i),
4068
- value: nodeValues[i],
4082
+ value: toFiniteNumber(nodeValues[i]),
4069
4083
  tooltipFields: tooltipNodeFields.length > 0 ? [...tooltipNodeFields].reduce((acc, fieldName) => {
4070
4084
  if (fieldName in nodeMeta) {
4071
4085
  acc[fieldName] = nodeMeta[fieldName];
@@ -4085,12 +4099,10 @@ var getUniqueNodesStruct = (source, target, nodeIds, nodeTexts, nodeTypes, nodeS
4085
4099
  const truncatedText = truncateTextToMaxLines(nodeTexts[i], FONT, MAX_TEXT_WIDTH, 4);
4086
4100
  const textWidth = Math.max(...truncatedText.map((line) => computeTextWidth(line, FONT)));
4087
4101
  const labelHeight = truncatedText.length > 0 ? RECT_VERTICAL_PADDING * 2 + LINE_HEIGHT * truncatedText.length : 0;
4102
+ const rawNodeSize = Array.isArray(nodeSizes) ? nodeSizes[i] : nodeSizes != null ? nodeSizes : DEFAULT_NODE_RADIUS * 2;
4088
4103
  const diameter = Math.max(
4089
4104
  MIN_NODE_DIAMETER,
4090
- Math.min(
4091
- MAX_NODE_DIAMETER,
4092
- Array.isArray(nodeSizes) ? nodeSizes[i] : nodeSizes != null ? nodeSizes : DEFAULT_NODE_RADIUS * 2
4093
- )
4105
+ Math.min(MAX_NODE_DIAMETER, toFiniteNumberOrFallback(rawNodeSize, DEFAULT_NODE_RADIUS * 2))
4094
4106
  );
4095
4107
  const nodeHeight = diameter + RECT_TOP_MARGIN + MIN_NODE_SPACING + labelHeight;
4096
4108
  const nodeWidth = Math.max(textWidth + RECT_HORIZONTAL_PADDING * 2, diameter + MIN_NODE_SPACING * 2);
@@ -4132,14 +4144,26 @@ var updatePositions = (nodeMap, positions) => {
4132
4144
  });
4133
4145
  return updatedNodeMap;
4134
4146
  };
4147
+ var parseWidth = (width) => {
4148
+ if (typeof width === "number") {
4149
+ return width;
4150
+ }
4151
+ if (typeof width === "string") {
4152
+ return Number(width);
4153
+ }
4154
+ return Number.NaN;
4155
+ };
4135
4156
  var getUniqueLinks = (source, target, linkColors, linkWidth, resultLimit) => {
4136
4157
  const linkMap = {};
4137
4158
  source.slice(0, resultLimit).forEach((sourceId, index) => {
4138
- var _a;
4139
4159
  const targetId = target[index];
4140
4160
  const linkColor = getValidColor(linkColors, index);
4141
- const width = typeof linkWidth === "number" ? linkWidth : (_a = linkWidth == null ? void 0 : linkWidth[index]) != null ? _a : DEFAULT_LINK_WIDTH;
4142
- const clampedWidth = Number.isNaN(width) ? DEFAULT_LINK_WIDTH : Math.min(MAX_LINK_WIDTH, Math.max(MIN_LINK_WIDTH, width));
4161
+ const width = typeof linkWidth === "number" ? linkWidth : linkWidth == null ? void 0 : linkWidth[index];
4162
+ const parsedWidth = parseWidth(width);
4163
+ const clampedWidth = Math.min(
4164
+ MAX_LINK_WIDTH,
4165
+ Math.max(MIN_LINK_WIDTH, Number.isNaN(parsedWidth) ? DEFAULT_LINK_WIDTH : parsedWidth)
4166
+ );
4143
4167
  if (targetId) {
4144
4168
  const linkId = `${sourceId}-${targetId}`;
4145
4169
  linkMap[linkId] = {
@@ -4170,13 +4194,11 @@ var getGridLayout = (nodeMap, gridColumns, nodeHorizontalPadding = DEFAULT_NODE_
4170
4194
  };
4171
4195
  var getPresetLayout = (nodeMap, xPositions, yPositions) => {
4172
4196
  const positionsMap = {};
4173
- const xPosFormatted = xPositions == null ? void 0 : xPositions.map((x) => x + 340);
4174
- const yPosFormatted = yPositions == null ? void 0 : yPositions.map((y) => y + 280);
4175
4197
  Object.keys(nodeMap).forEach((id) => {
4176
4198
  const { index } = nodeMap[id];
4177
4199
  positionsMap[id] = {
4178
- x: xPosFormatted[index],
4179
- y: yPosFormatted[index]
4200
+ x: toFiniteNumberOrFallback(xPositions == null ? void 0 : xPositions[index], 0) + 340,
4201
+ y: toFiniteNumberOrFallback(yPositions == null ? void 0 : yPositions[index], 0) + 280
4180
4202
  };
4181
4203
  });
4182
4204
  return positionsMap;
@@ -6995,6 +7017,41 @@ var config = {
6995
7017
  var config_default = enhanceConfig(config);
6996
7018
 
6997
7019
  // src/NetworkGraph/NetworkGraph.tsx
7020
+ var numericArrayOptionKeys = ["xPositions", "yPositions", "nodeValues"];
7021
+ var numericArrayOrScalarOptionKeys = ["nodeSize", "linkWidth"];
7022
+ var isNullOrEmptyString = (value) => value === null || typeof value === "string" && value.trim() === "";
7023
+ var toFiniteNumberOrUndefined = (value, treatNullOrEmptyStringAsInvalid = false) => {
7024
+ if (treatNullOrEmptyStringAsInvalid && isNullOrEmptyString(value)) {
7025
+ return void 0;
7026
+ }
7027
+ const numericValue = Number(value);
7028
+ return Number.isFinite(numericValue) ? numericValue : void 0;
7029
+ };
7030
+ var convertToNumbers = (arr, treatNullOrEmptyStringAsInvalid = false) => arr.map((item) => {
7031
+ if (treatNullOrEmptyStringAsInvalid && isNullOrEmptyString(item)) {
7032
+ return Number.NaN;
7033
+ }
7034
+ const numericValue = Number(item);
7035
+ return Number.isFinite(numericValue) ? numericValue : Number.NaN;
7036
+ });
7037
+ var normalizeNetworkGraphNumericOptions = (options) => {
7038
+ const normalizedOptions = __spreadValues({}, options);
7039
+ numericArrayOptionKeys.forEach((key) => {
7040
+ const value = normalizedOptions[key];
7041
+ if (Array.isArray(value)) {
7042
+ normalizedOptions[key] = convertToNumbers(value);
7043
+ }
7044
+ });
7045
+ numericArrayOrScalarOptionKeys.forEach((key) => {
7046
+ const value = normalizedOptions[key];
7047
+ if (Array.isArray(value)) {
7048
+ normalizedOptions[key] = convertToNumbers(value, true);
7049
+ } else if (value !== void 0) {
7050
+ normalizedOptions[key] = toFiniteNumberOrUndefined(value, true);
7051
+ }
7052
+ });
7053
+ return normalizedOptions;
7054
+ };
6998
7055
  var showPlaceHolderIcon = (dataSources) => {
6999
7056
  var _a, _b;
7000
7057
  const columns = (_b = (_a = dataSources == null ? void 0 : dataSources.primary) == null ? void 0 : _a.data) == null ? void 0 : _b.columns;
@@ -7002,12 +7059,22 @@ var showPlaceHolderIcon = (dataSources) => {
7002
7059
  const dataSourceState = (0, dataSourceUtils_exports.getDataSourceStateInfo)(dataSources == null ? void 0 : dataSources.primary);
7003
7060
  return dataSourceState.hasError || dataSourceState.isLoading || dataSourceState.isMissing || noColumns;
7004
7061
  };
7005
- var computeVizProps = ({ dataSources, onOptionsChange, themeFunc }) => {
7006
- var _a, _b, _c, _d, _e, _f;
7007
- const columns = ((_b = (_a = dataSources == null ? void 0 : dataSources.primary) == null ? void 0 : _a.data) == null ? void 0 : _b.columns) || [];
7062
+ var computeVizProps = (_a) => {
7063
+ var _b = _a, {
7064
+ dataSources,
7065
+ onOptionsChange,
7066
+ themeFunc
7067
+ } = _b, options = __objRest(_b, [
7068
+ "dataSources",
7069
+ "onOptionsChange",
7070
+ "themeFunc"
7071
+ ]);
7072
+ var _a2, _b2, _c, _d, _e, _f;
7073
+ const columns = ((_b2 = (_a2 = dataSources == null ? void 0 : dataSources.primary) == null ? void 0 : _a2.data) == null ? void 0 : _b2.columns) || [];
7008
7074
  const fields = ((_d = (_c = dataSources == null ? void 0 : dataSources.primary) == null ? void 0 : _c.data) == null ? void 0 : _d.fields) || [];
7009
7075
  const dataSourceData = (_f = (_e = dataSources == null ? void 0 : dataSources.primary) == null ? void 0 : _e.data) != null ? _f : {};
7010
7076
  const transformedData = convertToArrOfObjects(dataSourceData.columns, dataSourceData.fields);
7077
+ const normalizedOptions = normalizeNetworkGraphNumericOptions(options);
7011
7078
  const themeColorVariables = [
7012
7079
  "defaultBackgroundColor",
7013
7080
  "defaultLinkColor",
@@ -7018,12 +7085,12 @@ var computeVizProps = ({ dataSources, onOptionsChange, themeFunc }) => {
7018
7085
  themeColorVariables.forEach((variable) => {
7019
7086
  themeColors[variable] = themeFunc(variable);
7020
7087
  });
7021
- return __spreadValues({
7088
+ return __spreadValues(__spreadProps(__spreadValues({}, normalizedOptions), {
7022
7089
  fields: fields.map((field) => (field == null ? void 0 : field.name) ? field.name : field),
7023
7090
  columns,
7024
7091
  onOptionsChange,
7025
7092
  metadata: transformedData
7026
- }, themeColors);
7093
+ }), themeColors);
7027
7094
  };
7028
7095
  var withTooltipFields = (Viz) => {
7029
7096
  const VizWithTooltipFields = (_a) => {