10 #ifndef EMP_D3_LOAD_DATA_H 11 #define EMP_D3_LOAD_DATA_H 17 #include "../JSWrap.h" 18 #include "../js_utils.h" 19 #include "../../tools/string_utils.h" 29 EM_ASM({js.objects[$0] =
emp.__incoming_data;}, this->
id);
35 uint32_t fun_id = emp::JSWrap(comp,
"",
false);
37 double min = EM_ASM_DOUBLE({
38 return d3.min(js.objects[$0],
function(d) {return emp.Callback($1, d);});
41 emp::JSDelete(fun_id);
49 uint32_t fun_id = emp::JSWrap(comp,
"",
false);
51 double max = EM_ASM_DOUBLE({
52 return d3.max(js.objects[$0],
function(d) {return emp.Callback($1, d);});
55 emp::JSDelete(fun_id);
71 EM_ASM_ARGS({js.objects[$0] = [];}, this->
id);
78 js.objects[$0] =
function(root,
id) {
83 for (var k in root.children) {
84 if (root.children[k].name ==
id) {
85 return root.children[k];
87 else if (root.children[k].children) {
88 result = js.objects[$0](root.children[k],
id);
96 }, FindInHierarchy.
GetID());
101 d3.json(Pointer_stringify($1),
function(
data){js.objects[$0]=
data;});
102 },
id, filename.c_str());
105 template <
typename DATA_TYPE>
110 d3.json(Pointer_stringify($1),
function(
data){
112 emp[
"__json_load_fun__"+$0](
data);
114 },
id, filename.c_str());
119 std::cout << filename.c_str() <<
std::endl;
121 var filename = Pointer_stringify($1);
122 d3.json(filename,
function(
data){
124 console.log(filename,
data);
125 emp[
"__json_load_fun__"+$0]();
127 },
id, filename.c_str());
133 js.objects[$0].push(JSON.parse(Pointer_stringify($1)));
134 }, this->
id, json.c_str());
139 int fail = EM_ASM_INT({
141 var obj = JSON.parse(Pointer_stringify($2));
144 for (var i in js.objects[$0]) {
145 result = js.objects[$1](js.objects[$0][i], obj.parent);
153 result.children.push(obj);
155 }, this->
id, FindInHierarchy.
GetID(), json.c_str());
165 int pos = EM_ASM_INT({
166 var parent_node = null;
168 var child_node = JSON.parse(Pointer_stringify($1));
169 for (var item in js.objects[$0]) {
170 if (js.objects[$0][item].name == child_node.parent) {
171 parent_node = js.objects[$0][item];
177 if (!parent_node.hasOwnProperty(
"children")){
178 parent_node.children = [];
180 parent_node.children.push(child_node);
182 }, options.
GetID(), json.c_str());
197 var acc =
function(d){
198 return ([+d[0], +d[1]]);
201 var arg1 = Pointer_stringify($0);
202 var in_string = Pointer_stringify($1);
203 if (typeof window[in_string] ===
"function"){
204 in_string = window[in_string];
205 }
else if (typeof window[
"d3"][in_string] ===
"function") {
206 in_string = window[
"d3"][in_string];
207 }
else if (typeof window[
"emp"][in_string] ===
"function") {
208 in_string = window[
"emp"][in_string];
212 d3.csv(arg1, acc,
function(d){
217 d3.text(arg1,
function(d){
218 js.objects[$2] = d3.csvParseRows(d, acc);
222 }, location.c_str(), callback.c_str(), this->
id, header);
225 void Parse(std::string contents, std::string accessor){
230 void ParseRows(std::string contents, std::string accessor){
236 template <std::size_t N, typename T>
239 emp_i.__outgoing_array = js.objects[$0][js.objects[$0].length - 1];
void LoadDataFromFile(std::string filename, std::function< void(DATA_TYPE)> fun)
Definition: dataset.h:106
std::string to_string(ALL_TYPES &&...all_values)
Definition: string_utils.h:511
REAL_TYPE sfinae_decoy
Definition: meta.h:93
void LoadDataFromFile(std::string filename, std::function< void(void)> fun)
Definition: dataset.h:117
void ParseRows(std::string contents, std::string accessor)
Definition: dataset.h:230
void LoadDataFromFile(std::string location, std::string callback, bool header=true)
Definition: dataset.h:195
emp::sfinae_decoy< double, decltype(&T::operator())> Min(T comp)
Definition: dataset.h:34
JSONDataset()
Definition: dataset.h:70
void LoadDataFromFile(std::string filename)
Definition: dataset.h:99
Catch-all object for storing references to things created in JS.
Definition: d3_init.h:213
CSVDataset()
Definition: dataset.h:191
data
A set of modifiers are available do describe DataNode.
Definition: DataNode.h:38
int id
Definition: d3_init.h:45
JSONDataset(int i)
Definition: dataset.h:69
Definition: dataset.h:189
emp::sfinae_decoy< double, decltype(&T::operator())> Max(T comp)
Definition: dataset.h:48
void pass_array_to_cpp(emp::array< T, SIZE > &arr, bool recurse=false)
Definition: js_utils.h:299
Dataset()
Definition: dataset.h:25
static const PrintStr endl("<br>")
Pre-define emp::endl to insert a "<br>" and thus acting like a newline.
void Parse(std::string contents, std::string accessor)
Definition: dataset.h:225
#define D3_CALLBACK_FUNCTION_2_ARGS(FUNC, CALLBACK, ARG1)
Definition: utils.h:78
void CaptureIncoming()
Definition: dataset.h:28
Wrapper for creating functions in javascript and calling them there.
Definition: d3_init.h:219
void GetLastRow(emp::array< T, N > &arr)
Put the last row of the array into arr.
Definition: dataset.h:237
JSFunction FindInHierarchy
Definition: dataset.h:67
void Append(std::string json)
Definition: dataset.h:131
void AppendNested(std::string json)
Definition: dataset.h:137
If we are in emscripten, make sure to include the header.
Definition: array.h:37
void NotifyWarning(Ts &&...msg)
End user has done something possibly a problem.
Definition: errors.h:141
CSVDataset(int i)
Definition: dataset.h:192
int GetID() const
Definition: d3_init.h:96
Dataset(int i)
Definition: dataset.h:26
int AppendNestedFromList(std::string json, JSObject &options)
Definition: dataset.h:164