Commit ca155f04 authored by xurizaemon's avatar xurizaemon
Browse files

Issue #3262781: Duplicated vertices and edges - refactor and tidy up

parent dfc56055
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
services:
  migrate_visualize.migrate_graph:
    class: Drupal\migrate_visualize\MigrateGraph
    arguments:
      - '@entity_field.manager'
      - '@string_translation'
+20 −34
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

/**
 * @file
 * Theme functions for Migrate Visualize.
 */

use Graphp\GraphViz\GraphViz;
@@ -9,7 +10,10 @@ use Drupal\Component\Utility\Html;
use Fhaculty\Graph\Exception\UnexpectedValueException;

/**
 * Provide an array of graph object types and default attributes.
 *
 * @return array
 *   The mapping of objects to attributes.
 */
function _migrate_visualize_graph_type_attributes() {
  return [
@@ -19,21 +23,12 @@ function _migrate_visualize_graph_type_attributes() {
    'destination:field' => ['color' => 'darkgoldenrod3', 'shape' => 'box'],
    'destination:meta' => ['color' => 'white', 'shape' => 'cds'],
    'process' => ['color' => 'blue', 'shape' => 'box'],
    'process:pipeline' => ['color' => 'blue', 'shape' => 'box'],
    'process:meta' => ['color' => 'white', 'shape' => 'box'],
    'process:pipeline:step' => ['color' => 'blue', 'shape' => 'box'],
    'process:pipeline' => ['color' => 'blue', 'shape' => 'box'],
    'process:pipeline' => ['color' => 1, 'shape' => 'box'],
    'process:meta' => ['color' => 2, 'shape' => 'box'],
    'process:pipeline:step' => ['color' => 3, 'shape' => 'box'],
    'process:pipeline' => ['color' => 4, 'shape' => 'box'],
    'plugin' => ['color' => 'cornflowerblue2', 'shape' => 'box'],
    'destination' => ['color' => 'darkgoldenrod3', 'shape' => 'box'],
  // 'source' => ['colorscheme' => 'bupu9',],
  //    'source:field' => ['colorscheme' => 'bupu9',],
  //    'process' => ['colorscheme' => 'bupu9',],
  //    'process:field' => ['colorscheme' => 'bupu9',],
  //    'process:pipeline:step' => ['colorscheme' => 'bupu9',],
  //    'plugin' => ['colorscheme' => 'bupu9',],
  //    'process:plugin' => ['colorscheme' => 'bupu9',],
  //    'destination' => ['color' => 'goldenrod3',],
  //    'destination:field' => ['color' => 'goldenrod3',],
  ];
}

@@ -77,19 +72,22 @@ function template_preprocess_migration_visualize_graphviz(array &$variables) {
    }
  }

  $graphvizAttributes = [
    'colorscheme' => 'dark28',
    'penwidth' => 2,
  ];

  /** @var \Fhaculty\Graph\Edge\Directed $edge */
  foreach ($graph->getEdges() as $k => $edge) {
    if (!$edge->getAttribute('graphviz.color')) {
      $edge->setAttribute('graphviz.colorscheme', 'oranges9');
    $edge->setAttribute('graphviz.color', $k % 6 + 2);
    foreach ($graphvizAttributes as $name => $value) {
      if (!$edge->getAttribute($name)) {
        $edge->setAttribute("graphviz.{$name}", $value);
      }
    if ($edge->getAttribute('migrate_visualize.debug')) {
      $edge->setAttribute('migrate_visualize.label', t('(@debug)', [
        '@label' => $edge->getAttribute('migrate_visualize.label'),
        '@debug' => $edge->getAttribute('migrate_visualize.debug'),
      ]));
    }
    $edge->setAttribute('graphviz.penwidth', '2');
    if ($comment = $edge->getAttribute('migrate_visualize.debug')) {
      $edge->setAttribute('graphviz.comment', $comment);
    }
    if ($label = $edge->getAttribute('migrate_visualize.label')) {
      $edge->setAttribute('graphviz.label', $label);
    }
@@ -142,12 +140,6 @@ function template_preprocess_migration_visualize_mermaid(array &$variables) {
      }
    }

    // If ($vertex->getAttribute('migrate_visualize.key')) {
    //      $vertex->setAttribute('migrate_visualize.label', t('@label (@debug)', [
    //        '@label' => $vertex->getAttribute('migrate_visualize.label'),
    //        '@debug' => $vertex->getAttribute('migrate_visualize.key'),
    //      ]));
    //    }.
    $vertexType = $vertex->getAttribute('migrate_visualize.type');
    if ($label = $vertex->getAttribute('migrate_visualize.label')) {
      $vertex->setAttribute('graphviz.label', $label);
@@ -176,12 +168,6 @@ function template_preprocess_migration_visualize_mermaid(array &$variables) {
  foreach ($graph->getEdges() as $k => $edge) {
    $edge->setAttribute('graphviz.colorscheme', 'oranges9');
    $edge->setAttribute('graphviz.color', $k % 6 + 2);
    if ($edge->getAttribute('migrate_visualize.debug')) {
      // $edge->setAttribute('migrate_visualize.label', t('(@debug)', [
      // '@label' => $edge->getAttribute('migrate_visualize.label'),
      //        '@debug' => $edge->getAttribute('migrate_visualize.debug'),
      //      ]));
    }
    $edge->setAttribute('graphviz.penwidth', '2');
    if ($label = $edge->getAttribute('migrate_visualize.label')) {
      $edge->setAttribute('graphviz.label', $label);
+2 −0
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ class ListingController extends ControllerBase {
   *
   * @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager
   *   The migration plugin manager.
   * @param \Drupal\Core\Extension\ModuleHandler $module_handler
   *   The module handler service.
   */
  public function __construct(MigrationPluginManagerInterface $migration_plugin_manager, ModuleHandler $module_handler) {
    $this->migrationPluginManager = $migration_plugin_manager;
+5 −3
Original line number Diff line number Diff line
@@ -32,10 +32,12 @@ class VisualizeController extends ControllerBase {
   *
   * @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager
   *   The migration plugin manager.
   * @param Drupal\migrate_visualize\MigrateGraph $migrate_graph
   *   The migration graph service.
   */
  public function __construct(MigrationPluginManagerInterface $migration_plugin_manager, MigrateGraph $migration_graph) {
  public function __construct(MigrationPluginManagerInterface $migration_plugin_manager, MigrateGraph $migrate_graph) {
    $this->migrationPluginManager = $migration_plugin_manager;
    $this->migrationGraph = $migration_graph;
    $this->migrationGraph = $migrate_graph;
  }

  /**
@@ -59,7 +61,7 @@ class VisualizeController extends ControllerBase {
      ->getForm('Drupal\migrate_visualize\Form\VisualizeMigrationSwitcherForm');

    $migrationInstance = $this->migrationPluginManager->createInstance($migration);
    if ($migration !== '' && $migrationInstance === false) {
    if ($migration !== '' && $migrationInstance === FALSE) {
      $this->messenger()
        ->addError($this->t('Migration not found: @migration', [
          '@migration' => $migration,
+4 −4
Original line number Diff line number Diff line
@@ -35,14 +35,14 @@ class SettingsForm extends ConfigFormBase {
      '#type' => 'radios',
      '#title' => $this->t('Select visualization method:'),
      '#options' => [
        'mermaidjs' => 'MermaidJS',
        'graphviz' => 'GraphViz',
        'mermaidjs' => $this->t('MermaidJS'),
        'graphviz' => $this->t('GraphViz'),
      ],
      'mermaidjs' => [
        '#description' => 'Charts rendered in browser (uses CDN for MermaidJS library).',
        '#description' => $this->t('Charts rendered in browser (uses CDN for MermaidJS library).'),
      ],
      'graphviz' => [
        '#description' => 'Charts rendered on server (requires <strong>graphviz</strong> installed on server).',
        '#description' => $this->t('Charts rendered on server (requires <strong>graphviz</strong> installed on server).'),
      ],
      '#default_value' => $this->config('migrate_visualize.settings')->get('display_mode'),
    ];
Loading