I am trying to edit the d3_views module in this way:
adding 2 forms in the plugin d3_views_plugin_style_d3.inc:
1.form de type managed file: with this form I want to upload a photo to be used as a backgroud photo for the graph..
$form['Background_image'] = array(
'#type' => 'managed_file',
'#title' => t('Choose a background image'),
'#description' => t('Click "Browse..." to select an image to upload.'),
'#upload_location' => 'public://backgroundimage/',
'#default_value' => $this->options['Background_image'],
);
2.form de type select that display all the text files in the default directory of files: the file.text contains data in the format TVS file.
$form['Get_file'] = array(
'#title' => 'Choose a project',
'#type' => 'select',
'#options' =>$this->get_projects(),
'#default_value' => $this->options['Get_file'],
);
function get_projects(){
$directory= variable_get('file_directory_path', 'sites/default/files');
$filenames = array();
$extension =".txt";
$iterator = new DirectoryIterator($directory);
foreach ($iterator as $fileinfo) {
if ($fileinfo->isFile()) {
//check the extension ".txt"
if (strpos($fileinfo->getFilename(),'.txt') !== false)
{$filenames[$fileinfo->getMTime()] =substr($fileinfo->getFilename(), 0, -4);}
}
}
return $filenames;
}
The Idea is to get the image and the data file ,draw a graph with the data that exist in the data file and use the selected photo as a background photo of the final graph.
This function collect the required informations: data in order to return the graph
function draw($rows) {
$columns = $this->columns();
// I added an element that should contains image obj and the data in the selected txt file
//I definied a function that return the content of a file but still need how to create an image object from the selected image?
$extradata=[];
$legend = array();
foreach ($columns as $column => $info) {
$legend[] = $this->view->field[$column]->label();
}
$this->get_libraries();
$this->get_projects();
$type = $this->libraries[$this->options['library']]['js callback'];
$chart = array(
'id' => 'visualization',
'type' => $type,
'legend' => $legend,
'rows' => $rows,
'data' => $extradata,
);
return d3_draw($chart);
}
//function how to read the content of a file : the problem is how to get the file path automaticly from the selected file in the form
function open_file($path)
{
// I just test the function with a concrete path but I need to get automaticaly the path of the selected file from the get_file form
$path= variable_get('file_directory_path', 'sites/default/files').'/file.txt';
$data = file($path);
return $data;
}