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
769bf50f
You need to sign in or sign up before continuing.
Commit
769bf50f
authored
Jan 10, 2025
by
Almouhannad Hafez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add chart abstract class
parent
a8832ae2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
0 deletions
+101
-0
chart.ts
src/ts/chart.ts
+83
-0
chartConfiguration.ts
src/ts/chartConfiguration.ts
+17
-0
tsconfig.json
tsconfig.json
+1
-0
No files found.
src/ts/chart.ts
0 → 100644
View file @
769bf50f
import
*
as
d3
from
'd3'
;
import
{
ChartConfiguration
}
from
'./chartConfiguration'
;
export
abstract
class
Chart
{
protected
config
:
{
parentSVGElement
:
string
;
containerWidth
:
number
;
containerHeight
:
number
;
margin
:
{
top
:
number
;
right
:
number
;
bottom
:
number
;
left
:
number
;
};
};
protected
data
:
any
[];
protected
width
:
number
;
protected
height
:
number
;
protected
svg
:
d3
.
Selection
<
d3
.
BaseType
,
unknown
,
HTMLElement
,
any
>
;
protected
chart
:
any
;
/**
* Class constructor with basic chart configuration
*/
constructor
(
_config
:
ChartConfiguration
,
_data
:
any
[])
{
const
vis
=
this
;
// Configuration object with defaults
const
{
width
,
height
}
=
_config
.
containerSize
||
vis
.
getDefaultContainerSize
();
vis
.
config
=
{
parentSVGElement
:
_config
.
parentSVGElement
,
containerWidth
:
width
,
containerHeight
:
height
,
margin
:
_config
.
margin
||
vis
.
getDefaultMargins
()
};
vis
.
data
=
_data
;
vis
.
initChart
();
}
/**
* Returns default margin values.
*/
protected
abstract
getDefaultMargins
():
{
top
:
number
;
right
:
number
;
bottom
:
number
;
left
:
number
};
/**
* Returns default container size (width and height).
*/
protected
abstract
getDefaultContainerSize
():
{
width
:
number
;
height
:
number
};
/**
* Initialize chart element.
*/
private
initChart
()
{
const
vis
=
this
;
// Calculate inner chart size.
vis
.
width
=
vis
.
config
.
containerWidth
-
vis
.
config
.
margin
.
left
-
vis
.
config
.
margin
.
right
;
vis
.
height
=
vis
.
config
.
containerHeight
-
vis
.
config
.
margin
.
top
-
vis
.
config
.
margin
.
bottom
;
// Define size of SVG drawing area
vis
.
svg
=
d3
.
select
(
vis
.
config
.
parentSVGElement
)
.
attr
(
'width'
,
vis
.
config
.
containerWidth
)
.
attr
(
'height'
,
vis
.
config
.
containerHeight
);
// Append group element that will contain our actual chart
// and position it according to the given margin config
vis
.
chart
=
vis
.
svg
.
append
(
'g'
)
.
attr
(
'transform'
,
`translate(
${
vis
.
config
.
margin
.
left
}
,
${
vis
.
config
.
margin
.
top
}
)`
);
}
/**
* Initialize scales/axes and append static elements, such as axis titles.
*/
protected
abstract
initVis
():
void
;
/**
* This function contains the D3 code for binding data to visual elements.
* We call this function every time the data or configurations change.
*/
protected
abstract
renderVis
():
void
;
/**
* This function contains all the code to prepare the data before we render it.
*/
public
abstract
updateVis
():
void
;
}
\ No newline at end of file
src/ts/chartConfiguration.ts
0 → 100644
View file @
769bf50f
export
class
ChartConfiguration
{
/**
* parentSVGElement
*/
public
parentSVGElement
:
string
;
public
containerSize
?:
{
width
:
number
;
height
:
number
};
public
margin
?:
{
top
:
number
;
right
:
number
;
bottom
:
number
;
left
:
number
};
constructor
(
parentSVGElement
:
string
,
containerSize
?:
{
width
:
number
;
height
:
number
},
margin
?:
{
top
:
number
;
right
:
number
;
bottom
:
number
;
left
:
number
})
{
this
.
parentSVGElement
=
parentSVGElement
;
this
.
containerSize
=
containerSize
;
this
.
margin
=
margin
;
}
}
\ No newline at end of file
tsconfig.json
View file @
769bf50f
...
...
@@ -17,6 +17,7 @@
"noEmit"
:
true
,
/*
Linting
*/
"strict"
:
true
,
"strictPropertyInitialization"
:
false
,
"noUnusedLocals"
:
true
,
"noUnusedParameters"
:
true
,
"noFallthroughCasesInSwitch"
:
true
,
...
...
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