Skip to content

Commit 5e5b50d

Browse files
committed
limit number of items in plot history
1 parent 460e71d commit 5e5b50d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/plots/pane.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import PaneItem from '../util/pane-item'
77
import { toView, Toolbar, Button, Icon, BackgroundMessage } from '../util/etch'
88

99
let defaultPane
10+
const MAX_SIZE = 50
1011

1112
export default class PlotPane extends PaneItem {
1213
static activate() {
@@ -119,6 +120,7 @@ export default class PlotPane extends PaneItem {
119120
if (view) {
120121
this.ids.push(this.counter += 1)
121122
this.items.push(view)
123+
this.prune()
122124
this.activateItem(this.items.length - 1)
123125
}
124126
etch.update(this, false)
@@ -137,6 +139,21 @@ export default class PlotPane extends PaneItem {
137139
}
138140
}
139141

142+
prune () {
143+
const numItems = this.items.length
144+
if (numItems <= MAX_SIZE) return
145+
146+
const startInd = numItems - MAX_SIZE
147+
this.items.forEach((item, ind) => {
148+
if (ind < startInd && item.teardown) {
149+
item.teardown()
150+
}
151+
})
152+
153+
this.ids = this.ids.slice(startInd, numItems)
154+
this.items = this.items.slice(startInd, numItems)
155+
}
156+
140157
clearAll () {
141158
this.items.forEach(item => item.teardown && item.teardown())
142159
this.ids = []

0 commit comments

Comments
 (0)