Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cloud-3406140
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
cloud-3406140
Commits
f0ab6204
Commit
f0ab6204
authored
1 year ago
by
Masami Suzuki
Committed by
Yas Naoi
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3401036
by Masami, yas: Refactor to native JavaScript from jQuery (cloud_horizon_chart.js)
parent
3f843d4d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
js/cloud_horizon_chart.js
+52
-31
52 additions, 31 deletions
js/cloud_horizon_chart.js
with
52 additions
and
31 deletions
js/cloud_horizon_chart.js
+
52
−
31
View file @
f0ab6204
(
function
(
$
)
{
(
function
()
{
'
use strict
'
;
Drupal
.
Cloud
=
{};
window
.
Drupal
=
{};
window
.
Drupal
.
Cloud
=
{};
const
colors
=
[
[
'
#edf8e9
'
,
'
#bae4b3
'
,
'
#74c476
'
,
'
#31a354
'
,
'
#006d2c
'
],
...
...
@@ -17,18 +18,28 @@
const
BACKGROUND_DEFAULT_COLOR
=
'
rgba(0, 0, 0, 0)
'
;
// Draw Chart Function.
Drupal
.
Cloud
.
drawChart
=
function
(
data
,
first
)
{
window
.
Drupal
.
Cloud
.
drawChart
=
function
(
data
,
first
)
{
data
.
forEach
(
function
(
item
,
idx
)
{
// Delete current chart.
d3
.
select
(
item
.
selector
).
select
(
'
svg
'
).
remove
();
if
(
document
.
querySelector
(
item
.
selector
))
{
document
.
querySelector
(
item
.
selector
).
innerHTML
=
''
;
}
// Draw charts.
if
(
first
&&
idx
===
0
)
{
// Delete the axis.
d3
.
select
(
'
#x-axis
'
).
remove
();
const
xAxis
=
document
.
querySelector
(
'
#x-axis
'
);
if
(
xAxis
&&
xAxis
.
parentNode
)
{
xAxis
.
parentNode
.
removeChild
(
xAxis
);
}
// Add <div> for the axis.
$
(
item
.
selector
).
before
(
'
<div id="x-axis"></div>
'
);
const
xAxisDiv
=
document
.
createElement
(
'
div
'
);
xAxisDiv
.
id
=
'
x-axis
'
;
const
chartContainer
=
document
.
querySelector
(
item
.
selector
);
if
(
chartContainer
&&
chartContainer
.
parentNode
)
{
chartContainer
.
parentNode
.
insertBefore
(
xAxisDiv
,
chartContainer
);
}
// Draw charts.
const
axis
=
new
HorizonChart
();
...
...
@@ -37,25 +48,32 @@
axis
.
setSelector
(
'
#x-axis
'
);
axis
.
draw
();
const
chartg
=
d3
.
selectAll
(
'
#x-axis g:first-child
'
);
chartg
.
style
(
'
display
'
,
'
none
'
);
const
axisg
=
d3
.
selectAll
(
'
#x-axis .axis
'
);
axisg
.
attr
(
'
font-size
'
,
AXIS_FONT_SIZE
);
const
chartg
=
document
.
querySelectorAll
(
'
#x-axis g:first-child
'
);
if
(
chartg
&&
chartg
.
style
)
{
chartg
.
style
.
display
=
'
none
'
;
}
const
axisg
=
document
.
querySelectorAll
(
'
#x-axis .axis
'
);
if
(
axis
&&
axisg
.
style
)
{
axisg
.
style
.
fontSize
=
AXIS_FONT_SIZE
;
}
}
// Draw charts.
const
horizonChart
=
new
HorizonChart
();
const
fontColor
=
$
(
item
.
selector
).
css
(
'
color
'
)
;
const
fontColor
=
window
.
getComputedStyle
(
document
.
querySelector
(
item
.
selector
)
)
.
color
;
let
bgColor
=
''
;
$
(
item
.
selector
).
parents
().
each
(
function
()
{
console
.
log
(
getComputedStyle
(
this
).
backgroundColor
);
let
color
=
getComputedStyle
(
this
).
backgroundColor
;
if
(
color
&&
color
!==
BACKGROUND_DEFAULT_COLOR
)
{
bgColor
=
color
;
return
false
;
let
parents
=
document
.
querySelectorAll
(
item
.
selector
).
parents
;
if
(
parents
)
{
for
(
let
i
=
0
;
i
<
parents
.
length
;
i
++
)
{
console
.
log
(
window
.
getComputedStyle
(
parents
[
i
]).
backgroundColor
);
let
color
=
window
.
getComputedStyle
(
parents
[
i
]).
backgroundColor
;
if
(
color
&&
color
!==
BACKGROUND_DEFAULT_COLOR
)
{
bgColor
=
color
;
break
;
}
}
}
);
}
horizonChart
.
setTitle
(
item
.
id
);
horizonChart
.
setTitleFontSize
(
TITLE_FONT_SIZE
);
horizonChart
.
setTitlePosition
(
TITLE_POSITION_X
,
TITLE_POSITION_Y
);
...
...
@@ -67,23 +85,26 @@
horizonChart
.
setShowXScale
(
false
);
horizonChart
.
draw
();
const
g
=
d
3
.
s
electAll
(
item
.
selector
+
'
svg g
'
);
const
title
=
d
3
.
s
electAll
(
item
.
selector
+
'
svg text
'
);
const
bbox
=
$
(
item
.
selector
+
'
svg text
'
)[
0
].
getBBox
();
const
g
=
d
ocument
.
queryS
elect
or
All
(
item
.
selector
+
'
svg g
'
);
const
title
=
d
ocument
.
queryS
elect
or
All
(
item
.
selector
+
'
svg text
'
);
const
bbox
=
document
.
querySelectorAll
(
item
.
selector
+
'
svg text
'
)[
0
].
getBBox
();
g
.
insert
(
'
rect
'
,
item
.
selector
+
'
svg text
'
)
.
attr
(
'
x
'
,
bbox
.
x
-
1
)
.
attr
(
'
y
'
,
bbox
.
y
)
.
attr
(
'
width
'
,
bbox
.
width
+
2
)
.
attr
(
'
height
'
,
bbox
.
height
)
.
attr
(
'
fill
'
,
bgColor
)
.
style
(
'
opacity
'
,
'
0.8
'
);
const
rect
=
document
.
createElement
(
'
rect
'
);
rect
.
setAttribute
(
'
x
'
,
bbox
.
x
-
1
);
rect
.
setAttribute
(
'
y
'
,
bbox
.
y
);
rect
.
setAttribute
(
'
width
'
,
bbox
.
width
+
2
);
rect
.
setAttribute
(
'
height
'
,
bbox
.
height
);
rect
.
setAttribute
(
'
fill
'
,
bgColor
);
rect
.
style
.
opacity
=
'
0.8
'
;
if
(
g
)
{
g
.
insertBefore
(
rect
,
item
.
selector
+
'
svg text
'
);
}
$
(
item
.
selector
).
css
(
'
margin
-b
ottom
'
,
'
0
'
)
;
document
.
querySelector
(
item
.
selector
).
style
.
margin
B
ottom
=
'
0
'
;
if
(
!
first
||
idx
>
0
)
{
$
(
item
.
selector
).
css
(
'
border-top
'
,
'
1px solid #ddd
'
)
;
document
.
querySelector
(
item
.
selector
).
style
.
borderTop
=
'
1px solid #ddd
'
;
}
});
};
})(
jQuery
);
})();
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment