Skip to content

Commit

Permalink
save preference implementated
Browse files Browse the repository at this point in the history
  • Loading branch information
Koushikphy committed Jan 19, 2023
1 parent 3180f5c commit f502ffe
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Interactive Data Editor
### <i>A Software to interactively edit data in a graphical manner.</i>

[![Version](https://img.shields.io/badge/Version-2.12.1-brightgreen.svg)]()
[![Version](https://img.shields.io/badge/Version-2.13.0-brightgreen.svg)]()
[![MIT License](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://github.com/Koushikphy/Interactive_Data_Editor/blob/master/LICENSE)
[![interactive-data-editor](https://snapcraft.io/interactive-data-editor/badge.svg)](https://snapcraft.io/interactive-data-editor)
[![interactive-data-editor](https://snapcraft.io/interactive-data-editor/trending.svg?name=0)](https://snapcraft.io/interactive-data-editor)
Expand Down
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v2.13.0
1. **Save Preference**: Specify which columns to write and what format to use.

## v2.12.1
1. Bug with value swapping resolved.
2. Auto saving error fixed.
Expand Down
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ const homeMenuTemplate = [
mainWindow.webContents.send("menuTrigger", "saveas");
}
},
{
label: "Save Preference",
enabled: false,
id: 'savepref',
click() {
mainWindow.webContents.send("menuTrigger", "savepref");
}
},
{
label : "Export as image",
click() {
Expand Down Expand Up @@ -329,7 +337,7 @@ const homeMenuTemplate = [
if(mainWindow!=window) window.close()
})
var men = Menu.getApplicationMenu();
for (let i of ['save', 'saveas', 'tfs','tpl', '3dview', "spr", 'af', 'arf', 'tax', 'swapen', "extend", "fill", "filter", 'rgfit', 'lmfit']) {
for (let i of ['save', 'saveas', 'savepref', 'tfs','tpl', '3dview', "spr", 'af', 'arf', 'tax', 'swapen', "extend", "fill", "filter", 'rgfit', 'lmfit']) {
men.getMenuItemById(i).enabled = false;
}
mainWindow.reload();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"author": "Koushik Naskar <[email protected]>",
"copyright": "Copyright © January,2022 Koushik Naskar",
"homepage": "https://github.com/Koushikphy/Interactive-Data-Editor",
"version": "2.12.1",
"version": "2.13.0",
"main": "index.js",
"license": "MIT",
"scripts": {
Expand Down
12 changes: 2 additions & 10 deletions src/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -997,16 +997,8 @@ a:focus{



.adSave{
display: grid;
grid-auto-flow: row;
grid-template-columns: repeat(2,max-content);
grid-template-rows: repeat(4,max-content);
grid-column-gap: .5em;
grid-row-gap: 0.3em;



#popSv{
padding: 0.1em 0.3em;font-size: 1.1em;margin-top: 0.5em;
}
#fixer > input[type="submit"]{
grid-row: span 2;
Expand Down
33 changes: 23 additions & 10 deletions src/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,21 +238,34 @@
</div>


<!-- Advanced save popup
<div id="popupSetVal" class="popup" style="display: block">
<!-- Advanced save popup -->
<div id="popAdSv" class="popup">
<div class="title">
<label class='titletxt'>Save Options</label>
<b class='closbtn' title="Close">X</b>
</div>
<div class="popmain adSave">
<label title="Field delimiter to separate the values">Columns delimiter</label> <input type="text" id='saveDel' value="\t">
<label title="Single or sequence of format">Save format</label> <input type="text" id='saveForm'>
<label title="Which columns to store">Use columns</label> <input type="text" id='saveCol'>
<label title="Any text to put at the top of the file">Header</label> <input type="text" id='saveHead'>
<div class="popmain" style="text-align: center;padding: 0.5em">
<table>
<thead>
<tr>
<th colspan="2" style="padding-right: 10px;">Use column</th>
<th>Format</th>
</tr>
</thead>
<tbody id="sBody"></tbody>
</table>

<div style="text-align: left;margin-top: 0.3em;font-size: 0.75em;margin-bottom: 0.7em;">
&#x1F6C8;<a title="Complete Format Specification" href='javascript:void(0);'
style="text-decoration: underline;color: blue;font-style: italic;"
onclick="shell.openExternal('https://docs.python.org/3/library/string.html#format-specification-mini-language')">Complete Format Specification</a>
</div>
<div>
<input id="popSv"type="submit" value="Save">
</div>
</div>
</div> -->

</div>


<div id="branding">
Expand Down
105 changes: 79 additions & 26 deletions src/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ Plotly.newPlot(figurecontainer, [clone(iniPointsD)], clone(layout), {
modeBarButtonsToAdd: [[{
name: 'Save the image',
icon: Plotly.Icons.camera,
click() { document.getElementById('imRes').value = `${window.innerWidth}x${window.innerHeight}`;
$('#popupEx').show()
}
click() {
document.getElementById('imRes').value = `${window.innerWidth}x${window.innerHeight}`;
$('#popupEx').show()
}
}]]
});
var points = figurecontainer.querySelector(".scatterlayer .trace:first-of-type .points").getElementsByTagName("path");
Expand All @@ -49,7 +50,7 @@ function setUpFor2d() {
$('#yLabel').html('X')
$('#zLabel').html('Y')
col = store.get("cols2d", { x: 0, y: 0, z: 0, s: 0 })
enableMenu(['save', 'saveas', 'tfs', 'tpl', "spr", 'swapen', "extend", "fill", "filter", 'af', 'arf', 'rgfit', 'lmfit', 'smooth', 'fixer'])
enableMenu(['save', 'saveas', 'savepref', 'tfs', 'tpl', "spr", 'swapen', "extend", "fill", "filter", 'af', 'arf', 'rgfit', 'lmfit', 'smooth', 'fixer'])
disableMenu(["tax", '3dview'])
}

Expand All @@ -60,7 +61,7 @@ function setUpFor3d() {
$('#zLabel').html('Z')
setUpSlider();
col = store.get("cols3d", { x: 0, y: 0, z: 0, s: 0 })
enableMenu(['save', 'saveas', 'tfs', 'tpl', "spr", 'swapen', "extend", "fill", "filter", 'af', 'arf', 'tax', '3dview', 'smooth', 'fixer'])
enableMenu(['save', 'saveas', 'savepref', 'tfs', 'tpl', "spr", 'swapen', "extend", "fill", "filter", 'af', 'arf', 'tax', '3dview', 'smooth', 'fixer'])
disableMenu(["rgfit", 'lmfit'])
}

Expand Down Expand Up @@ -143,7 +144,7 @@ function fileReader(fname) {
swapped = 0; xName = "X"; saved = true, index = [], firstSave = true;
undoRedo.reset()
swapper.close();

data = fileOpener(fname)
is3D = data.length != 1;

Expand Down Expand Up @@ -190,6 +191,7 @@ function fileReader(fname) {
toolbarutil.closeToolBar()
autoSaver.resetReminder()
sidebar.buildSideBar()
saveProp.reset()
analytics.add('fileLoaded')
}

Expand Down Expand Up @@ -561,31 +563,37 @@ function saveAs() {
}


function parseSaveOption(){

getVal = (x) => document.getElementById(x).value.trim()

let delimiter = getVal("saveDel")
let format = getVal("saveForm").split(',')
let saveCols = getVal("saveCol").split(',')
let saveHead = getVal("saveHead")
let colLength = data[0].length

if(delimiter=="") delimiter ="\t"

if(format=="") format =".8g"
if(format.length==1) format = new Array(colLength).fill(format)
if(format.length!=1) alertElec("Format should be a single specifier or secifier for each column")

// if(saveCols=="")
function saveData() {
try {
var formats = saveProp.formats.map(Plotly.d3.format)
} catch (error) {
alertElec("Invalid write format")
}

var checkCol = []
saveProp.checks.forEach((e, i) => {if (e) checkCol.push(i) })

try{
var tmpData = swapped ? expRotate(data, col.y, col.x) : data
var txt = tmpData.map(x => transpose(x).map(y =>
checkCol.map(ind => formats[ind](y[ind])).join('\t')
).join('\n')).join('\n\n')

fs.writeFileSync(saveNames[currentEditable], txt);
showStatus("Data Saved in file " + replaceWithHome(saveNames[currentEditable]));
saved = true;
autoSaver.resetReminder()
analytics.add('saved')
} catch (error) {
showStatus("Something went wrong! Couldn't save the data...")
console.error(error)
return false;
}
}



function saveData() {
function saveData_old() {
var tmpData = swapped ? expRotate(data, col.y, col.x) : data
// https://www.npmjs.com/package/d3-format#locale_formatPrefix
//^ using d3 format, `g` means decimal/exponent notation, rounded to significant digits
Expand Down Expand Up @@ -932,7 +940,7 @@ class Analytics {
store.set('shown', shown + 1)
// if (shown % 10 == 0) { // shown after every 10 opening
// }
if(shown==0){
if (shown == 0) {
setTimeout(() => {
showInfo(
"Note from developer !",
Expand Down Expand Up @@ -972,4 +980,49 @@ class Analytics {
}
}

const analytics = new Analytics()
const analytics = new Analytics()


class SaveProperties {
// https://docs.python.org/3/library/string.html#format-specification-mini-language
constructor() {
}

reset() { // should load on every file load and also in every column change
this.colLenght = data[0].length
this.formats = new Array(this.colLenght).fill('.8g')
this.checks = new Array(this.colLenght).fill(true)
}

createui = () => { // reset on every file load
document.getElementById('sBody').innerHTML = data[0].map((_, i) => `
<tr>
<td> ${i + 1}. </td>
<td><input type="checkbox" class="sCheck" ${this.checks[i] ? 'checked' : ''}></td>
<td><input type="text" class="sFormat" value=${this.formats[i]}></td>
</tr>
`).join('')
$('#popAdSv').show()
document.getElementById('popSv').addEventListener('click', () => {
try {
this.getchecks()
this.getformat()
} catch (error) {
alertElec("Invalid write format")
}
$('#popAdSv').hide()
})
}

getchecks = () => {
var ts = $('tBody input:checkbox')
for (let i = 0; i < ts.length; i++) this.checks[i] = ts[i].checked ;
}

getformat = () => {
var ts = $('tBody input:text')
for (let i = 0; i < ts.length; i++) this.formats[i] = ts[i].value ;
}
}

const saveProp = new SaveProperties()
3 changes: 3 additions & 0 deletions src/js/keyIpcTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ function ipcTrigger(_, d) {
} else if (d == 'save' && !firstSave) {
saveData()

} else if (d == 'savepref') {
saveProp.createui()

} else if (d == '3dview') {
viewer3D.open()
analytics.add('3Dviewer')
Expand Down

0 comments on commit f502ffe

Please sign in to comment.