Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript Polyline #183

Open
etm opened this issue Sep 20, 2023 · 1 comment
Open

Javascript Polyline #183

etm opened this issue Sep 20, 2023 · 1 comment

Comments

@etm
Copy link

etm commented Sep 20, 2023

I can not find out how to draw a polyline with discontinuities (Sprungstellen) in javascript? Is this even possible?

An intuitive solution would be to set corresponding x,y pairs to null.

@danielkaiser
Copy link
Contributor

Hi @etm,

using NaN for x and y should produce discontinuities in a polyline:

<!doctype html>
<html lang="en-us">
<head>
  <meta charset="utf-8">
  <title>Polyline using gr.js</title>
</head>
<body>
  <canvas id="example-canvas" width="500" height="500"></canvas>
  <script src="https://gr-framework.org/downloads/gr-latest.js"></script>
  <script>
    GR.ready(function() {
      var gr = new GR('example-canvas');

      gr.setviewport(0, 1, 0, 1);

      var x = new Array(100);
      var y = new Array(100);
      x[0] = y[0] = 0;
      x[1] = 0.5;
      y[1] = 1;

      x[2] = y[2] = NaN;

      x[3] = 0.5;
      y[3] = 0;
      x[4] = y[4] = 1;

      gr.polyline(5, x, y);
    });
  </script>
</body>
</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants