Skip to content

Commit 314f924

Browse files
committed
chore: improe example
1 parent c712833 commit 314f924

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

examples/data.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

examples/example.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ const peaks = [
1717
{ x: 0.1, y: 0.2, width: 0.1 },
1818
];
1919

20-
const original = generateSpectrum(peaks, { from: -1, to: 1, nbPoints: 101 });
20+
const from = -1;
21+
const to = 1;
22+
23+
const original = generateSpectrum(peaks, { from, to, nbPoints: 101 });
2124

2225
let peakList = gsd(original, {
2326
minMaxRatio: 0,
@@ -40,6 +43,7 @@ let lines = optimizedPeaks.map((peak) => [
4043
{ x: peak.x, y: peak.y },
4144
{ x: peak.x, y: peak.y, dy: '-20px' },
4245
]);
46+
4347
let polygons = [];
4448
for (const peak of optimizedPeaks) {
4549
const peaksSpectrum = generateSpectrum([peak], {
@@ -54,11 +58,19 @@ for (const peak of optimizedPeaks) {
5458
polygons.push(polygon);
5559
}
5660

61+
let reconstructed = generateSpectrum(optimizedPeaks, {
62+
from,
63+
to,
64+
nbPoints: 5001,
65+
});
66+
reconstructed.x = Array.from(reconstructed.x)
67+
reconstructed.y = Array.from(reconstructed.y)
68+
5769
original.x = Array.from(original.x);
5870
original.y = Array.from(original.y);
5971

6072
writeFileSync(
6173
join(__dirname, 'data.json'),
62-
JSON.stringify({ data: original, labels, lines, polygons }),
74+
JSON.stringify({ data: original, labels, lines, polygons, reconstructed }),
6375
'utf8',
6476
);

examples/index.html

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,23 @@ <h1>A spectrum-generator module usage example</h1>
7070
waveForm.setData(data.y, data.x);
7171

7272
graph
73-
.newSerie('line serie', {}, 'line') // Creates a new serie
73+
.newSerie('original', { lineColor: 'black', lineWidth: 1 }, 'line') // Creates a new serie
7474
.autoAxis() // Assigns axes
7575
.setWaveform(waveForm);
7676

77+
if (json.reconstructed) {
78+
let waveForm2 = Graph.newWaveform();
79+
waveForm2.setData(json.reconstructed.y, json.reconstructed.x);
80+
graph
81+
.newSerie(
82+
'reconstructed',
83+
{ lineColor: 'red', lineWidth: 2 },
84+
'line',
85+
) // Creates a new serie
86+
.autoAxis() // Assigns axes
87+
.setWaveform(waveForm2);
88+
}
89+
7790
if (json.labels) {
7891
for (let label of json.labels) {
7992
const shape = graph.newShape('label', {
@@ -111,8 +124,8 @@ <h1>A spectrum-generator module usage example</h1>
111124
false,
112125
{
113126
fillColor: colors[i % colors.length],
114-
fillOpacity: 0.15,
115-
strokeWidth: 1,
127+
fillOpacity: 0.1,
128+
strokeWidth: 0,
116129
strokeColor: colors[i % colors.length],
117130
},
118131
);

0 commit comments

Comments
 (0)