brotherton-erpnext/erpnext/public/js/agriculture/ternary_plot.js
Ameya Shenoy 5c62368a65 [Agriculture Domain] (#11663)
* created Soil Analysis, Water Analysis, Weather and Fertilizer doctype

* soil doctype edited and crop doctype added

* minor stuff

* Land Unit + Leaflet

* crop cycle added

* Land Unit changes + Crop cycle

* autoname for plant_analysis

* created Agriculture Task

* minor stuff

* - deleted agriculture_task
- current state after the call

* [Agriculture] modified fertilizer doctype to have a link to Item
This was done so that the `Fertilizer` doctype could track the contents exclusive to the fertilizer, whereas the `Fertilizer Item` could be a seperate entity, so as to leverage the existing ERPNext doctypes

* Added fields to `Water Analysis` doctype
- Collection Datetime
- Laboratory Testing Datetime
- Results Datetime (default to Laboratory Testing Datetime)

* Edited the doctypes `Agrivulture Task`, `Pest` and `Soil Texture`
- Created `agriculture task` doctype
- added fields `Common Name`, `Scientific Name`, `Treatment` and `Treatment Options` to `Pest` doctype
- edited `Soil Texture` doctype to contain a soil texture ternary plot diagram made using SnapSVG. The code was put in public folder so as to be accessible by the entire agriculture module

* Recursively reflect child land unit feature changes on parents

* fixed feature repition bug

* added legeneds to ternary plot

* added stuff

* changes

* fix Task

* reverted the Task Doctype to have naming in the form TASK.#####

* fixed modifications made to TASK doctype

* [dirty commit] added auto create Task from Crop on creation of Crop Cycle

* Changed the Crop Cycle Doctype
- Deleted the "Crop Cycly Task" doctype and its link from "Crop Cycle"
- Creation of a new Project with the same name as the Crop Cycle on creation of a new Crop Cycle
- Creation of all the tasks imported from Agriculture Task doctype of the Crop in the Crop Cycle

* [Agriculture Module] Modifications
- Created childtable doctype "Pest Detected"
- Added childtable "Pest Detected" to Pest
- Modified "Agriculture Task" to include "Start Day" and "End Day" of task
- Modified the code in "Crop Cycle" to create a parent task with same name as Crop Cycle

* [Agriculture Module] fixed Pest doctype not saving issue

* [Agrcilture Module] Changes in Crop Cycle
- removed the creation of a master task on creation of a new crop cycle
- temporary fix to add the pest tasks from the pests added in crop cycle

* land_unit_tree.js fields modified to have field objects instead of just field names

* Revert "land_unit_tree.js modified"

* land_unit_tree.js fields modified to have field objects instead of just field names

* [Agriculture Domain] Converted Agriculture Module to a Domain
- Converted into a Domain field from Select to Link field in Company doctype, linked to Domain doctype
- Agriculture (alpha) is now a Domain

* land_unit area aggregation enabled

* land_unit.py checks feature diff for every ancestor and not just the parent

* Removed unnecessary print messages

* agriculture.py modified to include fixtures

* fixtures added to setup.py inside agriculture module

* [Agriculture Domain] UI tests added
- 'materials' table renamed to 'materials_required' in 'Crop'
- wrote UI test for Crop, Fertilizer, Crop Cycle, Pest, Water Analysis, Soil Texture
- moved creation of tasks from client side to server side in Crop Cycle
- Plant Analysis, Water Analysis, Soil Analysis, Soil Texture docs are now autonamed in the format PAnalysis.#####, WAnalysis.#####, SAnalysis.#####, STexture.##### respectively
- company_name changed in domains.py from 'Schrute Farms.' to 'Schrute Farms'

* [Agriculture Domain] Mostly written server side tests and moved client side code to server side
- moved client side code to server side for Crop, Water Analysis, Pest, Soil Texture,
- wrote server side tests for Crop, Crop Cycle, Fertilizer, Soil Texture, Pest
- NOTE: none of the server side codes were tested

* [Agriculture Domain] All server side tests working locally

* [Agriculture Domain] Testing
- added sample test for Land Unit, which needs to be modified to test multiple things
- modified tests to be independant of each other

* Land Units tests added and area aggregation code migrated to server side

* added land_unit server side tests and on_trash added to land_unit

* Changing field location for start date

* [Agriculture Domain] deleted unnecessary comments

* [Agriculture Domain] reverted changes

* [Agriculture Domain] Modified the code to replace Pest doctype with Land Unit doctype
- Deleted the Pest doctype and replaced it with the more generic Disease doctype
- Deleted the Detected Pest doctype and replaced it with Detected Disease doctype

* [Agriculture Domain] resolves #11654, resolves #11653

* [Agriculture] Added links to soil analysis, soil texture, plant analysis in crop cycle and land unit
- not working perfectly yet
- docs are fetched but not appended

* [Agricuture] Crop Cycle modifed to link with relevent analysis docs, not fully functional

* [Agriculture] added seperate stage for client side agriculture tests

* [Agriculture] minor modification to crop_cycle.js test

* [Agriculture] fixed tests

* upgrade chromedriver in .travis.yml from 2.32 to 2.33

* [Agriculture] added land unit ui test

* [Agriculture] added Agriculture server side test as a seperate stage in travis

* tesing travis.yml

* [Agriculture] Crop Cycle is able to fetch linked analysis docs

* Modified travis.yml for modular server side testing

* [minor fix][Agriculture] in soil_texture

- fixed multiple soil_texture ternary plot creation on refresh
- fixed error on soil composition change

* Update .travis.yml

* removed location field from linked doctypes

* minor fixes and cleanup of agri

* minor fix in agriculture and domain patches

* permissions added to agriculture

- Agriculture Manager and Agriculture User roles were added to all Agriculture doctypes

* [Agriculture]

- Created Agiculture Analysis Criteria and added sample records to it
- All the analysis doctypes now fetch their fields inside a child table, form Agriculture Analysis Criteria
- Also Fertilizer does the same
  This was introduced so that, new parameters could be added on demand

* minor changes requested in Agriculture

* minor changes

* minor fix

* Update desktop.py

* Update .travis.yml
2017-12-06 18:36:27 +05:30

232 lines
7.3 KiB
JavaScript

frappe.provide('agriculture');
agriculture.TernaryPlot = class TernaryPlot {
constructor(opts) {
Object.assign(this, opts);
frappe.require('assets/frappe/js/lib/snap.svg-min.js', () => {
this.make_svg();
this.init_snap();
this.init_config();
this.make_plot();
this.make_plot_marking();
this.make_legend();
this.mark_blip();
});
}
make_svg() {
this.$svg = $('<svg height="350" width="400">');
$(this.parent).append(this.$svg);
}
init_snap() {
this.paper = new Snap(this.$svg.get(0));
}
init_config() {
this.config = {
triangle_side: 300,
spacing: 50,
strokeWidth: 1,
stroke: frappe.ui.color.get('black')
};
this.config.scaling_factor = this.config.triangle_side / 100;
let { triangle_side: t, spacing: s, scaling_factor: p } = this.config;
this.coords = {
sand: {
points: [
s + t * Snap.cos(60), s,
s, s + t * Snap.cos(30),
s + t, s + t * Snap.cos(30)
],
color: frappe.ui.color.get('peach')
},
loamy_sand: {
points: [
s + 15 * p * Snap.cos(60), s + (100 - 15) * p * Snap.cos(30),
s + 10 * p * Snap.cos(60), s + (100 - 10) * p * Snap.cos(30),
s + (100 - 85) * p, s + t * Snap.cos(30),
s + (100 - 70) * p, s + t * Snap.cos(30)
],
color: frappe.ui.color.get('pink')
},
sandy_loam: {
points: [
s + 20 * p * Snap.cos(60) + 27.5 * p, s + (100 - 20) * p * Snap.cos(30),
s + 20 * p * Snap.cos(60), s + (100 - 20) * p * Snap.cos(30),
s + 15 * p * Snap.cos(60), s + (100 - 15) * p * Snap.cos(30),
s + (100 - 75) * p, s + t * Snap.cos(30),
s + (100 - 50) * p, s + t * Snap.cos(30),
s + (100 - 50) * p + 7.5 * p * Snap.cos(60), s + t * Snap.cos(30) - 7.5 * p * Snap.cos(30),
s + (100 - 50) * p + 7.5 * p * Snap.cos(60) - 10 * p, s + t * Snap.cos(30) - 7.5 * p * Snap.cos(30)
],
color: frappe.ui.color.get('pink', 'light')
},
loam: {
points: [
s + (100 - 50) * p + 27.5 * p * Snap.cos(60), s + t * Snap.cos(30) - 27.5 * p * Snap.cos(30),
s + (100 - 50) * p + 27.5 * p * Snap.cos(60) - 22.5 * p, s + t * Snap.cos(30) - 27.5 * p * Snap.cos(30),
s + 20 * p * Snap.cos(60) + 27.5 * p, s + (100 - 20) * p * Snap.cos(30),
s + (100 - 50) * p + 7.5 * p * Snap.cos(60) - 10 * p, s + t * Snap.cos(30) - 7.5 * p * Snap.cos(30),
s + (100 - 50) * p + 7.5 * p * Snap.cos(60), s + t * Snap.cos(30) - 7.5 * p * Snap.cos(30)
],
color: frappe.ui.color.get('brown')
},
silt_loam: {
points: [
s + t - 27.5 * p * Snap.cos(60), s + 72.5 * p * Snap.cos(30),
s + (100 - 50) * p + 27.5 * p * Snap.cos(60), s + t * Snap.cos(30) - 27.5 * p * Snap.cos(30),
s + (100 - 50) * p, s + t * Snap.cos(30),
s + (100 - 20) * p, s + t * Snap.cos(30),
s + (100 - 20) * p + 12.5 * p * Snap.cos(60), s + 90 * p * Snap.cos(30),
s + t - 12.5 * p * Snap.cos(60), s + (100 - 12.5) * p * Snap.cos(30)
],
color: frappe.ui.color.get('green', 'dark')
},
silt: {
points: [
s + t - 12.5 * p * Snap.cos(60), s + (100 - 12.5) * p * Snap.cos(30),
s + (100 - 20) * p + 12.5 * p * Snap.cos(60), s + 90 * p * Snap.cos(30),
s + (100 - 20) * p, s + t * Snap.cos(30),
s + t, s + t * Snap.cos(30)
],
color: frappe.ui.color.get('green')
},
silty_clay_loam: {
points: [
s + t - 40 * p * Snap.cos(60), s + 60 * p * Snap.cos(30),
s + t - 40 * p * Snap.cos(60) - 20 * p, s + 60 * p * Snap.cos(30),
s + t - 27.5 * p * Snap.cos(60) - 20 * p, s + 72.5 * p * Snap.cos(30),
s + t - 27.5 * p * Snap.cos(60), s + 72.5 * p * Snap.cos(30)
],
color: frappe.ui.color.get('cyan', 'dark')
},
silty_clay: {
points: [
s + t - 60 * p * Snap.cos(60), s + 40 * p * Snap.cos(30),
s + t - 40 * p * Snap.cos(60) - 20 * p, s + 60 * p * Snap.cos(30),
s + t - 40 * p * Snap.cos(60), s + 60 * p * Snap.cos(30)
],
color: frappe.ui.color.get('cyan')
},
clay_loam: {
points: [
s + t - 40 * p * Snap.cos(60) - 20 * p, s + 60 * p * Snap.cos(30),
s + t - 40 * p * Snap.cos(60) - 45 * p, s + 60 * p * Snap.cos(30),
s + t - 27.5 * p * Snap.cos(60) - 45 * p, s + 72.5 * p * Snap.cos(30),
s + t - 27.5 * p * Snap.cos(60) - 20 * p, s + 72.5 * p * Snap.cos(30)
],
color: frappe.ui.color.get('green', 'light')
},
sandy_clay_loam: {
points: [
s + 35 * p * Snap.cos(60) + 20 * p, s + (100 - 35) * p * Snap.cos(30),
s + 35 * p * Snap.cos(60), s + (100 - 35) * p * Snap.cos(30),
s + 20 * p * Snap.cos(60), s + (100 - 20) * p * Snap.cos(30),
s + 20 * p * Snap.cos(60) + 27.5 * p, s + (100 - 20) * p * Snap.cos(30),
s + t - 27.5 * p * Snap.cos(60) - 45 * p, s + 72.5 * p * Snap.cos(30)
],
color: frappe.ui.color.get('pink', 'dark')
},
sandy_clay: {
points: [
s + 55 * p * Snap.cos(60), s + (100 - 55) * p * Snap.cos(30),
s + 35 * p * Snap.cos(60), s + (100 - 35) * p * Snap.cos(30),
s + 35 * p * Snap.cos(60) + 20 * p, s + (100 - 35) * p * Snap.cos(30)
],
color: frappe.ui.color.get('red')
},
clay: {
points: [
s + t * Snap.cos(60), s,
s + 55 * p * Snap.cos(60), s + (100 - 55) * p * Snap.cos(30),
s + t - 40 * p * Snap.cos(60) - 45 * p, s + 60 * p * Snap.cos(30),
s + t - 40 * p * Snap.cos(60) - 20 * p, s + 60 * p * Snap.cos(30),
s + t - 60 * p * Snap.cos(60), s + 40 * p * Snap.cos(30)
],
color: frappe.ui.color.get('yellow')
},
};
}
get_coords(soil_type) {
return this.coords[soil_type].points;
}
get_color(soil_type) {
return this.coords[soil_type].color;
}
make_plot() {
for (let soil_type in this.coords) {
this.paper.polygon(this.get_coords(soil_type)).attr({
fill: this.get_color(soil_type),
stroke: this.config.stroke,
strokeWidth: this.config.strokeWidth
});
}
}
make_plot_marking() {
let { triangle_side: t, spacing: s, scaling_factor: p } = this.config;
let clay = this.paper.text(t * Snap.cos(60) / 2, s + t * Snap.cos(30) / 2, "Clay").attr({
fill: frappe.ui.color.get('black')
});
clay.transform("r300");
let silt = this.paper.text(t, s + t * Snap.cos(30) / 2, "Silt").attr({
fill: frappe.ui.color.get('black')
});
silt.transform("r60");
let sand = this.paper.text(35 + t * Snap.cos(60), 90 + t * Snap.cos(30), "Sand").attr({
fill: frappe.ui.color.get('black')
});
sand.transform("r0");
}
make_legend() {
// let side = len(this.coords)/2;
let index = 1;
let offset = 0;
let exec_once = true;
for (let soil_type in this.coords) {
if (index > 6 && exec_once){
offset = 300;
index = 1;
exec_once = false;
}
let rect = this.paper.rect(0+offset, 0+index*20, 100, 19, 5, 5).attr({
fill: this.get_color(soil_type),
stroke: frappe.ui.color.get('black')
});
let text = this.paper.text(5+offset, 16+index*20, soil_type).attr({
fill: frappe.ui.color.get('black'),
'font-size': 12
});
index++;
}
}
mark_blip({clay, sand, silt} = this) {
if (clay + sand + silt != 0){
let { triangle_side: t, spacing: s, scaling_factor: p } = this.config;
let x_blip = s + clay * p * Snap.cos(60) + silt * p;
let y_blip = s + silt * p * Snap.cos(30) + sand * p * Snap.sin(60);
this.blip = this.paper.circle(x_blip, y_blip, 4).attr({
fill: frappe.ui.color.get("orange"),
stroke: frappe.ui.color.get("orange"),
strokeWidth: 2
});
}
}
remove_blip() {
if (typeof this.blip !== 'undefined')
this.blip.remove();
}
};