Public
Edited
Mar 23, 2024
Insert cell
Insert cell
viewof input = Inputs.range([0, 10000], {label: "Amount", step: 100, value: 100})
Insert cell
Insert cell
Insert cell
Insert cell
legend = Legend({color: chart.scales.color, title: keyz})
Insert cell
chart = {

const KEYS = keys
const KEYZ = keyz
const data6 = replaceValuesWithEnums
// Specify the chart’s dimensions.
const width = 928;
const height = KEYS.length * 120;
const marginTop = 20;
const marginRight = 10;
const marginBottom = 20;
const marginLeft = 10;

const sumWeight = data6.length

// Create an horizontal (*x*) scale for each key.
const x = new Map(Array.from(KEYS, key => [key, d3.scaleLinear(d3.extent(data6, d => d[key]), [marginLeft, width - marginRight])]));

// Create the vertical (*y*) scale.
const y = d3.scalePoint(KEYS, [marginTop, height - marginBottom]);

// Create the color scale.
const color = d3.scaleSequential(x.get(KEYZ).domain(), t => d3.interpolateBrBG(1 - t));

// Create the SVG container.
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.attr("width", width)
.attr("height", height)
.attr("style", "max-width: 100%; height: auto;");

// Append the lines.
const line = d3.line()
.defined(([, value]) => value != null)
.x(([key, value]) => x.get(key)(value))
.y(([key]) => y(key));

svg.append("g")
.attr("fill", "none")
.attr("stroke-width", 1.5)
// .attr("stroke-opacity", 0.0001)
.selectAll("path")
.data(data6.slice().sort((a, b) => d3.ascending(a[KEYZ], b[KEYZ])))
.join("path")
// .attr("stroke", d => color(d[keyz]))
.attr("stroke", d => "gray")
.attr("stroke-opacity", opacity)
.attr("d", d => line(d3.cross(KEYS, [d], (key, d) => [key, d[key]])))
.append("title")
.text(d => d.name);

// Append the axis for each key.
svg.append("g")
.selectAll("g")
.data(KEYS)
.join("g")
.attr("transform", d => `translate(0,${y(d)})`)
.each(function(d) { d3.select(this).call(d3.axisBottom(x.get(d))); })
.call(g => g.append("text")
.attr("x", marginLeft)
.attr("y", -6)
.attr("text-anchor", "start")
.attr("fill", "currentColor")
.text(d => d))
.call(g => g.selectAll("text")
.clone(true).lower()
.attr("fill", "none")
.attr("stroke-width", 5)
.attr("stroke-linejoin", "round")
.attr("stroke", "white"));

return Object.assign(svg.node(), {scales: {color}});
}
Insert cell
replaceValuesWithEnums = {
const arr = plusVector.slice(0,input)
let outArr = []
for(const record in arr){
const rec = arr[record]
console.log("INPUT RECORD: ", rec)
const dict = Object.entries(rec)
let newDict = []
for(const param in dict){
console.log("OLD PARAM: ", dict[param])
const key = dict[param][0]
const value = dict[param][1]
console.log("key : ", key)
console.log("value : ", value)
console.log("NEW PARAM: ", [key, enumsFromValues[key][value]])
const out = [key, enumsFromValues[key][value]]
newDict = [...newDict, out]
}
const newRecord = Object.fromEntries(newDict)
outArr = [...outArr, newRecord]
}
return outArr
}
Insert cell
alertsFeedKeys = {
const outObj = {}
const keySet = new Set()
for(const alertRecord in plusVector){
console.log("[alertsFeedKeys] alertRecord: ", plusVector[alertRecord])
const keys = Object.keys(plusVector[alertRecord])
for(const key in keys){
keySet.add(keys[key])
}
}
const s = [...keySet]
s.map(e => outObj[e] = new Set())
return outObj
}
Insert cell
plusVector = flat.map((e,i) => {
delete e.generatorURL
return {...e, vector:Object.values(e).join(" ")}
})
Insert cell
Insert cell
Insert cell
alerts (2).json
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
enumsFromValues = {
const dict = {}
Object.entries(alertsFeedKeys).map(([key,value]) => {
const d = {}
const valueOfDicts = [...value].map((e,i) => d[e] = i)
dict[key] = d
})
return dict
}
Insert cell
plusVector
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
afteFilter
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// data = FileAttachment("data.csv").csv({typed: true})
Insert cell
Insert cell
Select a data source…
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
import {legend as Legend} from "@d3/color-legend"
Insert cell
Insert cell
expApiTestsResults = FileAttachment("exporterTests3.json").json()
Insert cell
exportertests33 = FileAttachment("exporterTests3@3.json").json()
Insert cell
// expApiTestsResults = ()
Insert cell
out = expApiTestsResults.rawResponse.hits.hits
.map(e => ({time:e.sort,...e.fields}))
.map(e => {
const outObj = {}
Object.entries(e).map(e => outObj[e[0]] = e[1][0])
console.log("outObj", outObj)
return {...outObj,time1:new Date(outObj["@timestamp"]).getTime()}
})
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more