33// Copyright (c) vis.gl contributors
44
55import { SAMPLE_GRAPH_DATASETS } from '../../../modules/graph-layers/test/data/graphs/sample-datasets' ;
6- import type { ExampleDefinition , ExampleStyles , LayoutType } from './layout-options' ;
6+ import type {
7+ ExampleDefinition ,
8+ ExampleStyles ,
9+ GraphExampleType ,
10+ LayoutType
11+ } from './layout-options' ;
712import witsRaw from '../../../modules/graph-layers/test/data/examples/wits.json' ;
813import sampleMultiGraph from './sample-multi-graph.json' ;
914
@@ -624,7 +629,8 @@ const ML_PIPELINE_EXAMPLE: ExampleDefinition = {
624629 data : dagPipelineDataset ,
625630 layouts : [ 'd3-dag-layout' ] ,
626631 layoutDescriptions : LAYOUT_DESCRIPTIONS ,
627- style : DAG_PIPELINE_STYLE
632+ style : DAG_PIPELINE_STYLE ,
633+ type : 'dag'
628634} ;
629635
630636const BROKEN_STYLESHEET_GRAPH : ExampleGraphData = {
@@ -684,7 +690,8 @@ const BROKEN_STYLESHEET_EXAMPLE: ExampleDefinition = {
684690 data : ( ) => cloneGraphData ( BROKEN_STYLESHEET_GRAPH ) ,
685691 layouts : [ 'd3-force-layout' ] ,
686692 layoutDescriptions : LAYOUT_DESCRIPTIONS ,
687- style : BROKEN_STYLESHEET
693+ style : BROKEN_STYLESHEET ,
694+ type : 'graph'
688695} ;
689696
690697export const EXAMPLES : ExampleDefinition [ ] = [
@@ -694,71 +701,80 @@ export const EXAMPLES: ExampleDefinition[] = [
694701 data : SAMPLE_GRAPH_DATASETS [ 'Les Miserable' ] ,
695702 layouts : [ 'd3-force-layout' , 'gpu-force-layout' , 'simple-layout' ] ,
696703 layoutDescriptions : LAYOUT_DESCRIPTIONS ,
697- style : LES_MISERABLES_STYLE
704+ style : LES_MISERABLES_STYLE ,
705+ type : 'graph'
698706 } ,
699707 {
700708 name : 'Random (20, 40)' ,
701709 description : 'Randomly connected graph with 20 nodes and 40 edges.' ,
702710 data : SAMPLE_GRAPH_DATASETS [ 'Random (20, 40)' ] ,
703711 layouts : [ 'd3-force-layout' , 'gpu-force-layout' , 'simple-layout' ] ,
704712 layoutDescriptions : LAYOUT_DESCRIPTIONS ,
705- style : RANDOM_20_40_STYLE
713+ style : RANDOM_20_40_STYLE ,
714+ type : 'graph'
706715 } ,
707716 {
708717 name : 'Random (100, 200)' ,
709718 description : 'Random graph with 100 nodes and 200 edges.' ,
710719 data : SAMPLE_GRAPH_DATASETS [ 'Random (100, 200)' ] ,
711720 layouts : [ 'd3-force-layout' , 'gpu-force-layout' , 'simple-layout' ] ,
712721 layoutDescriptions : LAYOUT_DESCRIPTIONS ,
713- style : RANDOM_100_200_STYLE
722+ style : RANDOM_100_200_STYLE ,
723+ type : 'graph'
714724 } ,
715725 {
716726 name : 'Random (1000, 2000)' ,
717727 description : 'Random graph with 1,000 nodes and 2,000 edges.' ,
718728 data : SAMPLE_GRAPH_DATASETS [ 'Random (1000, 2000)' ] ,
719729 layouts : [ 'gpu-force-layout' , 'd3-force-layout' , 'simple-layout' ] ,
720730 layoutDescriptions : LAYOUT_DESCRIPTIONS ,
721- style : RANDOM_1000_2000_STYLE
731+ style : RANDOM_1000_2000_STYLE ,
732+ type : 'graph'
722733 } ,
723734 {
724735 name : 'Random (5000, 3000)' ,
725736 description : 'Sparse random graph with 5,000 nodes and 3,000 edges.' ,
726737 data : SAMPLE_GRAPH_DATASETS [ 'Random (5000, 3000)' ] ,
727738 layouts : [ 'gpu-force-layout' , 'd3-force-layout' , 'simple-layout' ] ,
728739 layoutDescriptions : LAYOUT_DESCRIPTIONS ,
729- style : RANDOM_5000_3000_STYLE
740+ style : RANDOM_5000_3000_STYLE ,
741+ type : 'graph'
730742 } ,
731743 {
732744 name : 'Ladder (10)' ,
733745 description : 'Two parallel chains of 10 nodes connected like a ladder.' ,
734746 data : SAMPLE_GRAPH_DATASETS [ 'Ladder (10)' ] ,
735747 layouts : [ 'd3-force-layout' , 'gpu-force-layout' , 'simple-layout' ] ,
736748 layoutDescriptions : LAYOUT_DESCRIPTIONS ,
737- style : LADDER_10_STYLE
749+ style : LADDER_10_STYLE ,
750+ type : 'graph'
738751 } ,
739752 {
740753 name : 'BalancedBinTree (5)' ,
741754 description : 'Balanced binary tree with branching factor 2 and depth 5.' ,
742755 data : SAMPLE_GRAPH_DATASETS [ 'BalancedBinTree (5)' ] ,
743756 layouts : [ 'd3-force-layout' , 'gpu-force-layout' , 'simple-layout' ] ,
744757 layoutDescriptions : LAYOUT_DESCRIPTIONS ,
745- style : BALANCED_BIN_TREE_5_STYLE
758+ style : BALANCED_BIN_TREE_5_STYLE ,
759+ type : 'graph'
746760 } ,
747761 {
748762 name : 'BalancedBinTree (8)' ,
749763 description : 'Balanced binary tree with branching factor 2 and depth 8.' ,
750764 data : SAMPLE_GRAPH_DATASETS [ 'BalancedBinTree (8)' ] ,
751765 layouts : [ 'd3-force-layout' , 'gpu-force-layout' , 'simple-layout' ] ,
752766 layoutDescriptions : LAYOUT_DESCRIPTIONS ,
753- style : BALANCED_BIN_TREE_8_STYLE
767+ style : BALANCED_BIN_TREE_8_STYLE ,
768+ type : 'graph'
754769 } ,
755770 {
756771 name : 'Grid (10, 10)' ,
757772 description : '10x10 lattice grid graph.' ,
758773 data : SAMPLE_GRAPH_DATASETS [ 'Grid (10, 10)' ] ,
759774 layouts : [ 'd3-force-layout' , 'gpu-force-layout' , 'simple-layout' ] ,
760775 layoutDescriptions : LAYOUT_DESCRIPTIONS ,
761- style : GRID_10_10_STYLE
776+ style : GRID_10_10_STYLE ,
777+ type : 'graph'
762778 } ,
763779 {
764780 name : 'WattsStrogatz (100, 10, 0.06)' ,
@@ -767,7 +783,8 @@ export const EXAMPLES: ExampleDefinition[] = [
767783 data : SAMPLE_GRAPH_DATASETS [ 'WattsStrogatz (100, 10, 0.06)' ] ,
768784 layouts : [ 'd3-force-layout' , 'gpu-force-layout' , 'simple-layout' ] ,
769785 layoutDescriptions : LAYOUT_DESCRIPTIONS ,
770- style : WATTS_STROGATZ_STYLE
786+ style : WATTS_STROGATZ_STYLE ,
787+ type : 'graph'
771788 } ,
772789 {
773790 name : 'University hierarchy (radial)' ,
@@ -777,6 +794,7 @@ export const EXAMPLES: ExampleDefinition[] = [
777794 layouts : [ 'radial-layout' ] ,
778795 layoutDescriptions : LAYOUT_DESCRIPTIONS ,
779796 style : KNOWLEDGE_GRAPH_STYLE ,
797+ type : 'radial' ,
780798 getLayoutOptions : ( layout , _data ) =>
781799 layout === 'radial-layout'
782800 ? {
@@ -793,6 +811,7 @@ export const EXAMPLES: ExampleDefinition[] = [
793811 layouts : [ 'radial-layout' ] ,
794812 layoutDescriptions : LAYOUT_DESCRIPTIONS ,
795813 style : WITS_REGION_STYLE ,
814+ type : 'radial' ,
796815 getLayoutOptions : ( layout , _data ) =>
797816 layout === 'radial-layout'
798817 ? {
@@ -809,6 +828,7 @@ export const EXAMPLES: ExampleDefinition[] = [
809828 layouts : [ 'hive-plot-layout' ] ,
810829 layoutDescriptions : LAYOUT_DESCRIPTIONS ,
811830 style : KNOWLEDGE_GRAPH_STYLE ,
831+ type : 'hive' ,
812832 getLayoutOptions : ( layout , _data ) =>
813833 layout === 'hive-plot-layout'
814834 ? {
@@ -826,6 +846,7 @@ export const EXAMPLES: ExampleDefinition[] = [
826846 layouts : [ 'hive-plot-layout' ] ,
827847 layoutDescriptions : LAYOUT_DESCRIPTIONS ,
828848 style : WITS_REGION_STYLE ,
849+ type : 'hive' ,
829850 getLayoutOptions : ( layout , _data ) =>
830851 layout === 'hive-plot-layout'
831852 ? {
@@ -843,6 +864,7 @@ export const EXAMPLES: ExampleDefinition[] = [
843864 layouts : [ 'force-multi-graph-layout' ] ,
844865 layoutDescriptions : LAYOUT_DESCRIPTIONS ,
845866 style : MULTI_GRAPH_STYLE ,
867+ type : 'multi-graph' ,
846868 getLayoutOptions : ( layout , _data ) =>
847869 layout === 'force-multi-graph-layout'
848870 ? {
@@ -860,6 +882,7 @@ export const EXAMPLES: ExampleDefinition[] = [
860882 layouts : [ 'force-multi-graph-layout' ] ,
861883 layoutDescriptions : LAYOUT_DESCRIPTIONS ,
862884 style : WITS_REGION_STYLE ,
885+ type : 'multi-graph' ,
863886 getLayoutOptions : ( layout , _data ) =>
864887 layout === 'force-multi-graph-layout'
865888 ? {
@@ -874,4 +897,21 @@ export const EXAMPLES: ExampleDefinition[] = [
874897 BROKEN_STYLESHEET_EXAMPLE
875898] ;
876899
877- export const DEFAULT_EXAMPLE = ML_PIPELINE_EXAMPLE ;
900+ export function filterExamplesByType (
901+ examples : ExampleDefinition [ ] ,
902+ type ?: GraphExampleType
903+ ) : ExampleDefinition [ ] {
904+ if ( ! type ) {
905+ return examples ;
906+ }
907+
908+ return examples . filter ( ( example ) => example . type === type ) ;
909+ }
910+
911+ export function getExamplesByType ( type ?: GraphExampleType ) : ExampleDefinition [ ] {
912+ return filterExamplesByType ( EXAMPLES , type ) ;
913+ }
914+
915+ export function getDefaultExample ( type ?: GraphExampleType ) : ExampleDefinition | undefined {
916+ return getExamplesByType ( type ) [ 0 ] ;
917+ }
0 commit comments