Skip to content

Commit

Permalink
Adding Tooltips and Alt texts for Links
Browse files Browse the repository at this point in the history
  • Loading branch information
jpadfield committed Aug 15, 2022
1 parent a734921 commit d285e54
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 34 deletions.
14 changes: 11 additions & 3 deletions default.csv
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
//Graph LR - this is an optional special comment that requests TB (Top Bottom) or a LR (Left Right) flow diagram, the default is LR
//The first line is an optional special comment that requests TB (Top Bottom) or a LR (Left Right) flow diagram, the default is LR - the style of the nodes linking the displayed concepts can also be adjusted with the addition or omission of the extra term "fix"
// Extra formats can be selected using a | separated pair of terms - the format only needs to be defined the first time an entities is referenced
Dynamic Modeller was created by Joseph Padfield object|actor
Dynamic Modeller was created by Joseph Padfield|https://orcid.org/0000-0002-2572-6428 object|actor
Dynamic Modeller is based on https://mermaid-js.github.io/mermaid
Dynamic Modeller designed to "Allow users to create modelling flow-diagrams from simple lists of triples"
Dynamic Modeller works with Triples
Dynamic Modeller can use Subgraphs
Dynamic Modeller allows the use of Tooltips |document
Tooltips tooltip Also known as hover text or labels
Tooltips for example Example Concept with a Tooltip |thing
Example Concept with a Tooltip tooltip This approach can be used to hide comments on larger flow diagrams to simplify their appearance but without loosing the extra descriptions and information.
Tooltips has comment "Tooltips are added to link based nodes, with alternative texts, automatically, but they can also be added manually through an additional triple using the 'tooltip' property to link the item to the required text:<br/>Label tooltip Required hover text "
Dynamic Modeller can format Links with alternative labels
Links with alternative labels for example Example Formats |url
Links with alternative labels has comment "This can be achieved by adding the alternative label as a <b>'|'</b> separated suffix, such as:<br/>'ALT TEXT|https://full.url/or/link' "
Dynamic Modeller uses https://github.com/ariutta/svg-pan-zoom
https://github.com/ariutta/svg-pan-zoom has comment "svg-pan-zoom is used to allow users to use their mouse to navigate around and zoom in and out of larger models"
// Comments can be added simply by starting a line with // or ##
Expand All @@ -23,7 +31,7 @@ Styled Subgraphs has comment "Any of the existing standard formats can automatic
//end base
Triples are Tab separated
Triples have some "Basic automatic formatting, but it is possible to force some further options using additional instructions after the third value in a given triple"
Triples format examples https://research.ng-london.org.uk/modelling/?example=example_formats
Triples format examples Example Formats|https://research.ng-london.org.uk/modelling/?example=example_formats
Dynamic Modeller can also "Start with data formatted as JSON, which is then automatically converted to Triples, please check the triples and report any errors in the conversion"
// Blank node can be added as shown
_BN has type Production event_bn|
Expand Down
199 changes: 168 additions & 31 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

// Added tests for hover text - it just uses a default example text just now
// Added the option of fixing the properties tags to the lines or letting them float - add "fix" after //Graph LR fix
$versions = array(
"jquery" => "3.6.0",
"bootstrap" => "5.1.3",
//"mermaid" => "8.14.0"
"mermaid" => "9.1.3"
"mermaid" => "9.1.4"
);

if (isset($_GET["debug"])) {}
Expand All @@ -16,7 +17,8 @@

if (isset($_SERVER["HTTP_X_FORWARDED_HOST"]) and $_SERVER["HTTP_X_FORWARDED_HOST"] == "round4.ng-london.org.uk")
{$thisPage = "/ex".$thisPage;}


$fixlinks = false;
$orientation = "LR";
$live_edit_link = "./";
$default = file_get_contents("default.csv");
Expand All @@ -25,6 +27,13 @@
$usedClasses = array();
$allClasses = formatClassDef ($config["format"]);

$doc_example_links = array(
"LRNF" => array("TBNF", "LRF", "LR"),
"TBNF" => array("LRNF", "TBF", "TB"),
"LRF" => array("TBF", "LRNF", "LR fix"),
"TBF" => array("LRF", "TBNF", "TB fix"),
);

