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
88f5d2aa
Commit
88f5d2aa
authored
Jan 10, 2025
by
Almouhannad Hafez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename area to line
parent
631d4972
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
57 deletions
+57
-57
index.html
index.html
+1
-1
lineChart.ts
src/ts/lineChart.ts
+2
-2
main.ts
src/ts/main.ts
+54
-54
No files found.
index.html
View file @
88f5d2aa
...
...
@@ -9,7 +9,7 @@
<body>
<div
id=
"scatterplot-container"
style=
"display: none;"
>
<div
id=
"scatterplot-container"
>
<div
id=
"scatterplot-tooltip"
></div>
<svg
id=
"scatterplot"
></svg>
<ul
class=
"legend"
id=
"scatterplot-legend"
>
...
...
src/ts/lineChart.ts
View file @
88f5d2aa
...
...
@@ -2,7 +2,7 @@ import * as d3 from 'd3';
import
{
Chart
}
from
"./chart"
;
import
{
ChartConfiguration
}
from
"./chartConfiguration"
;
export
class
Area
Chart
extends
Chart
{
export
class
Line
Chart
extends
Chart
{
private
xScale
:
any
;
private
yScale
:
any
;
private
xAxis
:
any
;
...
...
@@ -117,7 +117,7 @@ export class AreaChart extends Chart {
.
duration
(
1000
)
.
call
(
vis
.
yAxis
);
//
Create a transparent tracking area
//
add a transparent tracking space
vis
.
chart
.
append
(
'rect'
)
.
attr
(
'width'
,
vis
.
width
)
.
attr
(
'height'
,
vis
.
height
)
...
...
src/ts/main.ts
View file @
88f5d2aa
import
{
ChartConfiguration
}
from
'./chartConfiguration'
;
import
{
Area
Chart
}
from
'./lineChart'
;
import
{
Line
Chart
}
from
'./lineChart'
;
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
//
*/
//
d3.csv('/data/vancouver_trails.csv')
//
.then(inputData => {
//
// Convert strings to numbers
//
inputData.forEach((d: any) => {
//
d.time = +d.time;
//
d.distance = +d.distance;
//
});
//
data = inputData;
//
// Initialize chart
//
scatterplot.data = inputData;
//
// Show chart
//
scatterplot.updateVis();
//
})
//
.catch(error => console.error(error));
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
*/
d3
.
csv
(
'/data/vancouver_trails.csv'
)
.
then
(
inputData
=>
{
// Convert strings to numbers
inputData
.
forEach
((
d
:
any
)
=>
{
d
.
time
=
+
d
.
time
;
d
.
distance
=
+
d
.
distance
;
});
data
=
inputData
;
// Initialize chart
scatterplot
.
data
=
inputData
;
// Show chart
scatterplot
.
updateVis
();
})
.
catch
(
error
=>
console
.
error
(
error
));
/**
* Load data from CSV file asynchronously and render scatter plot
*/
const
areaChart
=
new
Area
Chart
(
new
ChartConfiguration
(
"#line-chart"
));
let
area
ChartData
:
any
[];
const
lineChart
=
new
Line
Chart
(
new
ChartConfiguration
(
"#line-chart"
));
let
line
ChartData
:
any
[];
d3
.
select
(
'#line-chart-year-input'
)
.
on
(
'input'
,
function
()
{
// Get the current value of the input
let
value
=
d3
.
select
(
this
).
property
(
'value'
);
value
=
+
value
;
console
.
log
(
area
ChartData
[
0
].
date
);
const
areaChartFilteredData
=
area
ChartData
.
filter
(
item
=>
item
.
date
.
getFullYear
()
>=
value
);
areaChart
.
data
=
area
ChartFilteredData
;
area
Chart
.
updateVis
();
console
.
log
(
line
ChartData
[
0
].
date
);
const
lineChartFilteredData
=
line
ChartData
.
filter
(
item
=>
item
.
date
.
getFullYear
()
>=
value
);
lineChart
.
data
=
line
ChartFilteredData
;
line
Chart
.
updateVis
();
});
...
...
@@ -76,8 +76,8 @@ d3.csv('/data/sp_500_index.csv')
d
.
close
=
+
d
.
close
;
});
area
ChartData
=
inputData
;
area
Chart
.
data
=
inputData
;
area
Chart
.
updateVis
();
line
ChartData
=
inputData
;
line
Chart
.
data
=
inputData
;
line
Chart
.
updateVis
();
})
.
catch
(
error
=>
console
.
error
(
error
));
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