CoreFiles by mySites.guru
edges.es6.js80 lines, 2,537 bytes, from Joomla_6.1.1-Stable-Full_Package.zip
Raw History Compare with 6.1.0
md5
843e932def2b9e8632403babc25600f4
sha1
750c513849a81295cd278cdd5e8c81217adf082b
sha256
33cb9665b3f2a77b987791bea7755153c636bc71eda0ab980d71132e990dcc90
import { getEdgeColor } from './utils.es6.js';

/**
 * Generate styled edges based on transition data.
 * @param {Array<Object>} transitions - List of transitions.
 * @param {Object} options - Optional configuration - contains selected transition id.
 * @returns {Array<Object>} Styled edge definitions.
 */
export function generateStyledEdges(transitions, options = {}) {
  const {
    selectedId = null,
  } = options;

  // Group transitions by source-target pair
  const edgeGroups = {};
  transitions.forEach((transition) => {
    const sourceId = transition.from_stage_id === -1 ? 'from_any' : String(transition.from_stage_id);
    const targetId = String(transition.to_stage_id);
    const key = `${sourceId}__${targetId}`;
    if (!edgeGroups[key]) edgeGroups[key] = [];
    edgeGroups[key].push(transition);
  });

  // Assign offsetIndex for each edge in a group
  const edgeOffsetMap = new Map();
  Object.entries(edgeGroups).forEach(([key, group]) => {
    group.forEach((transition, idx) => {
      edgeOffsetMap.set(transition.id, idx - (group.length - 1) / 2);
    });
  });

  return transitions.map((transition) => {
    const sourceId = transition.from_stage_id === -1 ? 'from_any' : String(transition.from_stage_id);
    const targetId = String(transition.to_stage_id);

    const isSelected = transition.id === selectedId;
    const isBiDirectional = transitions.some(
      (t) => t.from_stage_id === transition.to_stage_id && t.to_stage_id === transition.from_stage_id,
    );

    // Offset index for multiple edges between same source-target
    let offsetIndex = edgeOffsetMap.get(transition.id) || 0;

    // If bidirectional, add a small extra offset to separate further
    if (isBiDirectional) {
      offsetIndex += transition.from_stage_id > transition.to_stage_id ? 1 : -1;
    }

    const edgeColor = getEdgeColor(transition, isSelected);
    const strokeWidth = isSelected ? 5 : 3;

    return {
      id: String(transition.id),
      source: sourceId,
      target: targetId,
      type: 'custom',
      animated: isSelected,
      style: {
        stroke: edgeColor,
        strokeWidth,
        strokeDasharray: transition.published ? undefined : '5,5',
        zIndex: isSelected ? 1000 : 1,
      },
      markerEnd: {
        type: 'arrow',
        width: 10,
        height: 10,
        color: edgeColor,
      },
      data: {
        ...transition,
        isSelected,
        isBiDirectional,
        offsetIndex,
        onEdit: () => {},
        onDelete: () => {},
      },
    };
  });
}

The same content is in 18 releases, Joomla 6.1.0-beta1 to 6.1.4. See them all, or every version of this file.