Skip to content

Commit 976b207

Browse files
committed
add options.cache flag
1 parent 9da0f6b commit 976b207

6 files changed

Lines changed: 40 additions & 9 deletions

File tree

dist/uPlot.cjs.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3282,6 +3282,8 @@ function uPlot(opts, data, then) {
32823282

32833283
opts = copy(opts);
32843284

3285+
const usePathCache = opts.cache ?? true;
3286+
32853287
const pxAlign = +ifNull(opts.pxAlign, 1);
32863288

32873289
const pxRound = pxRoundGen(pxAlign);
@@ -5233,14 +5235,19 @@ function uPlot(opts, data, then) {
52335235
viaAutoScaleX = false;
52345236

52355237
queuedCommit = false;
5238+
5239+
if (!usePathCache)
5240+
clearPathCache();
52365241
}
52375242

5238-
self.clearCache = () => {
5243+
function clearPathCache() {
52395244
series.forEach((s, i) => {
52405245
if (i > 0)
52415246
s._paths = null;
52425247
});
5243-
};
5248+
}
5249+
5250+
self.clearCache = clearPathCache;
52445251

52455252
self.redraw = (rebuildPaths, recalcAxes) => {
52465253
shouldConvergeSize = recalcAxes || false;

dist/uPlot.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@ declare namespace uPlot {
414414
hooks?: Hooks.Arrays;
415415

416416
plugins?: Plugin[];
417+
418+
// controls whether canvas path cache is auto-cleared after every draw call (see caveats of clearCache() above)
419+
cache?: boolean; // true
417420
}
418421

419422
export interface Focus {

dist/uPlot.esm.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3280,6 +3280,8 @@ function uPlot(opts, data, then) {
32803280

32813281
opts = copy(opts);
32823282

3283+
const usePathCache = opts.cache ?? true;
3284+
32833285
const pxAlign = +ifNull(opts.pxAlign, 1);
32843286

32853287
const pxRound = pxRoundGen(pxAlign);
@@ -5231,14 +5233,19 @@ function uPlot(opts, data, then) {
52315233
viaAutoScaleX = false;
52325234

52335235
queuedCommit = false;
5236+
5237+
if (!usePathCache)
5238+
clearPathCache();
52345239
}
52355240

5236-
self.clearCache = () => {
5241+
function clearPathCache() {
52375242
series.forEach((s, i) => {
52385243
if (i > 0)
52395244
s._paths = null;
52405245
});
5241-
};
5246+
}
5247+
5248+
self.clearCache = clearPathCache;
52425249

52435250
self.redraw = (rebuildPaths, recalcAxes) => {
52445251
shouldConvergeSize = recalcAxes || false;

dist/uPlot.iife.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3283,6 +3283,8 @@ var uPlot = (function () {
32833283

32843284
opts = copy(opts);
32853285

3286+
const usePathCache = opts.cache ?? true;
3287+
32863288
const pxAlign = +ifNull(opts.pxAlign, 1);
32873289

32883290
const pxRound = pxRoundGen(pxAlign);
@@ -5234,14 +5236,19 @@ var uPlot = (function () {
52345236
viaAutoScaleX = false;
52355237

52365238
queuedCommit = false;
5239+
5240+
if (!usePathCache)
5241+
clearPathCache();
52375242
}
52385243

5239-
self.clearCache = () => {
5244+
function clearPathCache() {
52405245
series.forEach((s, i) => {
52415246
if (i > 0)
52425247
s._paths = null;
52435248
});
5244-
};
5249+
}
5250+
5251+
self.clearCache = clearPathCache;
52455252

52465253
self.redraw = (rebuildPaths, recalcAxes) => {
52475254
shouldConvergeSize = recalcAxes || false;

dist/uPlot.iife.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uPlot.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ export default function uPlot(opts, data, then) {
355355

356356
opts = copy(opts);
357357

358+
const usePathCache = opts.cache ?? true;
359+
358360
const pxAlign = +ifNull(opts.pxAlign, 1);
359361

360362
const pxRound = pxRoundGen(pxAlign);
@@ -2310,14 +2312,19 @@ export default function uPlot(opts, data, then) {
23102312
viaAutoScaleX = false;
23112313

23122314
queuedCommit = false;
2315+
2316+
if (!usePathCache)
2317+
clearPathCache();
23132318
}
23142319

2315-
self.clearCache = () => {
2320+
function clearPathCache() {
23162321
series.forEach((s, i) => {
23172322
if (i > 0)
23182323
s._paths = null;
23192324
});
2320-
};
2325+
}
2326+
2327+
self.clearCache = clearPathCache;
23212328

23222329
self.redraw = (rebuildPaths, recalcAxes) => {
23232330
shouldConvergeSize = recalcAxes || false;

0 commit comments

Comments
 (0)