@opendata-ai/openchart-engine 8.0.0-rc.13 → 8.0.0-rc.15

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/dist/index.js CHANGED
@@ -11616,7 +11616,13 @@ function validateGraphSpec(spec, errors) {
11616
11616
  for (const key of Object.keys(edge)) edgeFields.add(key);
11617
11617
  }
11618
11618
  }
11619
- const nodeChannels = ["nodeColor", "nodeSize", "nodeOpacity", "nodeLabel"];
11619
+ const nodeChannels = [
11620
+ "nodeColor",
11621
+ "nodeSize",
11622
+ "nodeOpacity",
11623
+ "nodeLabel",
11624
+ "nodeLabelPriority"
11625
+ ];
11620
11626
  for (const channel of nodeChannels) {
11621
11627
  const ch = encoding[channel];
11622
11628
  if (ch?.field && typeof ch.field === "string" && nodes.length > 0 && !nodeFields.has(ch.field)) {
@@ -18933,7 +18939,7 @@ import {
18933
18939
 
18934
18940
  // src/graphs/animation.ts
18935
18941
  var ENTER_DEFAULT = {
18936
- duration: 600,
18942
+ duration: 500,
18937
18943
  ease: "smooth",
18938
18944
  stagger: true,
18939
18945
  cameraFit: true
@@ -19107,6 +19113,17 @@ function resolveNodeVisuals(nodes, encoding, edges, theme, nodeOverrides) {
19107
19113
  const range3 = scaleConfig?.range && scaleConfig.range.length >= 2 ? [Number(scaleConfig.range[0]), Number(scaleConfig.range[1])] : [0.25, 1];
19108
19114
  opacityScale = linear2().domain(domain).range(range3);
19109
19115
  }
19116
+ let labelPriorityScale;
19117
+ if (encoding.nodeLabelPriority?.field) {
19118
+ const field = encoding.nodeLabelPriority.field;
19119
+ const scaleConfig = encoding.nodeLabelPriority.scale;
19120
+ const values = nodes.map((n) => Number(n[field])).filter((v) => Number.isFinite(v));
19121
+ const lpMin = min(values) ?? 0;
19122
+ const lpMax = max(values) ?? 1;
19123
+ const domain = scaleConfig?.domain && scaleConfig.domain.length === 2 ? scaleConfig.domain : [lpMin, lpMax];
19124
+ const range3 = scaleConfig?.range && scaleConfig.range.length >= 2 ? [Number(scaleConfig.range[0]), Number(scaleConfig.range[1])] : [0, 1];
19125
+ labelPriorityScale = linear2().domain(domain).range(range3);
19126
+ }
19110
19127
  return nodes.map((node) => {
19111
19128
  let radius = DEFAULT_NODE_RADIUS;
19112
19129
  if (sizeScale && encoding.nodeSize?.field) {
@@ -19131,8 +19148,14 @@ function resolveNodeVisuals(nodes, encoding, edges, theme, nodeOverrides) {
19131
19148
  } else {
19132
19149
  label = node.id;
19133
19150
  }
19134
- const degree = degrees2.get(node.id) ?? 0;
19135
- const labelPriority = maxDegree > 0 ? degree / maxDegree : 0;
19151
+ let labelPriority;
19152
+ if (labelPriorityScale && encoding.nodeLabelPriority?.field) {
19153
+ const val = Number(node[encoding.nodeLabelPriority.field]);
19154
+ labelPriority = Number.isFinite(val) ? labelPriorityScale(val) : 0;
19155
+ } else {
19156
+ const degree = degrees2.get(node.id) ?? 0;
19157
+ labelPriority = maxDegree > 0 ? degree / maxDegree : 0;
19158
+ }
19136
19159
  const { id: _id, ...rest } = node;
19137
19160
  const data = { id: node.id, ...rest };
19138
19161
  const override = nodeOverrides?.[node.id];