Widget:Napchart: Difference between revisions

From Polyphasic Sleep Wiki
No edit summary
Tag: Reverted
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
<div style="padding:5px">
<div style="padding:5px">
<div style="width:320px;height:320px;">
<div style="width:320px;height:320px;">
<canvas id="nc-<!--{$url|escape:'html'}-->" style="width:100%;height:100%;"></canvas></div></div>
<canvas id="nc-<!--{$url|escape:'html'}-->" width:100%;height:100%;"></canvas></div></div>
<script src="/napchart.min.js"></script>
<script src="/napchart.min.js"></script>
<!-- jQuery script tag removed -->
<script>
<script>
   var chartIdSuffix = "<!--{$url|escape:'html'}-->".split('/').pop();
   const urlValue = "<!--{$url|escape:'html'}-->"; // Template variable
   var canvasId = "nc-<!--{$url|escape:'html'}-->";
  const idSuffixForCtxAndData = urlValue.split('/').pop();
 
   const idSuffixForNapchartVar = urlValue.slice(21); // Original logic for this variable name part
   var ctx = document.getElementById(canvasId).getContext('2d');
 
    
   const canvasElement = document.getElementById("nc-" + urlValue);
   fetch('https://napchart.com/api/v2/getChart?chartid=' + chartIdSuffix)
  const context = canvasElement.getContext('2d');
     .then(response => response.json())
 
   window["ctx_" + idSuffixForCtxAndData] = context;
 
   const dataUrl = 'https://cache.polysleep.org/napcharts/' + idSuffixForCtxAndData + ".json";
 
  fetch(dataUrl)
     .then(response => {
      if (!response.ok) {
        throw new Error('Network response was not ok for ' + dataUrl);
      }
      return response.json();
    })
     .then(data => {
     .then(data => {
       Napchart.init(ctx, data['chartData']);
       window["myNapchart_" + idSuffixForNapchartVar] = Napchart.init(context, data['chartData']);
       console.log(data);
       console.log(data); // Original console.log
     })
     })
     .catch(error => console.error('Error fetching napchart data:', error));
     .catch(error => {
      console.error('Error fetching or initializing napchart:', error);
    });
</script>
</script>
</includeonly>
</includeonly>

Latest revision as of 13:58, 5 June 2025