Widget:Napchart: Difference between revisions

From Polyphasic Sleep Wiki
mNo edit summary
No edit summary
 
(39 intermediate revisions by the same user not shown)
Line 1: Line 1:
<includeonly>
<includeonly>
<div style="width:280px;height:280px;margin:5px">
<div style="padding:5px">
<canvas id="myNapchart" width:100%;height:100%"></canvas></div>
<div style="width:320px;height:320px;">
<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>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- jQuery script tag removed -->
<script>
<script>
   var ctx = document.getElementById("myNapchart").getContext('2d')
   const urlValue = "<!--{$url|escape:'html'}-->"; // Template variable
   var id = "zmdb8"
  const idSuffixForCtxAndData = urlValue.split('/').pop();
  var ch;
  const idSuffixForNapchartVar = urlValue.slice(21); // Original logic for this variable name part
   $.getJSON('https://Admin6174-eval-prod.apigee.net/get?chartid=' + id, function(data) {
 
    var myNapchart = Napchart.init(ctx, data['chartData'])
  const canvasElement = document.getElementById("nc-" + urlValue);
    console.log(data)
  const context = canvasElement.getContext('2d');
});
 
 
   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 => {
      window["myNapchart_" + idSuffixForNapchartVar] = Napchart.init(context, data['chartData']);
      console.log(data); // Original console.log
    })
    .catch(error => {
      console.error('Error fetching or initializing napchart:', error);
    });
</script>
</script>
</includeonly>
</includeonly>

Latest revision as of 13:58, 5 June 2025