Content-Length: 366876 | pFad | http://github.com/fnando/sparkline/commit/18b9c1d2569b88135c453821af47e455229ccde2

FA Fix x coords for any number of datapoints. Close #1. · fnando/sparkline@18b9c1d · GitHub
Skip to content

Commit 18b9c1d

Browse files
committed
Fix x coords for any number of datapoints. Close #1.
1 parent 0bdf25b commit 18b9c1d

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
exports['renders svg with array of numbers and default options 1'] = "<svg width=\"100\" height=\"30\" stroke-width=\"2\"><path d=\"M4 26 L 4 26 L 23.2 7.67 L 42.4 18.67 L 61.599999999999994 11.33 L 80.8 4\" fill=\"none\"></path><path d=\"M4 26 L 4 26 L 23.2 7.67 L 42.4 18.67 L 61.599999999999994 11.33 L 80.8 4 V 30 L 4 30 Z\" stroke=\"none\"></path></svg>"
1+
exports['renders svg with array of numbers and default options 1'] = "<svg width=\"100\" height=\"30\" stroke-width=\"2\"><path d=\"M4 26 L 4 26 L 28 7.67 L 52 18.67 L 76 11.33 L 100 4\" fill=\"none\"></path><path d=\"M4 26 L 4 26 L 28 7.67 L 52 18.67 L 76 11.33 L 100 4 V 30 L 4 30 Z\" stroke=\"none\"></path></svg>"
22

33
exports['renders svg for empty values array 1'] = "<svg width=\"100\" height=\"30\" stroke-width=\"2\"></svg>"
44

55
exports['renders svg for 1-item array 1'] = "<svg width=\"100\" height=\"30\" stroke-width=\"2\"></svg>"
66

7-
exports['renders interactive svg 1'] = "<svg width=\"100\" height=\"30\" stroke-width=\"2\"><path d=\"M4 26 L 4 26 L 36 15 L 68 4\" fill=\"none\"></path><path d=\"M4 26 L 4 26 L 36 15 L 68 4 V 30 L 4 30 Z\" stroke=\"none\"></path><line class=\"sparkline--cursor\" x1=\"-1000\" x2=\"-1000\" y1=\"0\" y2=\"30\" stroke-width=\"2\"></line><circle class=\"sparkline--spot\" cx=\"-1000\" cy=\"-1000\" r=\"2\"></circle></svg>"
7+
exports['renders interactive svg 1'] = "<svg width=\"100\" height=\"30\" stroke-width=\"2\"><path d=\"M4 26 L 4 26 L 52 15 L 100 4\" fill=\"none\"></path><path d=\"M4 26 L 4 26 L 52 15 L 100 4 V 30 L 4 30 Z\" stroke=\"none\"></path><line class=\"sparkline--cursor\" x1=\"-1000\" x2=\"-1000\" y1=\"0\" y2=\"30\" stroke-width=\"2\"></line><circle class=\"sparkline--spot\" cx=\"-1000\" cy=\"-1000\" r=\"2\"></circle></svg>"
88

9-
exports['updates interactive svg when mouse moves 1'] = "<svg width=\"100\" height=\"30\" stroke-width=\"2\"><path d=\"M4 26 L 4 26 L 36 15 L 68 4\" fill=\"none\"></path><path d=\"M4 26 L 4 26 L 36 15 L 68 4 V 30 L 4 30 Z\" stroke=\"none\"></path><line class=\"sparkline--cursor\" x1=\"68\" x2=\"68\" y1=\"0\" y2=\"30\" stroke-width=\"2\"></line><circle class=\"sparkline--spot\" cx=\"68\" cy=\"4\" r=\"2\"></circle></svg>"
9+
exports['updates interactive svg when mouse moves 1'] = "<svg width=\"100\" height=\"30\" stroke-width=\"2\"><path d=\"M4 26 L 4 26 L 52 15 L 100 4\" fill=\"none\"></path><path d=\"M4 26 L 4 26 L 52 15 L 100 4 V 30 L 4 30 Z\" stroke=\"none\"></path><line class=\"sparkline--cursor\" x1=\"100\" x2=\"100\" y1=\"0\" y2=\"30\" stroke-width=\"2\"></line><circle class=\"sparkline--spot\" cx=\"100\" cy=\"4\" r=\"2\"></circle></svg>"
1010

11-
exports['renders interactive svg based on the nearest edge 1'] = "<svg width=\"100\" height=\"30\" stroke-width=\"2\"><path d=\"M4 15 L 4 15 L 52 4\" fill=\"none\"></path><path d=\"M4 15 L 4 15 L 52 4 V 30 L 4 30 Z\" stroke=\"none\"></path><line class=\"sparkline--cursor\" x1=\"52\" x2=\"52\" y1=\"0\" y2=\"30\" stroke-width=\"2\"></line><circle class=\"sparkline--spot\" cx=\"52\" cy=\"4\" r=\"2\"></circle></svg>"
11+
exports['renders interactive svg based on the nearest edge 1'] = "<svg width=\"100\" height=\"30\" stroke-width=\"2\"><path d=\"M4 15 L 4 15 L 100 4\" fill=\"none\"></path><path d=\"M4 15 L 4 15 L 100 4 V 30 L 4 30 Z\" stroke=\"none\"></path><line class=\"sparkline--cursor\" x1=\"4\" x2=\"4\" y1=\"0\" y2=\"30\" stroke-width=\"2\"></line><circle class=\"sparkline--spot\" cx=\"4\" cy=\"15\" r=\"2\"></circle></svg>"
1212

