dev:web: chart.hamlet: reindent, simpler comment syntax

This commit is contained in:
Simon Michael 2025-06-28 21:01:24 -07:00
parent fd0bf6f90d
commit cb0a0fafa5

View File

@ -8,8 +8,8 @@ $# If $ is the first character in a line, it must be \-escaped to hide it from h
\$('#register-chart-label').text('#{charttitle}'); \$('#register-chart-label').text('#{charttitle}');
var seriesData = [ var seriesData = [
$forall (c,items) <- percommoditytxnreports $forall (c,items) <- percommoditytxnreports
/* we render each commodity using two series: // we render each commodity using two series:
* one with extra data points added to show a stepped balance line */ // one with extra data points added to show a stepped balance line
{ {
data: [ data: [
$forall i <- reverse items $forall i <- reverse items
@ -30,7 +30,7 @@ $# If $ is the first character in a line, it must be \-escaped to hide it from h
clickable: false, clickable: false,
hoverable: false, hoverable: false,
}, },
/* and one with the original data, showing one clickable, hoverable point per transaction */ // and one with the original data, showing one clickable, hoverable point per transaction
{ {
data: [ data: [
$forall i <- reverse items $forall i <- reverse items
@ -42,7 +42,6 @@ $# If $ is the first character in a line, it must be \-escaped to hide it from h
'#{concat $ intersperse "\\n" $ lines $ T.unpack $ showTransaction $ triOrigTransaction i}', '#{concat $ intersperse "\\n" $ lines $ T.unpack $ showTransaction $ triOrigTransaction i}',
#{tindex $ triOrigTransaction i} #{tindex $ triOrigTransaction i}
], ],
/* [] */
], ],
label: '', label: '',
color: #{colorForCommodity c}, color: #{colorForCommodity c},
@ -53,13 +52,20 @@ $# If $ is the first character in a line, it must be \-escaped to hide it from h
show: true, show: true,
}, },
}, },
] ];
var plot = registerChart($chartdiv, seriesData);
plot.setSelection({ xaxis: { from: 500, to: 700 } }); // ?
\$chartdiv.bind("plotclick", registerChartClick);
\$chartdiv.bind("plotselected", registerChartSelect);
};
});
//eslint-disable-next-line no-unused-vars //eslint-disable-next-line no-unused-vars
function registerChart($container, series) { function registerChart($container, series) {
// https://github.com/flot/flot/blob/master/API.md // https://github.com/flot/flot/blob/master/API.md
return $container.plot( return $container.plot(
series, series,
{ /* general chart options */ {
xaxis: { xaxis: {
mode: "time", mode: "time",
timeformat: "%Y/%m/%d", timeformat: "%Y/%m/%d",
@ -100,7 +106,7 @@ $# If $ is the first character in a line, it must be \-escaped to hide it from h
autoHighlight: true, autoHighlight: true,
clickable: true, clickable: true,
}, },
/* https://github.com/krzysu/flot.tooltip */ // https://github.com/krzysu/flot.tooltip
tooltip: true, tooltip: true,
tooltipOpts: { tooltipOpts: {
xDateFormat: "%Y/%m/%d", xDateFormat: "%Y/%m/%d",
@ -116,6 +122,8 @@ $# If $ is the first character in a line, it must be \-escaped to hide it from h
} }
).data("plot"); ).data("plot");
} }
// Handle a click event on the chart.
function registerChartClick(ev, pos, item) { function registerChartClick(ev, pos, item) {
if (!item) { if (!item) {
return; return;
@ -129,13 +137,15 @@ $# If $ is the first character in a line, it must be \-escaped to hide it from h
}, 1000); }, 1000);
} }
} }
// Handle a selection (zoom) event on the chart. // Handle a selection (zoom) event on the chart.
// This should pick good from/to dates based on the selected x-values, which is tricky to get right.
function registerChartSelect(ev, ranges) { function registerChartSelect(ev, ranges) {
console.log("selected", ranges.xaxis.from, ranges.xaxis.to); console.log("selected", ranges.xaxis.from, ranges.xaxis.to);
/* Round down for the 'from' day: */
// This should pick good from/to dates based on the selected x-values, which is tricky to get right.
// Round down for the 'from' day:
var from = new Date(ranges.xaxis.from); var from = new Date(ranges.xaxis.from);
/* Round up for the 'to' day: */ // Round up for the 'to' day:
var to = new Date(ranges.xaxis.to + (24 * 60 * 60 * 1000) - 1); var to = new Date(ranges.xaxis.to + (24 * 60 * 60 * 1000) - 1);
var range = var range =
from.getFullYear() + "/" + (from.getMonth() + 1) + "/" + from.getDate() + "-" + from.getFullYear() + "/" + (from.getMonth() + 1) + "/" + from.getDate() + "-" +
@ -147,9 +157,3 @@ $# If $ is the first character in a line, it must be \-escaped to hide it from h
document.location = baselink + "%20date:" + range; document.location = baselink + "%20date:" + range;
} }
} }
var plot = registerChart($chartdiv, seriesData);
plot.setSelection({ xaxis: { from: 500, to: 700 } });
\$chartdiv.bind("plotclick", registerChartClick);
\$chartdiv.bind("plotselected", registerChartSelect);
};
});