daily_observations_chart = {
let thedata = clientes_energizados_daychosen;
let thedata_max = thedata[d3.maxIndex(thedata, d => d.total_clientes_sin_servicio)];
let themargins = {
marginLeft: 10,
marginRight: 0,
marginTop: 20,
marginBottom: 40,
}
let the_width = chosen_width
let chart_width = the_width - themargins.marginLeft - themargins.marginRight;
let num_points = 288;
const min_radius = 1;
const max_radius = 3;
const chosen_radius = dot_symbol_packing_X('circle', chart_width, num_points, min_radius, max_radius);
const rule_padding = .95;
const min_rule_width = 0;
const fit_radius = chart_width / (num_points - 1) / 2;
const fit_rule_width = fit_radius*2;
const padded_rule_width = fit_rule_width * (1 - rule_padding);
const chosen_rule_width = Math.max(
min_rule_width,
Math.min(padded_rule_width, 1)
);
let theplot = Plot.plot({
caption: `Radius: ${(chosen_radius)} Rule width: ${chosen_rule_width} Chart width: ${chart_width}`,
style: "overflow: visible;",
...themargins,
// marginLeft: 80,
width: the_width,
// width: 700,
height: 600,
// marginTop: 200,
x: {
domain: [fecha_picker, new Date(fecha_picker.getTime() + 1439*60000)],
},
y: {
domain: [0,100e3],
// ticks: 5,
// tickFormat: '%'
},
r: {type: 'linear'},
marks: [
Plot.axisX({
fontFamily: 'Inter, sans-serif',
}),
Plot.axisY({
rotate: -90,
textAnchor: 'middle',
tickFormat: d => (d/1e3).toString() + ' mil',
label: null,
fontSize: 12,
tickSize: 0,
fontFamily: 'Inter, sans-serif',
// ticks: 5,
ticks: [25e3, 50e3, 75e3, 100e3],
}),
Plot.gridY({
strokeDasharray: "2",
interval: 25e3, stroke: "black", strokeOpacity: 1}),
// Plot.areaY(
// thedata
// , {
// tip: false,
// x: "marca_hora_presentada",
// y1: d => d["total_clientes_sin_servicio"] >= service_threshold ? 0 : null,
// y2: d => d["total_clientes_sin_servicio"] >= service_threshold ? d["total_clientes_sin_servicio"] : null,
// fill: 'red', fillOpacity: 0.5,
// curve: 'step-after'
// //stroke: 'red', strokeOpacity: 1,
// }),
Plot.ruleX(thedata, {
x: 'marca_hora_presentada', y: d => d.total_clientes_sin_servicio !== 0 ? d.total_clientes_sin_servicio : null,
// strokeWidth: d => .2,
strokeWidth: chosen_rule_width,
}),
Plot.ruleX(thedata, {
x: 'marca_hora_presentada',
y1: d => d.total_clientes_sin_servicio !== 0 ? Math.max(0, d.total_clientes_sin_servicio - stroke_length) : null,
y2: d => d.total_clientes_sin_servicio !== 0 ? d.total_clientes_sin_servicio : null,
// strokeWidth: d => .2,
strokeWidth: 1,
stroke: 'black',
strokeLinecap: 'square',
}),
show_line ? Plot.line(
thedata
, {
tip: false,
x: "marca_hora_presentada", y:"total_clientes_sin_servicio",
stroke: 'darkblue',
strokeWidth: chosen_radius,
channels: {noService: "porcentaje_clientes_sin_servicio", hora: 'marca_hora_presentada'},
}) : null,
show_dot ? Plot.dot(
thedata
, {
tip: true,
x: "marca_hora_presentada", y:"total_clientes_sin_servicio",
stroke: null,
fill: 'black',
r: chosen_radius,
channels: {noService: "porcentaje_clientes_sin_servicio", hora: 'marca_hora_presentada'},
}) : null,
Plot.text([thedata_max], {
x: "marca_hora_presentada", y:"total_clientes_sin_servicio",
fill: 'black',
text: 'total_clientes_sin_servicio',
lineAnchor: 'bottom', dy: -8,
fontWeight: 'bold',
fontSize: 14,
fontFamily: 'B612 Mono',
}),
Plot.ruleY([0]),
// Plot.Tip()
]
})
return theplot
}