MediaWiki:Gadget-GlossaryGraph.js: Difference between revisions

Jump to navigation Jump to search
AdminIsidore (talk | contribs)
No edit summary
AdminIsidore (talk | contribs)
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 7: Line 7:
             if (!pageTitle) {
             if (!pageTitle) {
                 $container.text('Error: No page title');
                 $container.text('Error: No page title');
                console.error('No page title found for container');
                 return;
                 return;
             }
             }


            // Extract term (e.g., "Dictum" from "Lingua:Dictum")
             var term = pageTitle.split(':').pop().toLowerCase();
             var term = pageTitle.split(':').pop();
 
            // Query SMW for pages with Glossary-Definition
            var smwQuery = encodeURIComponent('[[Category:Glossary Entries]][[Glossary-Definition::+*]]|?Glossary-Term|limit=50');
             new mw.Api().get({
             new mw.Api().get({
                 action: 'ask',
                 action: 'askargs',
                 query: smwQuery,
                 conditions: 'Category:Glossary Entries',
                 format: 'json'
                printouts: 'Glossary-Term|Glossary-Definition',
                parameters: 'limit=50',
                 format: 'json',
                formatversion: 2
             }).done(function(data) {
             }).done(function(data) {
                console.log('SMW API response:', JSON.stringify(data, null, 2));
                 var results = data.query.results || {};
                 var results = data.query.results || {};
                 var links = [];
                 var links = [];
                 for (var page in results) {
                 for (var page in results) {
                     if (results.hasOwnProperty(page) && page !== pageTitle) {
                     if (results.hasOwnProperty(page) && page !== pageTitle) {
                         var definition = results[page].printouts['Glossary-Definition'] || [];
                         var definitions = results[page].printouts['Glossary-Definition'] || [];
                         // Check if definition contains the term (case-insensitive)
                         if (definitions.length > 0 && definitions.some(function(def) {
                        if (definition.some(function(def) {
                             return def.toLowerCase().indexOf(term) !== -1;
                             return def.toLowerCase().indexOf(term.toLowerCase()) !== -1;
                         })) {
                         })) {
                             links.push({ title: page });
                             links.push({ title: page });
Line 36: Line 36:
                 if (links.length === 0) {
                 if (links.length === 0) {
                     $container.text('No connections found.');
                     $container.text('No connections found.');
                    console.log('No connections found for term:', term);
                     return;
                     return;
                 }
                 }
Line 67: Line 68:


                 var node = svg.append('g')
                 var node = svg.append('g')
                     .selectAll('circle')
                     .selectAll('g')
                     .data(nodes)
                     .data(nodes)
                     .enter().append('circle')
                     .enter().append('g')
                    .attr('r', 10)
                    .attr('fill', '#00CC00')
                     .call(d3.drag()
                     .call(d3.drag()
                         .on('start', function(event, d) {
                         .on('start', function(event, d) {
Line 87: Line 86:
                             d.fy = null;
                             d.fy = null;
                         }));
                         }));
                node.append('circle')
                    .attr('r', 10)
                    .attr('fill', '#00CC00');
                node.append('text')
                    .attr('dx', 12)
                    .attr('dy', '.35em')
                    .text(d => d.id.split(':').pop()) // Show short term name (e.g., "Dictum")
                    .style('fill', '#00FF00')
                    .style('font-family', 'IBMPlexMono, "Courier New", monospace')
                    .style('font-size', '12px');


                 node.append('title').text(d => d.id);
                 node.append('title').text(d => d.id);
Line 95: Line 106:
                         .attr('x2', d => d.target.x)
                         .attr('x2', d => d.target.x)
                         .attr('y2', d => d.target.y);
                         .attr('y2', d => d.target.y);
                     node.attr('cx', d => d.x)
                     node.attr('transform', d => `translate(${d.x},${d.y})`);
                        .attr('cy', d => d.y);
                 });
                 });
             }).fail(function(error) {
             }).fail(function(jqXHR, textStatus, errorThrown) {
                 $container.text('Error: API request failed');
                 $container.text('Error: API request failed');
                 console.error('SMW API error:', error);
                 console.error('SMW API error details:', {
                    status: textStatus,
                    error: errorThrown,
                    responseText: jqXHR.responseText,
                    statusCode: jqXHR.status,
                    url: 'https://www.ooda.wiki/api.php?action=askargs&conditions=Category:Glossary%20Entries&printouts=Glossary-Term|Glossary-Definition&parameters=limit=50&format=json&formatversion=2'
                });
             });
             });
         });
         });
     });
     });
});
});