13-
exports['renders interactive svg based on the nearest edge 2'] = "<svg width=\"100\" height=\"30\" stroke-width=\"2\"><path d=\"M4 15 L 4 15 L 52 4\" fill=\"none\"></path><path d=\"M4 15 L 4 15 L 52 4 V 30 L 4 30 Z\" stroke=\"none\"></path><line class=\"sparkline--cursor\" x1=\"52\" x2=\"52\" y1=\"0\" y2=\"30\" stroke-width=\"2\"></line><circle class=\"sparkline--spot\" cx=\"52\" cy=\"4\" r=\"2\"></circle></svg>"
13+
exports['renders interactive svg based on the nearest edge 2'] = "<svg width=\"100\" height=\"30\" stroke-width=\"2\"><path d=\"M4 15 L 4 15 L 100 4\" fill=\"none\"></path><path d=\"M4 15 L 4 15 L 100 4 V 30 L 4 30 Z\" stroke=\"none\"></path><line class=\"sparkline--cursor\" x1=\"100\" x2=\"100\" y1=\"0\" y2=\"30\" stroke-width=\"2\"></line><circle class=\"sparkline--spot\" cx=\"100\" cy=\"4\" r=\"2\"></circle></svg>"
1414

15-
exports['renders svg with custom cursor 1'] = "<svg width=\"100\" height=\"30\" stroke-width=\"2\"><path d=\"M4 15 L 4 15 L 52 4\" fill=\"none\"></path><path d=\"M4 15 L 4 15 L 52 4 V 30 L 4 30 Z\" stroke=\"none\"></path><line class=\"sparkline--cursor\" x1=\"52\" x2=\"52\" y1=\"0\" y2=\"30\" stroke-width=\"3\"></line><circle class=\"sparkline--spot\" cx=\"52\" cy=\"4\" r=\"2\"></circle></svg>"
15+
exports['renders svg with custom cursor 1'] = "<svg width=\"100\" height=\"30\" stroke-width=\"2\"><path d=\"M4 15 L 4 15 L 100 4\" fill=\"none\"></path><path d=\"M4 15 L 4 15 L 100 4 V 30 L 4 30 Z\" stroke=\"none\"></path><line class=\"sparkline--cursor\" x1=\"4\" x2=\"4\" y1=\"0\" y2=\"30\" stroke-width=\"3\"></line><circle class=\"sparkline--spot\" cx=\"4\" cy=\"15\" r=\"2\"></circle></svg>"
1616

17-
exports['renders svg with custom spot 1'] = "<svg width=\"100\" height=\"30\" stroke-width=\"2\"><path d=\"M6 15 L 6 15 L 53 5\" fill=\"none\"></path><path d=\"M6 15 L 6 15 L 53 5 V 30 L 6 30 Z\" stroke=\"none\"></path><line class=\"sparkline--cursor\" x1=\"53\" x2=\"53\" y1=\"0\" y2=\"30\" stroke-width=\"2\"></line><circle class=\"sparkline--spot\" cx=\"53\" cy=\"5\" r=\"3\"></circle></svg>"
17+
exports['renders svg with custom spot 1'] = "<svg width=\"100\" height=\"30\" stroke-width=\"2\"><path d=\"M6 15 L 6 15 L 100 5\" fill=\"none\"></path><path d=\"M6 15 L 6 15 L 100 5 V 30 L 6 30 Z\" stroke=\"none\"></path><line class=\"sparkline--cursor\" x1=\"6\" x2=\"6\" y1=\"0\" y2=\"30\" stroke-width=\"2\"></line><circle class=\"sparkline--spot\" cx=\"6\" cy=\"15\" r=\"3\"></circle></svg>"
1818

src/sparkline.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,17 @@ export function sparkline(svg, entries, options) {
8080

8181
// The maximum value. This is used to calculate the Y coord of
8282
// each sparkline datapoint.
83-
const max = Math.max.apply(Math, values);
83+
const max = Math.max(...values);
8484

8585
// Some arbitrary value to remove the cursor and spot out of
8686
// the viewing canvas.
8787
const offscreen = -1000;
8888

89-
// Cache the values size.
90-
const entriesCount = values.length;
91-
9289
// Cache the last item index.
93-
const lastItemIndex = entriesCount - 1;
90+
const lastItemIndex = values.length - 1;
9491

9592
// Calculate the X coord base step.
96-
const offset = width / entriesCount;
93+
const offset = width / lastItemIndex;
9794

9895
// Hold all datapoints, which is whatever we got as the entry plus
9996
// x/y coords and the index.

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/fnando/sparkline/commit/18b9c1d2569b88135c453821af47e455229ccde2

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy