{"spec_id":"network-weighted","library":"echarts","language":"javascript","code":"// anyplot.ai\n// network-weighted: Weighted Network Graph with Edge Thickness\n// Library: echarts 6.1.0 | JavaScript 22.23.2\n// Quality: 93/100 | Created: 2026-09-02\n\n//# anyplot-orientation: square\nconst t = window.ANYPLOT_TOKENS;\n\n// --- Data (in-memory, deterministic) ----------------------------------------\n// Research collaboration network: institutions grouped by field, edge weight\n// = number of co-authored papers (2020-2024).\nconst categories = [\n  { name: \"Biology\" },\n  { name: \"Computer Science\" },\n  { name: \"Physics\" },\n  { name: \"Chemistry\" },\n];\n\nconst nodeCategory = {\n  \"Stanford Bio Lab\": 0,\n  \"MIT Genomics\": 0,\n  \"Broad Institute\": 0,\n  \"Wellcome Sanger\": 0,\n  \"MIT CSAIL\": 1,\n  \"Berkeley AI Research\": 1,\n  DeepMind: 1,\n  \"Carnegie Mellon\": 1,\n  CERN: 2,\n  Fermilab: 2,\n  \"Max Planck Physics\": 2,\n  \"Caltech Physics\": 2,\n  \"Scripps Research\": 3,\n  \"ETH Zurich Chem\": 3,\n  \"Max Planck Chem\": 3,\n  \"Tokyo Chem Institute\": 3,\n};\n\nconst edges = [\n  [\"Stanford Bio Lab\", \"MIT Genomics\", 9],\n  [\"Stanford Bio Lab\", \"Broad Institute\", 14],\n  [\"MIT Genomics\", \"Broad Institute\", 11],\n  [\"Broad Institute\", \"Wellcome Sanger\", 7],\n  [\"MIT Genomics\", \"Wellcome Sanger\", 5],\n  [\"MIT CSAIL\", \"Berkeley AI Research\", 16],\n  [\"MIT CSAIL\", \"DeepMind\", 12],\n  [\"MIT CSAIL\", \"Carnegie Mellon\", 13],\n  [\"Berkeley AI Research\", \"DeepMind\", 8],\n  [\"Berkeley AI Research\", \"Carnegie Mellon\", 6],\n  [\"DeepMind\", \"Carnegie Mellon\", 4],\n  [\"CERN\", \"Fermilab\", 15],\n  [\"CERN\", \"Max Planck Physics\", 10],\n  [\"CERN\", \"Caltech Physics\", 9],\n  [\"Fermilab\", \"Caltech Physics\", 6],\n  [\"Max Planck Physics\", \"Caltech Physics\", 5],\n  [\"Scripps Research\", \"ETH Zurich Chem\", 8],\n  [\"Scripps Research\", \"Max Planck Chem\", 6],\n  [\"ETH Zurich Chem\", \"Max Planck Chem\", 10],\n  [\"Max Planck Chem\", \"Tokyo Chem Institute\", 7],\n  [\"Scripps Research\", \"Tokyo Chem Institute\", 4],\n  [\"MIT Genomics\", \"MIT CSAIL\", 5],\n  [\"Broad Institute\", \"Max Planck Chem\", 3],\n  [\"CERN\", \"MIT CSAIL\", 4],\n  [\"Scripps Research\", \"Stanford Bio Lab\", 6],\n  [\"Max Planck Physics\", \"Max Planck Chem\", 5],\n];\n\n// Weighted degree (sum of incident edge weights) drives node size.\nconst weightedDegree = {};\nfor (const [source, target, weight] of edges) {\n  weightedDegree[source] = (weightedDegree[source] || 0) + weight;\n  weightedDegree[target] = (weightedDegree[target] || 0) + weight;\n}\nconst degrees = Object.values(weightedDegree);\nconst minDegree = Math.min(...degrees);\nconst maxDegree = Math.max(...degrees);\nconst weights = edges.map((edge) => edge[2]);\nconst minWeight = Math.min(...weights);\nconst maxWeight = Math.max(...weights);\n\nconst nodeSize = (name) =>\n  34 + ((weightedDegree[name] - minDegree) / (maxDegree - minDegree)) * 46;\nconst edgeWidth = (weight) =>\n  2 + ((weight - minWeight) / (maxWeight - minWeight)) * 13;\n\n// --- Init ---------------------------------------------------------------------\nconst chart = echarts.init(document.getElementById(\"container\"));\n\n// --- Option ---------------------------------------------------------------------\nchart.setOption({\n  animation: false,\n  color: t.palette,\n  backgroundColor: \"transparent\",\n  title: {\n    text: \"network-weighted · javascript · echarts · anyplot.ai\",\n    subtext: `Edge thickness = co-authored papers, ${minWeight}–${maxWeight} (2020–2024) · node size = total collaborations`,\n    left: \"center\",\n    textStyle: { color: t.ink, fontSize: 22, fontWeight: 500 },\n    subtextStyle: { color: t.inkSoft, fontSize: 15 },\n  },\n  legend: {\n    data: categories.map((category) => category.name),\n    bottom: 8,\n    left: \"center\",\n    textStyle: { color: t.ink, fontSize: 16 },\n    itemWidth: 16,\n    itemHeight: 16,\n  },\n  series: [\n    {\n      type: \"graph\",\n      layout: \"force\",\n      top: 150,\n      bottom: 170,\n      left: 150,\n      right: 210,\n      roam: false,\n      draggable: true,\n      categories,\n      force: {\n        initLayout: \"circular\",\n        repulsion: 1550,\n        edgeLength: [100, 300],\n        gravity: 0.06,\n        friction: 0.6,\n        layoutAnimation: false,\n      },\n      label: {\n        show: true,\n        position: \"bottom\",\n        color: t.inkSoft,\n        fontSize: 17,\n      },\n      labelLayout: { moveOverlap: \"shiftX\" },\n      lineStyle: {\n        color: t.inkSoft,\n        opacity: 0.45,\n        curveness: 0.08,\n      },\n      emphasis: {\n        focus: \"adjacency\",\n        lineStyle: { opacity: 0.9 },\n        label: { fontWeight: \"bold\" },\n      },\n      data: Object.keys(nodeCategory).map((name) => ({\n        name,\n        category: nodeCategory[name],\n        symbolSize: nodeSize(name),\n      })),\n      links: edges.map(([source, target, weight]) => ({\n        source,\n        target,\n        value: weight,\n        lineStyle: { width: edgeWidth(weight) },\n      })),\n    },\n  ],\n});\n"}