Public
Edited
Dec 21, 2023
2 forks
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.lineY(plotData, { x: "duration", y: "power", stroke: "darkblue" }),
],
x: { transform: (d) => d/60, domain: [0,40], label: "时间(分钟)", labelArrow: false },
y: { domain: [0,22], ticks: 10, tickSize: 5, inset: true, line: true, nice: true, label: "功率(W)", labelAnchor: "center", labelArrow: false },
width: 800,
height: 260,
marginLeft: 40,
marginRight: 50,
marginBottom: 30,
marginTop: 20,
})
Insert cell
plotData = {
var battery_t = rawBattery[0].batteryLevel
return rawHJWJ.filter((d) => d.power > 0).map((d1) => {
let duration = (d1.time - time0)/1000
let durationT = `${Math.floor(duration/60)}m${duration%60}s`
const d2 = rawBattery.find((element) => element.time - d1.time == 0);
if (d2 !== undefined) {
battery_t = d2.batteryLevel
}
return {duration: duration, durationT: durationT, ...d1, batteryLevel: battery_t};
})
}
Insert cell
time0 = rawHJWJ[0].time
Insert cell
rawBattery = FileAttachment("231217_142525.csv").csv({typed: true})
Insert cell
Plot.plot({
x: {domain: [0,3], line: true, nice: true, label: "电流(A)", labelArrow: false, labelAnchor: "center"},
y: {domain: [4,9], grid: true, line: true, nice: true, label: "电压(V)", labelAnchor: "center", labelArrow: false},
marks: [
Plot.dot(rawHJWJ, { filter: (d) => d.power > 0, x: "current", y: "voltage", r: 2, symbol: "circle", stroke: "darkcyan", strokeWidth: 0.8, tip: {anchor: "top-right", textPadding: 4, strokeOpacity: 0.1, fill: "darkcyan", fillOpacity: 0.1}, title: (d) => `维简3A ○\n电压:${d.voltage}V\n电流:${d.current}A`}),
Plot.dot(rawHJHW, { filter: (d) => d.power > 0, x: "current", y: "voltage", r: 2, symbol: "triangle2", stroke: "darkgoldenrod", strokeWidth: 0.8, tip: {anchor: "top-left", textPadding: 4, strokeOpacity: 0.1, fill: "darkgoldenrod", fillOpacity: 0.1}, title: (d) => `华为3A △\n电压:${d.voltage}V\n电流:${d.current}A` }),
Plot.ruleY([0]),
Plot.dotY(["维简3A"], {x: 2.4, y: 4.4, symbol: "circle", stroke: "darkcyan"}),
Plot.text([" 航嘉20W + 维简3A线"], {x: 2.4, y: 4.4, textAnchor: "start"}),
Plot.dotY(["华为3A"], {x: 2.4, y: 4.2, symbol: "triangle2", stroke: "darkgoldenrod"}),
Plot.text([" 航嘉20W + 华为3A线"], {x: 2.4, y: 4.2, textAnchor: "start"}),
Plot.ruleX([2.22], {stroke: "grey", strokeOpacity: 0.8}),
Plot.tip([tip222], {x: 2.22, y: 8.3, anchor: "top-right", textPadding: 6, strokeOpacity: 0.3, lineHeight: 1.5}),
]
})
Insert cell
tip222 = {
let tempd = rawHJWJ.filter((d) => d.current == 2.22 && d.voltage > 8)
let mean = d3.mean(tempd, (d) => d.voltage)
let min = d3.min(tempd, (d) => d.voltage)
let max = d3.max(tempd, (d) => d.voltage)
let tempd1 = rawHJHW.filter((d) => d.current == 2.22 && d.voltage > 8)
let mean1 = d3.mean(tempd1, (d) => d.voltage)
let min1 = d3.min(tempd1, (d) => d.voltage)
let max1 = d3.max(tempd1, (d) => d.voltage)
return `电压(V) Mean (Min ~ Max) @2.22A\n-- 维简3A:${d3.format(".2f")(mean)} (${min} ~ ${max})\n-- 华为3A:${d3.format(".2f")(mean1)} (${d3.format(".2f")(min1)} ~ ${max1})`
}
Insert cell
rawHJWJ = FileAttachment("231217_142426.csv").csv({typed: true})
Insert cell
rawHJHW = {
const url = "https://gist.githubusercontent.com/wn2try/47f45560b768da09f0d0061580450af7/raw/21a8887152307825be3c338b30090e8956ace7e2/231129_174428.csv";
return fetch(url)
.then((res) => res.text())
.then((res) => d3.csvParse(res, d3.autoType));
};
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