Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
D
DV-HW4
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
almohanad.hafez
DV-HW4
Commits
61556da8
Commit
61556da8
authored
Jan 10, 2025
by
Almouhannad Hafez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add filter by level to scatterplot
parent
3af71174
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
7 deletions
+40
-7
index.html
index.html
+4
-3
style.css
src/css/style.css
+5
-0
main.ts
src/ts/main.ts
+31
-4
No files found.
index.html
View file @
61556da8
...
...
@@ -11,9 +11,10 @@
<div
id=
"scatterplot-container"
>
<svg
id=
"scatterplot"
></svg>
<ul
class=
"legend"
id=
"scatterplot-legend"
>
<li><span
class=
"legend-e easy"
id=
"scatterplot-legend-easy"
></span>
Easy
</li>
<li><span
class=
"legend-e intermediate"
id=
"scatterplot-intermediate"
></span>
Intermediate
</li>
<li><span
class=
"legend-e difficult"
id=
"scatterplot-difficult"
></span>
Difficult
</li>
<p>
Filter by level:
</p>
<li
id=
"scatterplot-legend-Easy"
><span
class=
"legend-e easy"
></span>
Easy
</li>
<li
id=
"scatterplot-legend-Intermediate"
><span
class=
"legend-e intermediate"
></span>
Intermediate
</li>
<li
id=
"scatterplot-legend-Difficult"
><span
class=
"legend-e difficult"
></span>
Difficult
</li>
</ul>
</div>
<script
type=
"module"
src=
"/src/ts/main.ts"
></script>
...
...
src/css/style.css
View file @
61556da8
...
...
@@ -88,4 +88,9 @@ body {
background
:
#2a8d46
;
}
#scatterplot-container
p
{
font-weight
:
900
;
color
:
#2a8d46
;
}
/* #endregion */
\ No newline at end of file
src/ts/main.ts
View file @
61556da8
...
...
@@ -3,19 +3,46 @@ import { Scatterplot } from './scatter';
import
'/src/css/style.css'
;
import
*
as
d3
from
'd3'
;
const
selectedDifficulties
:
string
[]
=
[];
let
data
:
any
[]
=
[];
const
scatterplot
=
new
Scatterplot
(
new
ChartConfiguration
(
"#scatterplot"
));
function
handleLevelSelectionEvent
(
element
:
any
,
difficulty
:
string
)
{
const
index
=
selectedDifficulties
.
indexOf
(
difficulty
);
if
(
index
>
-
1
)
{
// Difficulty is in the array, remove it
selectedDifficulties
.
splice
(
index
,
1
);
d3
.
select
(
element
).
style
(
"opacity"
,
1
);
}
else
{
// Difficulty is not in the array, add it
selectedDifficulties
.
push
(
difficulty
);
d3
.
select
(
element
).
style
(
"opacity"
,
0.5
);
}
const
filteredData
=
data
.
filter
(
item
=>
!
selectedDifficulties
.
includes
(
item
.
difficulty
));
scatterplot
.
data
=
filteredData
;
scatterplot
.
updateVis
();
}
const
difficulties
=
[
"Easy"
,
"Intermediate"
,
"Difficult"
]
// Add click event listeners for each difficulty level
for
(
const
level
of
difficulties
)
{
const
id
=
`#scatterplot-legend-
${
level
}
`
d3
.
select
(
id
)
.
on
(
"click"
,
function
()
{
handleLevelSelectionEvent
(
this
,
level
);
});
}
/**
* Load data from CSV file asynchronously and render scatter plot
*/
const
scatterplot
=
new
Scatterplot
(
new
ChartConfiguration
(
"#scatterplot"
));
d3
.
csv
(
'/data/vancouver_trails.csv'
)
.
then
(
d
ata
=>
{
.
then
(
inputD
ata
=>
{
// Convert strings to numbers
d
ata
.
forEach
((
d
:
any
)
=>
{
inputD
ata
.
forEach
((
d
:
any
)
=>
{
d
.
time
=
+
d
.
time
;
d
.
distance
=
+
d
.
distance
;
});
data
=
inputData
;
// Initialize chart
scatterplot
.
data
=
d
ata
;
scatterplot
.
data
=
inputD
ata
;
// Show chart
scatterplot
.
updateVis
();
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment