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
 
(4 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;
             }
             }


             var term = pageTitle.split(':').pop().toLowerCase();
             var term = pageTitle.split(':').pop().toLowerCase();
            var smwQuery = encodeURIComponent('[[Category:Glossary Entries]]|?Glossary-Term|?Glossary-Definition');
             new mw.Api().get({
             new mw.Api().get({
                 action: 'ask',
                 action: 'askargs',
                 query: smwQuery,
                 conditions: 'Category:Glossary Entries',
                 limit: 50, // Limit as separate param
                 printouts: 'Glossary-Term|Glossary-Definition',
                 format: 'json'
                parameters: 'limit=50',
                 format: 'json',
                formatversion: 2
             }).done(function(data) {
             }).done(function(data) {
                 console.log('SMW API response:', 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 = [];
Line 34: 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 65: 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 85: 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 93: 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(jqXHR, textStatus, errorThrown) {
             }).fail(function(jqXHR, textStatus, errorThrown) {
Line 101: Line 113:
                     status: textStatus,
                     status: textStatus,
                     error: errorThrown,
                     error: errorThrown,
                     responseText: jqXHR.responseText
                     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'
                 });
                 });
             });
             });