Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
See what's new at GitLab
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
T
Telegram chart contest
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vasily Belolapotkov
Telegram chart contest
Commits
94cc2964
Commit
94cc2964
authored
Mar 23, 2019
by
Vasily Belolapotkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: cleanup chart component
parent
ac2125c5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
16 deletions
+32
-16
src/chart-components/chart.ts
src/chart-components/chart.ts
+32
-16
No files found.
src/chart-components/chart.ts
View file @
94cc2964
...
...
@@ -7,10 +7,13 @@ import { makeLegend } from './legend';
import
{
makeHtmlElement
}
from
'
../utils/ui
'
;
import
{
makeChartStateController
}
from
'
./chart-state-controller
'
;
export
function
makeChart
(
chartData
:
IChartData
):
IChartComponent
<
any
>
{
export
function
makeChart
(
chartData
:
IChartData
):
IChartComponent
<
null
>
{
const
chartState
=
makeChartState
(
chartData
);
const
chartStateController
=
makeChartStateController
(
chartState
);
const
chartAspectRatio
=
4
/
3
;
const
previewAspectRatio
=
5
;
let
chartContainer
:
HTMLElement
;
let
plotHeight
:
number
;
let
plotWidth
:
number
;
let
previewHeight
:
number
;
...
...
@@ -20,21 +23,16 @@ export function makeChart(chartData: IChartData): IChartComponent<any> {
});
function
render
(
container
:
HTMLElement
):
void
{
const
chartContainer
=
makeChartContainer
();
renderChartContainer
(
container
);
renderPlotArea
();
renderPreview
();
renderLegend
();
}
function
renderChartContainer
(
container
:
HTMLElement
)
{
chartContainer
=
makeChartContainer
();
container
.
appendChild
(
chartContainer
);
initSizeProps
(
chartContainer
);
const
plotArea
=
makePlotArea
(
chartStateController
);
plotArea
.
render
(
chartContainer
,
{
plotWidth
,
plotHeight
});
const
chartPreview
=
makeChartPreview
(
chartStateController
);
chartPreview
.
render
(
chartContainer
,
{
width
:
plotWidth
,
height
:
previewHeight
,
});
const
legend
=
makeLegend
(
chartStateController
);
legend
.
render
(
chartContainer
);
}
function
makeChartContainer
():
HTMLElement
{
...
...
@@ -45,7 +43,25 @@ export function makeChart(chartData: IChartData): IChartComponent<any> {
function
initSizeProps
(
chartContainer
:
HTMLElement
):
void
{
plotWidth
=
chartContainer
.
offsetWidth
;
plotHeight
=
Math
.
round
(
0.75
*
plotWidth
);
previewHeight
=
Math
.
round
(
plotHeight
/
5
);
plotHeight
=
Math
.
round
(
plotWidth
/
chartAspectRatio
);
previewHeight
=
Math
.
round
(
plotHeight
/
previewAspectRatio
);
}
function
renderPlotArea
()
{
const
plotArea
=
makePlotArea
(
chartStateController
);
plotArea
.
render
(
chartContainer
,
{
plotWidth
,
plotHeight
});
}
function
renderPreview
()
{
const
preview
=
makeChartPreview
(
chartStateController
);
preview
.
render
(
chartContainer
,
{
width
:
plotWidth
,
height
:
previewHeight
,
});
}
function
renderLegend
()
{
const
legend
=
makeLegend
(
chartStateController
);
legend
.
render
(
chartContainer
);
}
}
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