if (isset($_POST["triplesTxt"]) and $_POST["triplesTxt"])
{$triplesTxt = checkTriples ($_POST["triplesTxt"]);}
else if (isset($_GET["example"]) and isset($examples[$_GET["example"]]))
Expand All @@ -33,26 +42,33 @@
{$triplesTxt = gzuncompress(base64_decode(urldecode($ex["data"])));}
else
{$triplesTxt = checkTriples (file_get_contents($ex["uri"]));}}
else if (isset($_GET["example"]) and isset($doc_example_links[$_GET["example"]]))
{$triplesTxt = docExampleTriples ($doc_example_links[$_GET["example"]]);}
else if (isset($_GET["url"]))
{$triplesTxt = checkTriples (file_get_contents($_GET["url"]));}
else if (isset($_GET["data"]))
{$triplesTxt = gzuncompress(base64_decode($_GET["data"]));}
else
{$triplesTxt = checkTriples ($default);}
{
$triplesTxt = docExampleTriples ($doc_example_links["LRNF"]);
//$triplesTxt = checkTriples ($default);
}

// Thumbnail display might be possible with
//
// O4 -- "crm:P48_has_preferred_identifier" -->O6[&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<img src='https://research.ng-london.org.uk/iiif/pics/tmp/raphael_pyr/N-1171/08_Images_of_Frames/raphael%20capitals%20right%20and%20left-PYR.tif/full/,125/0/default.jpg'/>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp]


// The text "&nbsp"s are required to get the box to be bigger - it results in a slide like display.

// in 9.1.4 it seems to work without the "&nbsp"s
// O4 -- "crm:P48_has_preferred_identifier" -->O6[<img src='https://research.ng-london.org.uk/iiif/pics/tmp/raphael_pyr/N-1171/08_Images_of_Frames/raphael%20capitals%20right%20and%20left-PYR.tif/full/,125/0/default.jpg'/>];

$data = urlencode(base64_encode(gzcompress($triplesTxt)));
$bookmark = $thisPage.'?data='.$data;

//prg(0, $triplesTxt);
$triples = getCleanTriples($triplesTxt);
//prg(1, $triples);
//prg(0, $triples);
$cleanTriplesTxt = implode("\n", $triples);
//prg(0, $cleanTriplesTxt);
$raw = getRaw($triples);
Expand All @@ -66,6 +82,31 @@

////////////////////////////////////////////////////////////////////////


function docExampleTriples ($ex)
{
global $default;

$layout_comments = array(
"TB" => array ("Graph TB", "In addition to the default left-right (LR) orientation diagrams can also be arranged from the top-bottom (TB)"),
"LR" => array ("Graph LR", "In addition to the optional top-bottom (TB) orientation diagrams can also be arranged with the default Left-Right (LR) orientation"),
"F" => array ("Fixed Properties", "This format extends and straightens the lines linking the various concepts together to ensure there is a flat section of the line for the link property to be specifically fixed to. This can result in a larger overall diagram, but can be required when there are higher numbers of property links being displayed together"),
"NF" => array ("Relaxed Properties", "This format curves the lines linking the various concepts together to minimise the size of the generated diagram.")
);

$triplesTxt = "//Graph $ex[2] \n".checkTriples ($default);

$do = str_split($ex[0], 2);
$triplesTxt .= "\nDynamic Modeller\tcan be formatted with\t".$layout_comments[$do[0]][0]."|https://research.ng-london.org.uk/modelling/?example=$ex[0]";
$triplesTxt .= "\n".$layout_comments[$do[0]][0]."\thas comment\t".json_encode($layout_comments[$do[0]][1]);

$do = str_split($ex[1], 2);
$triplesTxt .= "\nDynamic Modeller\tcan be formatted with\t".$layout_comments[$do[1]][0]."|https://research.ng-london.org.uk/modelling/?example=$ex[1]";
$triplesTxt .= "\n".$layout_comments[$do[1]][0]."\thas comment\t".json_encode($layout_comments[$do[1]][1]);

return ($triplesTxt);
}

