-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
found bugs w/ moving many plot elements
- Loading branch information
1 parent
ac78f7c
commit 298dde6
Showing
4 changed files
with
266 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
|
||
<!-- d3--> | ||
<script src="https://d3js.org/d3.v5.js" charset="utf-8"></script> | ||
|
||
<!-- Load data from json--> | ||
<script src="../mwes/data/path_data_plotmwe.json" charset="utf-8"></script> | ||
|
||
<!-- Math symbols PUT AS LAST IMPORT!--> | ||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_SVG"> | ||
</script> | ||
|
||
</head> | ||
|
||
<style> | ||
</style> | ||
|
||
<body> | ||
<script type="module"> | ||
|
||
import {Canvas} from '../../src/functions/Canvas.js' | ||
import {NQBGColors,NQColors,NQTextColors,NQFonts} from '../../src/variables/NQ_colors_and_fonts.js' | ||
import {Svg} from '../src/classes/Svg.js' | ||
import {Plot} from '../src/classes/Plot.js' | ||
import {AddMathJax} from '../../src/functions/AddMathJax.js' | ||
|
||
if (document.URL.includes('template_hh')){ | ||
window.currentTime = 0 | ||
performance.now = () => currentTime | ||
} | ||
|
||
let timing = 0 | ||
|
||
/********************************* | ||
Auxiliaries | ||
*********************************/ | ||
function pseudorandom(seed) { | ||
// https://stackoverflow.com/a/19303725/7037299 | ||
//let seed = 1 | ||
let x = Math.sin(seed++) * 10000 | ||
return x - Math.floor(x) | ||
} | ||
function getRandomIntInclusive(dd, seed) { | ||
let min = Math.ceil(dd[0]) | ||
let max = Math.floor(dd[1]) | ||
return Math.floor(pseudorandom(seed) * (max - min + 1)) + min //The maximum is inclusive and the minimum is inclusive | ||
} | ||
function CreateScatterData(d){ | ||
let scatterData = [] | ||
for (let i=1;i<=10;i++) { | ||
scatterData.push({"x": getRandomIntInclusive(d.x, i), "y": getRandomIntInclusive(d.y, i), "color": NQColors.orange, "r": 10}) | ||
} | ||
return scatterData | ||
} | ||
|
||
/********************************* | ||
Define objects | ||
*********************************/ | ||
// Backgorund svg | ||
const svg = Canvas({}) | ||
|
||
let svg1params = { | ||
"id" : "svg1" | ||
,"pos" : [[150, 100]] | ||
,"dim" : [2300, 1090] | ||
,"strokeColor" : "red" | ||
,"strokeWidth" : 3 | ||
} | ||
let svg1 = new Svg(svg1params) | ||
svg1.Draw({delay:0, duration:0}) | ||
|
||
// line plot | ||
let params1 = { | ||
"pos" : [[0,0]] | ||
,"xRange" : [0,1400] | ||
,"yRange" : [0,770] | ||
,"yDomain" : [0,10] | ||
,"xDomain" : [0,9] | ||
,"id" : "plot1" | ||
,"yLabel" : "$\\alpha + \\text{Time}$" | ||
,"yLabelSize" : 30 | ||
,"xLabel" : "dd" | ||
,"svgid" :"svg1" | ||
} | ||
let plot1 = new Plot(params1) | ||
let lineDataParams1 = { | ||
"data" : lineDataObject["y1"] | ||
,"id" : "linedata1" | ||
,"strokeWidth" : 3 | ||
,"strokeColor" : NQColors.orange | ||
,"drawEase" : d3.easeCubic | ||
} | ||
let lineDataParams1_copy = { | ||
"data" : lineDataObject["y1"] | ||
,"id" : "linedata1_copy" | ||
,"strokeWidth" : 3 | ||
,"strokeColor" : NQColors.yellow | ||
,"drawEase" : d3.easeCubic | ||
} | ||
|
||
/********************************* | ||
Animate | ||
*********************************/ | ||
// Plot axes to svg1, plot line to axes | ||
timing = timing + 1000 | ||
plot1.Draw({delay:timing, duration:300}) | ||
plot1.DrawLine({delay:timing+300, duration:500, lineParams:lineDataParams1}) | ||
|
||
// Zoom out svg1; etend x axis and adjust line accordingly | ||
timing = timing + 1000 | ||
svg1.Update({ | ||
delay:timing, | ||
duration:1000, | ||
params:{ | ||
newScale : 0.7 | ||
} | ||
}) | ||
let params1_a = {'xDomain': [0, 16], 'xRange': [0, 2300]} | ||
plot1.MoveLine({delay:timing, duration:1000, lineParams:lineDataParams1, plotParams:params1_a}) | ||
|
||
// Adjusting x-axis now produces weird truncating effect for the line! | ||
// Luckily works other way arund (if domain extended, not contracted) | ||
timing = timing + 2000 | ||
let params1_b = {'xDomain': [0, 9]} | ||
plot1.MoveLine({delay:timing, duration:5000, lineParams:lineDataParams1, plotParams:params1_b}) | ||
|
||
// Seems not to be xScale issue, as new line drawn on the axes comes out as it should | ||
timing = timing + 6000 | ||
plot1.DrawLine({delay:timing, duration:10000, lineParams:lineDataParams1_copy}) | ||
|
||
// This needs to be added in conjunction with the import above! | ||
AddMathJax(svg) | ||
|
||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.