Notebook - Welcome to Notebook

Contact/Report Bugs
You can contact me at: bkenwright@xbdev.net












Circle path grouping but also has hover over information Nobel prize data shows which catagories over the years have won script type text javascript src https d3js org d3 v7 min js script style circle fill indianred opacity 0 3 stroke white text font family Helvetica Neue Helvetica sans serif fill black font size 13px text anchor middle font weight 900 style svg viewBox 10 10 400 400 g g svg script collection of data sets ref https github com jdorfman awesome json datasets async let pro await fetch https api nobelprize org v1 prize json let json await pro json console log json prizes 0 number of unique categories for let key in json prizes 0 console log key put the data into a format for visualizing the categories let data name laureates children for let i 0 i json prizes length i if data children filter e e name json prizes i category length 0 data children push name json prizes i category laureates children data children filter e e name json prizes i category 0 children push name laureates JSON stringify json prizes i laureates value 1 console log data var colorScale d3 scaleLinear domain 1 3 5 6 range 2c7bb6 ffffbf d7191c interpolate d3 interpolateHcl var packLayout d3 pack size 300 300 var rootNode d3 hierarchy data rootNode sum function d return d value packLayout rootNode var nodes d3 select svg g selectAll g data rootNode descendants join g attr transform function d return translate d x d y nodes append circle attr r d return d r attr fill d i return colorScale i nodes filter function d return d depth 1 append text attr class test style class test attr dx 0 attr opacity 1 text function d i return d data name nodes filter function d return d depth 2 append svg title text function d i return d data laureates Helper function Move region svg to front should be defined before called d3 selection prototype moveToFront function return this each function this parentNode appendChild this d3 selection prototype moveToFront2 function return this each function this parentNode appendChild this var parent this parentNode parent parentNode appendChild parent var currNode d3 select this Fix to move title hover over text to the very front d3 selection prototype moveToFront3 function return this each function d3 select svg node appendChild this nodes selectAll test moveToFront append text attr dx 10 text function d return ddd d3 selectAll text filter function d return d depth 1 moveToFront2 d3 selectAll title filter function d return d depth 2 moveToFront3 var region2 nodes filter function d return d depth 2 append title text dd add text node label and move to front var region nodes filter function d return d depth 1 moveToFront append text attr dx 0 text function d return d data name add title node label and move to front nodes filter function d return d depth 2 moveToFront2 append title text function d return d data laureates script Donut with Arc Labels script type text javascript src https d3js org d3 v7 min js script Nice fancy text for the names link href https fonts googleapis com css family Pacifico rel stylesheet type text css style body font family Pacifico sans serif fill 333333 font size 16px text align center style svg viewBox 40 40 500 400 g g svg script async let pro await fetch https api nobelprize org v1 prize json let json await pro json get the catagory data from the prize json and put it into an array var donutData for let i 0 i json prizes length i if donutData filter e e name json prizes i category length 0 donutData push name json prizes i category value 0 donutData filter e e name json prizes i category 0 value 1 setup var screenWidth window innerWidth var margin left 20 top 20 right 20 bottom 20 var width Math min screenWidth 500 margin left margin right var height Math min screenWidth 500 margin top margin bottom var svg d3 select svg attr width width margin left margin right attr height height margin top margin bottom append g attr class wrapper attr transform translate width 2 margin left height 2 margin top data and scaling note D3 v4 it is no longer named d3 scale linear Use d3 scaleLinear instead Create a color scale var colorScale d3 scaleLinear domain 1 3 5 6 range 2c7bb6 ffffbf d7191c interpolate d3 interpolateHcl Create an arc function var arc d3 arc innerRadius width 0 75 2 outerRadius width 0 75 2 30 Turn the pie chart 90 degrees counter clockwise so it starts at the left var pie d3 pie startAngle 90 Math PI 180 endAngle 90 Math PI 180 2 Math PI value function d return d value padAngle 01 sort null Create the donut slices and also the invisible arcs for the text svg selectAll donutArcs data pie donutData enter append path attr class donutArcs attr d arc style fill function d i if i 7 return CCCCCC Other else return colorScale i each function d i Search pattern for everything between the start and the first capital L var firstArcSection L Grab everything up to the first Line statement var newArc firstArcSection exec d3 select this attr d 1 Replace all the comma s so that IE can handle it newArc newArc replace g If the end angle lies beyond a quarter of a circle 90 degrees or pi 2 flip the end and start position if d endAngle 90 Math PI 180 var startLoc M A Everything between the first capital M and first capital A middleLoc A 0 0 1 Everything between the first capital A and 0 0 1 endLoc 0 0 1 Everything between the first 0 0 1 and the end of the string denoted by Flip the direction of the arc by switching the start en end point and sweep flag of those elements that are below the horizontal line var newStart endLoc exec newArc 1 var newEnd startLoc exec newArc 1 var middleSec middleLoc exec newArc 1 Build up the new arc notation set the sweep flag to 0 newArc M newStart A middleSec 0 0 0 newEnd if Create a new invisible arc that the text can flow along svg append path attr class hiddenDonutArcs attr id donutArc i attr d newArc style fill none Append the label names on the outside svg selectAll donutText data pie donutData enter append text attr class donutText Move the labels below the arcs for those slices with an end angle greater than 90 degrees attr dy function d i return d endAngle 90 Math PI 180 18 11 append textPath attr startOffset 50 style text anchor middle attr xlink href function d i return donutArc i text function d return d data name console log finished script

