refactor: working heatmap

This commit is contained in:
ruthra kumar 2023-09-27 09:35:25 +05:30
parent bd3dc6482e
commit 16db6c2f47
2 changed files with 63 additions and 25 deletions

View File

@ -2,27 +2,58 @@
// For license information, please see license.txt
frappe.ui.form.on("Bisect Accounting Statements", {
onload(frm) {
frm.trigger("render_heatmap");
},
refresh(frm) {
frm.add_custom_button(__('Bisect Left'), () =>
frm.trigger("bisect_left")
);
frm.add_custom_button(__('Bisect Left'), () => {
frm.trigger("bisect_left");
});
frm.add_custom_button(__('Bisect Right'), () =>
frm.trigger("bisect_right")
);
frm.add_custom_button(__('Bisect Right'), () => {
frm.trigger("bisect_right");
});
frm.add_custom_button(__('Up'), () =>
frm.trigger("move_up")
);
frm.add_custom_button(__('Build Tree'), () =>
frm.trigger("build_tree")
);
frm.add_custom_button(__('Up'), () => {
frm.trigger("move_up");
});
frm.add_custom_button(__('Build Tree'), () => {
frm.trigger("build_tree");
});
},
render_heatmap(frm) {
let bisect_heatmap = frm.get_field("bisect_heatmap").$wrapper;
bisect_heatmap.addClass("bisect_heatmap_location");
// milliseconds in a day
let msiad=24*60*60*1000;
let datapoints = {};
let fr_dt = new Date(frm.doc.current_from_date).getTime();
let to_dt = new Date(frm.doc.current_to_date).getTime();
for(let x=fr_dt; x <= to_dt; x+=msiad){
let epoch_in_seconds = x/1000;
datapoints[epoch_in_seconds] = 1;
}
console.log(datapoints);
new frappe.Chart(".bisect_heatmap_location", {
type: "heatmap",
title: "Bisecting On",
data: {
dataPoints: datapoints,
start: new Date(frm.doc.from_date),
end: new Date(frm.doc.to_date),
},
countLabel: 'Difference',
discreteDomains: 1
});
},
bisect_left(frm) {
frm.call({
doc: frm.doc,
method: 'bisect_left',
callback: (r) => {
frm.trigger("render_heatmap");
console.log(r);
}
});
@ -32,6 +63,7 @@ frappe.ui.form.on("Bisect Accounting Statements", {
doc: frm.doc,
method: 'bisect_right',
callback: (r) => {
frm.trigger("render_heatmap");
console.log(r);
}
});
@ -41,6 +73,7 @@ frappe.ui.form.on("Bisect Accounting Statements", {
doc: frm.doc,
method: 'move_up',
callback: (r) => {
frm.trigger("render_heatmap");
console.log(r);
}
});
@ -50,6 +83,7 @@ frappe.ui.form.on("Bisect Accounting Statements", {
doc: frm.doc,
method: 'build_tree',
callback: (r) => {
frm.trigger("render_heatmap");
console.log(r);
}
});

View File

@ -14,13 +14,14 @@
"to_date",
"column_break_iwny",
"algorithm",
"section_break_zbty",
"section_break_8ph9",
"current_node",
"sandbox",
"section_break_hmsy",
"current_from_date",
"column_break_uqyd",
"current_to_date",
"section_break_ngid",
"bisect_heatmap",
"section_break_hbyo",
"p_l_summary",
"column_break_aivo",
@ -54,10 +55,6 @@
"fieldname": "column_break_iwny",
"fieldtype": "Column Break"
},
{
"fieldname": "section_break_zbty",
"fieldtype": "Section Break"
},
{
"fieldname": "current_node",
"fieldtype": "Link",
@ -65,12 +62,6 @@
"label": "Current Node",
"options": "Nodes"
},
{
"fieldname": "sandbox",
"fieldtype": "HTML",
"hidden": 1,
"label": "sandbox"
},
{
"fieldname": "section_break_hmsy",
"fieldtype": "Section Break"
@ -125,13 +116,26 @@
{
"fieldname": "column_break_hcam",
"fieldtype": "Column Break"
},
{
"fieldname": "section_break_ngid",
"fieldtype": "Section Break"
},
{
"fieldname": "section_break_8ph9",
"fieldtype": "Section Break"
},
{
"fieldname": "bisect_heatmap",
"fieldtype": "HTML",
"label": "Heatmap"
}
],
"hide_toolbar": 1,
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2023-09-26 21:25:48.779453",
"modified": "2023-09-27 12:10:40.044935",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Bisect Accounting Statements",