function buildExamplesDD ()
{
global $examples;
Expand Down Expand Up @@ -171,6 +212,11 @@ function buildPage ($triplesTxt, $mermaid)

$bw = "26px";

$vs[0] = $versions["bootstrap"];
$vs[1] = $versions["jquery"];
$vs[2] = $versions["bootstrap"];
$vs[3] = $versions["mermaid"];

ob_start();
echo <<<END
Expand All @@ -180,9 +226,30 @@ function buildPage ($triplesTxt, $mermaid)
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta charset="utf-8">
<title>Dynamic Simple Modelling</title>
<link href="https://unpkg.com/bootstrap@${versions[bootstrap]}/dist/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="https://unpkg.com/bootstrap@$vs[0]/dist/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="local-dev.css" rel="stylesheet" type="text/css">
<style></style>
<style>
/* Added to get the hover texts or tooltips to appear and be formatted.
based on values in https://unpkg.com/browse/[email protected]/dist/mermaid.css */
div.mermaidTooltip {
position: absolute;
text-align: center;
max-width: 300px;
padding: 5px;
font-family: 'trebuchet ms', verdana, arial;
font-size: 1rem;
background: #ffffde;
border: 1px solid #aaaa33;
border-radius: 5px;
pointer-events: none;
z-index: 10000;
}
</style>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-P2QQWTBKX7"></script>
<script>
Expand Down Expand Up @@ -248,9 +315,9 @@ function gtag(){dataLayer.push(arguments);}
$modal
</div><!-- CLOSE PAGE -->
<script src="https://unpkg.com/jquery@${versions[jquery]}/dist/jquery.min.js"></script> <script src="https://unpkg.com/[email protected]/dist/js/tether.min.js"></script>
<script src="https://unpkg.com/bootstrap@${versions[bootstrap]}/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://unpkg.com/mermaid@${versions[mermaid]}/dist/mermaid.min.js"></script>
<script src="https://unpkg.com/jquery@$vs[1]/dist/jquery.min.js"></script> <script src="https://unpkg.com/[email protected]/dist/js/tether.min.js"></script>
<script src="https://unpkg.com/bootstrap@$vs[2]/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://unpkg.com/mermaid@$vs[3]/dist/mermaid.min.js"></script>
<script src="./svg-pan-zoom.js" crossorigin="anonymous"></script>
<script src="local.js"></script>
<script></script>
Expand Down Expand Up @@ -519,7 +586,7 @@ function getCleanTriples($triplesTxt)

function getRaw($data)
{
global $orientation, $config;
global $orientation, $config, $fixlinks;

$au = $config["unique"]["regex"];
$output = array();
Expand Down Expand Up @@ -568,6 +635,7 @@ function getRaw($data)
else if((preg_match("/^[\/][\/][ ]*[gG]raph[ ]*([LT][BR])(.*)$/", $line, $m)) or
(preg_match("/^[\/][\/][ ]*[gG]raph[ ]*([LT][BR])(.*)$/", $trip[0], $m)))
{$orientation = $m[1];
if (strtolower(trim($m[2])) == "fix") {$fixlinks = true;}
$trip = array($line);}
else if(preg_match("/^[\/][\/][ ]*[sS][uU][bB][gG][Rr][Aa][Pp][Hh[ ]*(.*)$/", $line, $m))
{$trip = array("subgraph", $m[1], "");}
Expand Down Expand Up @@ -683,7 +751,7 @@ function formatClassDef ($formats)

function Mermaid_formatData ($selected)
{
global $orientation, $live_edit_link, $config, $allClasses, $usedClasses;
global $orientation, $live_edit_link, $config, $allClasses, $usedClasses, $fixlinks;

$defs = "";
$things = array();
Expand All @@ -708,7 +776,7 @@ function Mermaid_formatData ($selected)
}
else if (in_array($t[0], array("end")))
{
$defs .= "\n$t[0] $t[1]\n";
$defs .= "\n$t[0]\n";
$sgID = array_pop($sgIDs);
if ($t[1])
{
Expand All @@ -717,14 +785,61 @@ function Mermaid_formatData ($selected)
$defs .= "class $sgID $t[1]\n";
}
}
else if ($t[1] == "tooltip")
{
// Some of this section is a duplication of the steps below so it might be good to look at moving this tooltips section down later

// Allow the user to force the formatting classes used for the
// object and subject
$fcs = array(false, false);

if(isset($t[3]))
{
$fcs = explode ("|", $t[3]);
if(!isset($fcs[1]))
{$fcs = explode ("@@", $t[3]);}

if(!isset($fcs[1]))
{$fcs[1] = false;}
}

if (!$fcs[1] and isset($t[1]) and $t[1] == "has note")
{$fcs = array(false, "note");}

if (!isset($things[$t[0]]))
{$things[$t[0]] = "O".$no;

// Default objects to object class
if (!$fcs[0] and !preg_match ("/^[a-zA-Z]+[:].+$/", $t[0], $m))
{
if ($t["bn"] ) {$fcs[0] = "object_bn";}
else {$fcs[0] = "object";}
}

$defs .= Mermaid_defThing($t[0], $no, $fcs[0]);
$no++;}
$defs .= "click ".$things[$t[0]]." function \"$t[2]\"; \n";}
else
{
// Format the displayed text, either wrapping or removing numbers
// used to indicate separate instances of the same text/name
if (count_chars($t[2]) > 60)
{$use = wordwrap($t[2], 60, "<br/>", true);}
else
{$use = $t[2];}
{
// Catch URL with an ALT text suffix
$t0extraLink = false;
$t2extraLink = false;

if (preg_match("/^([^|]+)[|](http.+)$/", $t[0], $t0m) or
preg_match("/^([^|]+)[|](\?.+)$/", $t[0], $t0m))
{$t0extraLink = $t0m[2];
$t[0] = $t0m[1];}
if (preg_match("/^([^|]+)[|](http.+)$/", $t[2], $t2m) or
preg_match("/^([^|]+)[|](\?.+)$/", $t[2], $t2m))
{$t2extraLink = $t2m[2];
$t[2] = $t2m[1];}

// Format the displayed text, either wrapping or removing numbers
// used to indicate separate instances of the same text/name
if (count_chars($t[2]) > 60)
{$use = wordwrap($t[2], 60, "<br/>", true);}
else
{$use = $t[2];}

// If entities have been numbered to force them to be unique
// hide the number from being displayed
Expand Down Expand Up @@ -752,6 +867,8 @@ function Mermaid_formatData ($selected)

if (!$fcs[1] and isset($t[1]) and $t[1] == "has note")
{$fcs = array(false, "note");}
else if (!$fcs[1] and $t2extraLink)
{$fcs[1] = "url";}

if (!isset($things[$t[0]]))
{
Expand All @@ -767,15 +884,16 @@ function Mermaid_formatData ($selected)
$defs .= Mermaid_defThing($t[0], $no, $fcs[0]);
$no++;
}

// NEED TO REVISIT THE AUTOMATIC ASSIGNMENT OF object class
// NEED NEW RULES
if (!isset($things[$t[2]]))
{
if (preg_match ("/^([a-zA-Z]+)([:].+)$/", $t[2], $m))
{$prf = strtolower($m[1]);
//$t[2] = $prf.$m[2];
}
{
$prf = strtolower($m[1]);
//$t[2] = $prf.$m[2];
}
else
{$prf = false;}

Expand All @@ -787,7 +905,17 @@ function Mermaid_formatData ($selected)
else if (!$fcs[1] and $t["type"] and !in_array(strtolower($prf), array_keys($config["prefix"])))
{$fcs[1] = "type";}
$defs .= Mermaid_defThing($t[2], $no, $fcs[1]);
$no++;}
$no++;}

// If an ALT suffix was supplied for a link, add ref to the link back in with a tool tip.
if ($t0extraLink)
{$pp = pathinfo($t0extraLink);
$tt = "Link to: $pp[dirname] ...";
$defs .= "click ".$things[$t[0]]." \"$t0extraLink\" \"$tt\"; \n";}
if ($t2extraLink)
{$pp = pathinfo($t2extraLink);
$tt = "Link to: $pp[dirname] ...";
$defs .= "click ".$things[$t[2]]." \"$t2extraLink\" \"$tt\"; \n";}

// need to check for an image and if so update $use
// O6[&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<img src='https://research.ng-london.org.uk/iiif/pics/tmp/raphael_pyr/N-1171/08_Images_of_Frames/raphael%20capitals%20right%20and%20left-PYR.tif/full/,125/0/default.jpg'/>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp]
Expand All @@ -796,10 +924,17 @@ function Mermaid_formatData ($selected)
$use = "[&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp$tmp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp]";}
else
{$use = "[\"".$use."\"]";}

$defs .= $things[$t[0]]." -- ".$t[1]. " -->".$things[$t[2]].
$use."\n";
}

if ($fixlinks)
{$lformat = " ---->|$t[1]|";}
else
{$lformat = " -- ".$t[1]. " -->";}

//$defs .= $things[$t[0]]." -- ".$t[1]. " -->".$things[$t[2]].
$defs .= $things[$t[0]].$lformat.$things[$t[2]].
$use."\n";
}

}//exit;

$defs = "graph $orientation\n".
Expand Down Expand Up @@ -840,7 +975,9 @@ function Mermaid_defThing ($var, $no, $fc=false)
{
$cls = $a["format"] ;
if (isset($a["url"]))
{$click = "click ".$code." \"".$a["url"]."$m[1]\"\n";}
{$pp = pathinfo($a["url"]);
$tt = "Link to: $pp[dirname] ...";
$click = "click ".$code." \"".$a["url"]."$m[1]\" \"$tt\"; \n";}
else if(preg_match("/^http.+$/", $var, $m))
{$click = "click ".$code." \"".$var."\"\n";}
break;
Expand Down

0 comments on commit d285e54

Please sign in to comment.