svg viewBox 40 40 500 400 g g svg script async let pro await fetch https api nobelprize org v1 prize json let json await pro json get the catagory data from the prize json and put it into an array var donutData for let i 0 i json prizes length i if donutData filter e e name json prizes i category length 0 donutData push name json prizes i category value 0 donutData filter e e name json prizes i category 0 value 1 setup var screenWidth window innerWidth var margin left 20 top 20 right 20 bottom 20 var width Math min screenWidth 500 margin left margin right var height Math min screenWidth 500 margin top margin bottom var svg d3 select svg attr width width margin left margin right attr height height margin top margin bottom append g attr class wrapper attr transform translate width 2 margin left height 2 margin top data and scaling note D3 v4 it is no longer named d3 scale linear Use d3 scaleLinear instead Create a color scale var colorScale d3 scaleLinear domain 1 3 5 6 range 2c7bb6 ffffbf d7191c interpolate d3 interpolateHcl Create an arc function var arc d3 arc innerRadius width 0 75 2 outerRadius width 0 75 2 30 Turn the pie chart 90 degrees counter clockwise so it starts at the left var pie d3 pie startAngle 90 Math PI 180 endAngle 90 Math PI 180 2 Math PI value function d return d value padAngle 01 sort null Create the donut slices and also the invisible arcs for the text svg selectAll donutArcs data pie donutData enter append path attr class donutArcs attr d arc style fill function d i if i 7 return CCCCCC Other else return colorScale i each function d i Search pattern for everything between the start and the first capital L var firstArcSection L Grab everything up to the first Line statement var newArc firstArcSection exec d3 select this attr d 1 Replace all the comma s so that IE can handle it newArc newArc replace g If the end angle lies beyond a quarter of a circle 90 degrees or pi 2 flip the end and start position if d endAngle 90 Math PI 180 var startLoc M A Everything between the first capital M and first capital A middleLoc A 0 0 1 Everything between the first capital A and 0 0 1 endLoc 0 0 1 Everything between the first 0 0 1 and the end of the string denoted by Flip the direction of the arc by switching the start en end point and sweep flag of those elements that are below the horizontal line var newStart endLoc exec newArc 1 var newEnd startLoc exec newArc 1 var middleSec middleLoc exec newArc 1 Build up the new arc notation set the sweep flag to 0 newArc M newStart A middleSec 0 0 0 newEnd if Create a new invisible arc that the text can flow along svg append path attr class hiddenDonutArcs attr id donutArc i attr d newArc style fill none Append the label names on the outside svg selectAll donutText data pie donutData enter append text attr class donutText Move the labels below the arcs for those slices with an end angle greater than 90 degrees attr dy function d i return d endAngle 90 Math PI 180 18 11 append textPath attr startOffset 50 style text anchor middle attr xlink href function d i return donutArc i text function d return d data name console log finished script

