|
6 | 6 | import Plotly from 'plotly.js' |
7 | 7 | import { store } from './Globals.js' |
8 | 8 | import * as d3 from 'd3' |
| 9 | +import { faWindowRestore } from '@fortawesome/free-solid-svg-icons' |
9 | 10 |
|
10 | 11 | const Color = require('color') |
11 | 12 |
|
@@ -217,64 +218,94 @@ export default { |
217 | 218 | } |
218 | 219 | }, |
219 | 220 | methods: { |
| 221 | + popupButton () { |
| 222 | + return { |
| 223 | + name: 'Open in new window', |
| 224 | + icon: { |
| 225 | + title: 'test', |
| 226 | + name: 'iconFS', |
| 227 | + width: 600, |
| 228 | + height: 600, |
| 229 | + path: faWindowRestore.icon[4] |
| 230 | + }, // Use any icon available |
| 231 | + click: (gd) => { |
| 232 | + // const plotData = JSON.parse(JSON.stringify(gd.data)) |
| 233 | + // const plotLayout = JSON.parse(JSON.stringify(gd.layout)) |
| 234 | + // const plotConfig = { showLink: false, displayModeBar: true } |
| 235 | +
|
| 236 | + // Open a new window |
| 237 | + const newWindow = window.open( |
| 238 | + '/#/plot', '_blank', |
| 239 | + 'toolbar=no,scrollbars=yes,resizable=yes,top=500,left=500,width=800,height=400,allow-scripts' |
| 240 | + ) |
| 241 | + setTimeout(() => { |
| 242 | + console.log(newWindow) |
| 243 | + console.log(newWindow.setPlotData) |
| 244 | + newWindow.setPlotData(gd.data) |
| 245 | + newWindow.setPlotOptions(gd.layout) |
| 246 | + newWindow.setCssColors(this.state.cssColors) |
| 247 | + newWindow.plot() |
| 248 | + }, 1000) |
| 249 | + console.log(newWindow) |
| 250 | + } |
| 251 | + } |
| 252 | + }, |
220 | 253 | csvButton () { |
221 | | - return [ |
222 | | - { |
223 | | - name: 'downloadCsv', |
224 | | - title: 'Download data as csv', |
225 | | - icon: Plotly.Icons.disk, |
226 | | - click: () => { |
227 | | - console.log(this.gd.data) |
228 | | - const data = this.gd.data |
229 | | - const header = ['timestamp(ms)'] |
230 | | - for (const series of data) { |
231 | | - header.push(series.name.split(' |')[0]) |
232 | | - } |
| 254 | + return { |
| 255 | + name: 'downloadCsv', |
| 256 | + title: 'Download data as csv', |
| 257 | + icon: Plotly.Icons.disk, |
| 258 | + click: () => { |
| 259 | + console.log(this.gd.data) |
| 260 | + const data = this.gd.data |
| 261 | + const header = ['timestamp(ms)'] |
| 262 | + for (const series of data) { |
| 263 | + header.push(series.name.split(' |')[0]) |
| 264 | + } |
233 | 265 |
|
234 | | - const indexes = [] |
| 266 | + const indexes = [] |
235 | 267 |
|
236 | | - const interval = 100 |
237 | | - let lasttime = Infinity |
238 | | - let finaltime = 0 |
| 268 | + const interval = 100 |
| 269 | + let lasttime = Infinity |
| 270 | + let finaltime = 0 |
239 | 271 |
|
240 | | - for (const series in data) { |
241 | | - indexes.push(0) |
242 | | - const x = data[series].x |
243 | | - lasttime = Math.min(lasttime, x[0]) |
244 | | - finaltime = Math.max(finaltime, x[x.length - 1]) |
245 | | - } |
246 | | - finaltime = Math.min(finaltime, this.state.timeRange[1]) |
247 | | - lasttime = Math.max(lasttime, this.state.timeRange[0]) |
| 272 | + for (const series in data) { |
| 273 | + indexes.push(0) |
| 274 | + const x = data[series].x |
| 275 | + lasttime = Math.min(lasttime, x[0]) |
| 276 | + finaltime = Math.max(finaltime, x[x.length - 1]) |
| 277 | + } |
| 278 | + finaltime = Math.min(finaltime, this.state.timeRange[1]) |
| 279 | + lasttime = Math.max(lasttime, this.state.timeRange[0]) |
248 | 280 |
|
249 | | - const csv = [header] |
250 | | - while (lasttime < finaltime - interval) { |
251 | | - const line = [lasttime] |
252 | | - for (const series in data) { |
253 | | - let index = indexes[series] |
254 | | - let x = data[series].x[index] |
255 | | - while (x < lasttime) { |
256 | | - indexes[series] += 1 |
257 | | - index = indexes[series] |
258 | | - x = data[series].x[index] |
259 | | - } |
260 | | - line.push(data[series].y[index]) |
| 281 | + const csv = [header] |
| 282 | + while (lasttime < finaltime - interval) { |
| 283 | + const line = [lasttime] |
| 284 | + for (const series in data) { |
| 285 | + let index = indexes[series] |
| 286 | + let x = data[series].x[index] |
| 287 | + while (x < lasttime) { |
| 288 | + indexes[series] += 1 |
| 289 | + index = indexes[series] |
| 290 | + x = data[series].x[index] |
261 | 291 | } |
262 | | - csv.push(line) |
263 | | - lasttime = lasttime + interval |
| 292 | + line.push(data[series].y[index]) |
264 | 293 | } |
265 | | - const csvContent = csv.map(e => e.join(',')).join('\n') |
266 | | - const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' }) |
267 | | - const link = document.createElement('a') |
268 | | - const url = URL.createObjectURL(blob) |
269 | | - link.setAttribute('href', url) |
270 | | - link.setAttribute('download', 'data.csv') |
271 | | - link.style.visibility = 'hidden' |
272 | | - document.body.appendChild(link) |
273 | | - link.click() |
274 | | - document.body.removeChild(link) |
| 294 | + csv.push(line) |
| 295 | + lasttime = lasttime + interval |
275 | 296 | } |
| 297 | + const csvContent = csv.map(e => e.join(',')).join('\n') |
| 298 | + const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' }) |
| 299 | + const link = document.createElement('a') |
| 300 | + const url = URL.createObjectURL(blob) |
| 301 | + link.setAttribute('href', url) |
| 302 | + link.setAttribute('download', 'data.csv') |
| 303 | + link.style.visibility = 'hidden' |
| 304 | + document.body.appendChild(link) |
| 305 | + link.click() |
| 306 | + document.body.removeChild(link) |
276 | 307 | } |
277 | | - ] |
| 308 | + } |
278 | 309 | }, |
279 | 310 | resize () { |
280 | 311 | Plotly.Plots.resize(this.gd) |
@@ -787,7 +818,7 @@ export default { |
787 | 818 | plotData, |
788 | 819 | plotOptions, |
789 | 820 | { |
790 | | - modeBarButtonsToAdd: this.csvButton(), |
| 821 | + modeBarButtonsToAdd: [this.csvButton(), this.popupButton()], |
791 | 822 | scrollZoom: true, |
792 | 823 | editable: true, |
793 | 824 | responsive: true |
|
0 commit comments