Skip to content

Instantly share code, notes, and snippets.

View j-medland's full-sized avatar

John Medland j-medland

  • Control Software Solutions
  • Manchester, UK
  • X @j_medland
View GitHub Profile
@j-medland
j-medland / Server Side SVG Rendering with D3.js 4.x and jsdom.md
Last active August 10, 2023 02:39
Server Side SVG Rendering with D3.js 4.x and jsdom

Server Side SVG Rendering with D3.js 4.x and jsdom

This gist is mostly based on Tom Pearson's Block but with a slightly clearer use of d3 with the window object provided by jsdom's 'done' function. This example works as expected but perhaps there are some subtleties that I have missed in Tom's approach.

Other examples of using D3 and jsdom can be found in the tests straight from the D3 github

To use this example, open a command-prompt/terminal and

cd /directory/containing/package.json
npm install
function pricePerArea (area) {
var areas = [0.15, 0.5, 0.75, 1, 5, 10, 15, 20, 35, 50, 75, 100, 150, 200, 350, 500, 750, 1000, 1250, 1500, 2000, 2500, 3000]
var prices = [8, 8, 5, 4.5, 4, 3.8, 2.8, 2.6, 2.4, 2.2, 2, 1.6, 1.4, 1.2, 0.9, 0.75, 0.65, 0.5, 0.4, 0.35, 0.25, 0.15, 0.12]
// catch edge cases
if (area <= areas[0]) {
return prices[0]
}
if (area >= areas.slice(-1)[0]) {
return prices.slice(-1)[0]
ּ_בּ
בּ_בּ
טּ_טּ
כּ‗כּ
לּ_לּ
מּ_מּ
סּ_סּ
תּ_תּ
٩(×̯×)۶
٩(̾●̮̮̃̾•̃̾)۶
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@j-medland
j-medland / index.html
Last active November 30, 2017 13:44
Fancy Clip Path
<!DOCTYPE html>
<meta charset="utf-8">
<svg width="960" height="500"></svg>
<script src="//d3js.org/d3.v4.min.js"></script>
<script>
var lineAPoint = [[10,50], [300,150], [950,50]]
var lineBPoint = [[10,150], [300,20], [950,50]]
var line = d3.line()
@j-medland
j-medland / .block
Last active December 4, 2017 08:32 — forked from mbostock/.block
Bounded Force Layout
license: gpl-3.0
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@j-medland
j-medland / commands.txt
Last active September 17, 2021 18:03
surf browser on NIRT Linux
# shh as admin into the CRio and execute:
opkg update
opkg install pkgconfig gtk+-dev webkitgtk-dev
wget https://dl.suckless.org/surf/surf-2.0.tar.gz
tar -xvzf surf-2.0.tar.gz
cd surf-2.0
make clean install
# then on the CRio
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 3 columns, instead of 2. in line 1.
PROCESSOR,ARCHITECTURE,IGNORED
77B1,ARM-FlexRIO
77B2,ARM-FlexRIO
77AC,ARM-FlexRIO
762F,ARM-cRIO-myRIO
76D3,ARM-cRIO-myRIO
76F2,ARM-cRIO-roboRIO
7AAE,ARM-cRIO-roboRIO
7740,ARM-cRIO-4-slot
7741,ARM-cRIO-4-slot
This snippet allows for the rotation and translation vectors between two sets of three-dimensional points to be estimated.