3dplot
a4print
about
acejs
acejs2
acejs3
aessecurity
angularjs
animbackgroundimage
aseformat
assert
asteroidsjs
backgrounds01
backgrounds02
backgrounds03
barnsleyfern
base26
base64
bib
binary
bodypix
bouncy
box2dweb
breakoutjs
browserversion
buslanes
busybutton
bvhreader
calendar
canvas
canvas2
canvas3
canvasmandelbrot
canvasmandelbrot2
canvasnumbers
canvaszoom
capsule
changingimages
chatgptusingopenai
chatgptusingopenai2
chatgptusingopenai3
checkboxtoggle
chinesetiles
classes
classfeatures
clipboardbutton
clonenode
codedropdown
codemirror
codemirror2
collada
colorpick
columnresizer
contextmenu
convnet
cookiebanner
countdown
countdown2
countdown3
crop
css3dbarchart
css3dbarchart2
css3dbook
css3dscene
csscube
csscube2
csscube3
csscubevideos
cssfilelist
csshas
csspulse
cssresizeaspect
cssspin
csszooming
csvtoarray
customcheckbox
d3datamap
d3js
d3js10
d3js11
d3js2
d3js3
d3js4
d3js5
d3js6
d3js7
d3js8
d3js9
d3jsanimatedgrid
d3jsarctransition
d3jsarctransition2
d3jsaxis
d3jsaxischanging
d3jsbars
d3jsbrushing
d3jsbuslanes
d3jsbuslanes2
d3jscalendar
d3jscheat
d3jsclock
d3jscloudmap
d3jscogs
d3jscolors
d3jscovid
d3jscovid2
d3jscovid3
d3jsdashboard
d3jsdashboard2
d3jsdashboard3
d3jsdatakeyfunction
d3jsdensity
d3jsdragresizing
d3jsdragresizing2
d3jseach
d3jsease
d3jsevents
d3jsflower
d3jsforcegroups
d3jsforces
d3jsforces2
d3jsfractaltree
d3jsgeo
d3jsgroupbars
d3jsgroups
d3jsheatmap
d3jshex
d3jshierarchies
d3jshierarchies2
d3jshistogram
d3jshistogram2
d3jshistogram3
d3jshistogram4
d3jsinterpolate
d3jsjoin
d3jskmean
d3jskmean2
d3jsline
d3jsline2
d3jsline3
d3jsline4
d3jslinetransition
d3jslinetransition0
d3jslinetransition2
d3jsmaplocations
d3jsmaps
d3jsmaps2
d3jsmaps3
d3jsmisc
d3jsmisc2
d3jsmodule
d3jsmodulecolor
d3jsmultistyles
d3jsnobel
d3jsoverlappinggraphs
d3jspanel
d3jspie
d3jspieinterpolate
d3jssankey
d3jssankey2
d3jsscatter
d3jsshapes
d3jsslider
d3jsspending
d3jsspending2
d3jsspiralplot
d3jsspirograph
d3jssquare
d3jsstack
d3jsstackedbar
d3jsstackedbar2
d3jssunburst
d3jssunmoon
d3jssvglines
d3jssymbols
d3jstimelines
d3jsuk
d3jsvoronoi
d3scatterplot
d3timeline
d3timeline2
datalist
datamuse
date
dblclickhighlight
deviceorientation
dictionaryapi
dockermenu
doodlepad
downloadgif
dragdroplistitems
dragrotateresizediv
dragrotateresizediv2
dragrotateresizediv3
dragrotateresizediv4
dragrotateresizefontsize
dragselectbrush
drawlinesdiv
dropdown
dualquaternionimages
dynamicgrid
easefunctions
easeinterpolate3dplots
echart
echart2
echart3
encapsulation
epubviewer
errorstack
excalidraw
excalidraw2
excalidraw3
excalidraw5
expandable
faker
fetchplus
fileupload
fixedtopbar
fonts
fonts2
footerbar
fractalmaze
fractalmaze2
fractalnoiseimage
fractals
fractals2
fractaltree
freesvg
fresnel
froggerjs
gantt
gifgiphyapi
gifhex
gltffromscratch
gradients
griditems
griditems2
griditems3
griditems4
gridworms
heat
hexview
hexview2
highlight
icons
icons2
iframes
ik
imagetracertosvg
imgur
inputfile
invadersjs
ipynb
ipynb2
ipynb3
ipynb4
isbn13
isbn2
jpghex
jquery
jquery2
jqueryui
jqueryui2
jsdraganddrop
jslint
jsobfuscate
jsraytracer
jstree
jstree2
jszip
jszipimages
jszipread
keyframes
l2dwidget
lda
leftmenu
less
less2
lineargradientimage
linenumbers
loadimagefromfile
makepdf
maps
markdown
markdown2
markdownalerts
markdownalerts2
markdownbookmarks
markovimage
markovpixelblocks
mathjax
matrices
matsandvects
mazegamejs
md2tex
metrotiles
metrowindows
milestones
misc
misc2
modules
myipdetails
neataptic
networkstructures
networkstructures2
number
obj
objtojson
openaiimages
opencv
opencv2
opencv3
opencv4
opencv5
outline
p2
p5fractalleaf
p5fractalshape
p5js
p5js2
p5js3
p5jsanimatedcover
p5mengercube
p5snowflakes
palindrome
panel
parallax
paste
paste2
pasteimgfromurl
pdfjs
pdfjs2
pdfkit
pdfkit2
pdfkit3
pdfkit4
pdfkit5
pdfkit6
pdfmake
pdfmake2
pdfmake3
pdfmake4
pdfmake5
pdfmake6
perlin
perlin2
perlin3
perspective
pexels
playground
plotly
plotlynoise
plotlyranddist
plyloader
plyloader2
pngtxtencoder
pongjs
pptxgenjs
prettycode
prism
prn
problems
progress
pseudorandom
px2svg
python
quotes
racergame
random
randomprofilepatterns
randomstring
rating
rayambient
raymonte
raymonteprogressive
raymonteprogressive2
raymontewarmstart
reexpcross
reexpcross2
regex
regexbib
regexpfixbib
regexpmultiline
repeatwordsregexp
resizabletable
resizabletable2
revealjs
revealjs2
revealjsmulti
ritalanguage
ritalanguage2
ritalanguage3
rotateimg
rough
rsapublicprivatekeys
rss
rss2
sankey
scrappingsvg
scrolltext
scrolltext2
scrollwidth
sdfboxinboxtwist
sdfhollowbox
setintervalexception
shareurl
shuffle
sidecomment
similarity
simplehighlighter
simpleplatformgamejs
sinecanvas
sliderpopout
slides
smileys
snowfall
snowman
sound
soundsignal
sphererayintersection
springs
sqljs
steganography
stereogram
stringmatching
svg
svgchaos
svgdragresize
svgdragresize2
svgdragresize3
svgdragrotate
svgdrawing
svglines
svglines2
svglines3
svglines4
svglines5
svglinesmandelbrot
svgpathsdragrotate
svgpathsdragrotateresize
svgpie
svgpie2
svgpie3
svgpiepath
svgpiepath2
svgrandomfaces
symbols
synaptic
synaptic2
synonyms
tablerotatecells
tablerotatecells2
tablerotatecells3
tablerotatecells3b
tablerotatecells4
tables
tablezebra
tabularjs
tabularjs2
tabulatordownload
tagcanvas
tensorflowgan
tensorflowjs
tensorflowjsbasic
tensorflowjscnn
tensorflowjssinewave
tensorflowjssound
tensorflowmobilenet
tetrahedronfractal
tetrahedronfractalfolding
tetris
textarea
textareaauto
textareadiv
textareadiv2
textmaskimage
theirorthere
thesaurus
threejs
threejs2
threejs3
threejs4
threejsgltf
threejstokyo
tiles
toaster
tooltip
transition
transitionexpandabledropdown
treeview
treeview2
tricks
tshirt
tshirt2
tshirt3
turningpages
unsplash
urlblob
urlblob2
userdefinepoints
vector
videos
videos2
visualsort
vue
w2ui
w2uientertextdialog
webcam
webgl
webgl2
webgl3
webgl4
webgl5
webglbasic1
webglbasic2
webglcube
webglfov
webglfrustum
webgljson
webglleaves
webgllighting
webglorthographic
webglpoints1
webglpoints2
webglpoints3
webglsquare
webgltexture1
webgltexture2
webgltexture3
webgltransforms
webgltriangle
webgpu
webgpu10
webgpu11
webgpu12
webgpu13
webgpu14
webgpu15
webgpu16
webgpu17
webgpu2
webgpu3
webgpu4
webgpu5
webgpu6
webgpu7
webgpu8
webgpu9
webgpubars
webgpubuffers
webgpubuffers2
webgpucellnoise
webgpuclouds
webgpuclydescope
webgpucompute
webgpucubemap
webgpucubemap2
webgpudeferred
webgpudepth
webgpudof
webgpudrops
webgpuetha
webgpufire
webgpufractalcubes
webgpuglassrain
webgpugltf
webgpugltf2
webgpugrass
webgpugrid
webgpukernel
webgpukleinian
webgpulabupdates
webgpulighting
webgpumandelbrot
webgpumeta3d
webgpumetaballs
webgpumouse
webgpunoise
webgpunormalmapping
webgpuobj
webgpuparallax
webgpuparallax2
webgpuparallax3
webgpuparallaxshadow
webgpuparallaxshadow2
webgpupixel
webgpuquad
webgpuray1
webgpuraytracing
webgpuraytracing2
webgpushadowmaps
webgpushadowmaps2
webgpusierpinski2d
webgpusierpinski3d
webgpusinusoid
webgpussao
webgpustadiumobj
webgpuswirl
webgputestpipe3
webgputoon
webgputopology
webgputt
webgpuvolcloud
webgpuwater
webgpuwireframe
webgpuwireframe2
webpcanvas
webworkers
webxr
webxr2
wiggly
wikipedia