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

Output data into a separate script tag. #111

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ class ClinicFlame extends events.EventEmitter {
}

writeHtml (data, outputFilename, callback) {
// TODO: migrate most of this to clinic-common
const fakeDataPath = path.join(__dirname, 'visualizer', 'data.json')
const stylePath = path.join(__dirname, 'visualizer', 'style.css')
const scriptPath = path.join(__dirname, 'visualizer', 'main.js')
const logoPath = path.join(__dirname, 'visualizer/assets', 'flame-logo.svg')
Expand All @@ -114,18 +112,14 @@ class ClinicFlame extends events.EventEmitter {
const nearFormLogoFile = fs.createReadStream(nearFormLogoPath)
const clinicFaviconBase64 = fs.createReadStream(clinicFaviconPath)

const dataFile = JSON.stringify(data)
const flameVersion = require('./package.json').version

// build JS
const scriptFile = buildJs({
basedir: __dirname,
debug: this.debug,
fakeDataPath,
scriptPath,
beforeBundle: b => b.require({
source: JSON.stringify(data),
file: fakeDataPath
}),
env: {
PRESENTATION_MODE: process.env.PRESENTATION_MODE
}
Expand All @@ -142,6 +136,7 @@ class ClinicFlame extends events.EventEmitter {
favicon: clinicFaviconBase64,
title: 'Clinic Flame',
styles: styleFile,
data: dataFile,
script: scriptFile,
headerLogoUrl: 'https://clinicjs.org/flame/',
headerLogoTitle: 'Clinic Flame on Clinicjs.org',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"license": "GPL-3.0-or-later",
"dependencies": {
"0x": "^4.9.1",
"@nearform/clinic-common": "^3.0.0",
"@nearform/clinic-common": "^3.1.0",
"copy-to-clipboard": "^3.0.8",
"d3-array": "^2.0.2",
"d3-fg": "^6.13.1",
Expand Down
8 changes: 4 additions & 4 deletions visualizer/filters-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ class FiltersContent extends HtmlContent {
onChange: (datum, event) => {
this.ui.setUseMergedTree(event.target.checked)
// Toggle "Show optimization status" disabled class if Merged enabled/disabled
const showOptStatusId = this.sections.advanced[this.sections.advanced.length-1].id
const el = this.d3Advanced.select('#'+showOptStatusId)
const showOptStatusId = this.sections.advanced[this.sections.advanced.length - 1].id
const el = this.d3Advanced.select('#' + showOptStatusId)
el.classed('disabled', event.target.checked)
}
},
Expand Down Expand Up @@ -306,8 +306,8 @@ class FiltersContent extends HtmlContent {
ul.appendChild(this._createListItems(this.sections.advanced))

// "Show optimization status" disabled class by default
const showOptStatusId = this.sections.advanced[this.sections.advanced.length-1].id
const el = this.d3Advanced.select('#'+showOptStatusId)
const showOptStatusId = this.sections.advanced[this.sections.advanced.length - 1].id
const el = this.d3Advanced.select('#' + showOptStatusId)
el.classed('disabled', true)

// Preferences
Expand Down
3 changes: 2 additions & 1 deletion visualizer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const drawUi = () => {
ui.initializeElements()

// TODO: see if there's a way to load this asyncronously (in case of huge data) that works with puppeteer
const dataTree = require('./data.json')
const dataElement = document.querySelector('#clinic-data')
const dataTree = JSON.parse(dataElement.textContent)
ui.setData(dataTree)

// Select hottest frame, after frame visibility has been set in d3-fg
Expand Down
1 change: 0 additions & 1 deletion visualizer/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const d3 = require('./d3.js')
const path = require('path')
const events = require('events')
const d3 = require('./d3')
const htmlContentTypes = require('./html-content-types.js')
const debounce = require('lodash.debounce')
const DataTree = require('./data-tree.js')
Expand Down