Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue 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
Engineering Digital Service
Metabase
Commits
4327bcea
Commit
4327bcea
authored
7 years ago
by
Tom Robinson
Browse files
Options
Downloads
Patches
Plain Diff
Add 70% height limit for rotated labels
parent
101e8dbb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/src/metabase/visualizations/lib/LineAreaBarPostRender.js
+40
-10
40 additions, 10 deletions
.../src/metabase/visualizations/lib/LineAreaBarPostRender.js
with
40 additions
and
10 deletions
frontend/src/metabase/visualizations/lib/LineAreaBarPostRender.js
+
40
−
10
View file @
4327bcea
...
...
@@ -4,9 +4,10 @@ import d3 from "d3";
import
{
clipPathReference
}
from
"
metabase/lib/dom
"
;
const
X_LABEL_MIN_SPACING
=
2
;
// minimum amount of space we want to leave between labels
const
X_LABEL_ROTATE_90_THRESHOLD
=
40
;
const
X_LABEL_HIDE_THRESHOLD
=
12
;
const
X_LABEL_MIN_SPACING
=
2
;
// minimum space we want to leave between labels
const
X_LABEL_ROTATE_90_THRESHOLD
=
24
;
// tick width breakpoint for switching from 45° to 90°
const
X_LABEL_HIDE_THRESHOLD
=
12
;
// tick width breakpoint for hiding labels entirely
const
X_LABEL_MAX_LABEL_HEIGHT_RATIO
=
0.7
;
// percent rotated labels are allowed to take
// +-------------------------------------------------------------------------------------------------------------------+
// | ON RENDER FUNCTIONS |
...
...
@@ -350,8 +351,7 @@ function computeMinHorizontalMargins(chart) {
return
min
;
}
function
computeXAxisMargin
(
chart
)
{
const
rotation
=
getXAxisRotation
(
chart
);
function
computeXAxisLabelMaxSize
(
chart
)
{
let
maxWidth
=
0
;
let
maxHeight
=
0
;
chart
.
selectAll
(
"
g.x text
"
).
each
(
function
()
{
...
...
@@ -359,9 +359,21 @@ function computeXAxisMargin(chart) {
maxWidth
=
Math
.
max
(
maxWidth
,
width
);
maxHeight
=
Math
.
max
(
maxHeight
,
height
);
});
const
rotatedMaxHeight
=
Math
.
sin
((
rotation
+
180
)
*
(
Math
.
PI
/
180
))
*
maxWidth
;
return
Math
.
max
(
0
,
rotatedMaxHeight
-
maxHeight
);
// subtract the existing height
return
{
width
:
maxWidth
,
height
:
maxHeight
};
}
function
rotateSize
(
size
,
rotation
)
{
return
{
width
:
Math
.
sin
(
rotation
*
(
Math
.
PI
/
180
))
*
size
.
width
,
height
:
Math
.
sin
(
rotation
*
(
Math
.
PI
/
180
))
*
size
.
height
,
};
}
function
computeXAxisMargin
(
chart
)
{
const
rotation
=
getXAxisRotation
(
chart
);
const
maxSize
=
computeXAxisLabelMaxSize
(
chart
);
const
rotatedMaxSize
=
rotateSize
(
maxSize
,
rotation
+
180
);
return
Math
.
max
(
0
,
rotatedMaxSize
.
width
-
maxSize
.
height
);
// subtract the existing height
}
function
checkLabelOverlap
(
chart
)
{
...
...
@@ -379,6 +391,16 @@ function checkLabelOverlap(chart) {
return
false
;
}
function
checkLabelHeight
(
chart
,
rotation
)
{
const
rotatedMaxSize
=
rotateSize
(
computeXAxisLabelMaxSize
(
chart
),
rotation
+
180
,
);
const
xAxisSize
=
chart
.
selectAll
(
"
g.y
"
)[
0
][
0
].
getBBox
();
const
ratio
=
Math
.
abs
(
rotatedMaxSize
.
width
)
/
xAxisSize
.
height
;
return
ratio
<
X_LABEL_MAX_LABEL_HEIGHT_RATIO
;
}
function
computeXAxisSpacing
(
chart
)
{
const
rects
=
[];
let
minXAxisSpacing
=
Infinity
;
...
...
@@ -405,9 +427,17 @@ function beforeRenderComputeXAxisLabelType(chart) {
if
(
spacing
<
X_LABEL_HIDE_THRESHOLD
)
{
chart
.
settings
[
"
graph.x_axis.axis_enabled
"
]
=
false
;
}
else
if
(
spacing
<
X_LABEL_ROTATE_90_THRESHOLD
)
{
chart
.
settings
[
"
graph.x_axis.axis_enabled
"
]
=
"
rotate-90
"
;
if
(
checkLabelHeight
(
chart
,
90
))
{
chart
.
settings
[
"
graph.x_axis.axis_enabled
"
]
=
"
rotate-90
"
;
}
else
{
chart
.
settings
[
"
graph.x_axis.axis_enabled
"
]
=
false
;
}
}
else
{
chart
.
settings
[
"
graph.x_axis.axis_enabled
"
]
=
"
rotate-45
"
;
if
(
checkLabelHeight
(
chart
,
45
))
{
chart
.
settings
[
"
graph.x_axis.axis_enabled
"
]
=
"
rotate-45
"
;
}
else
{
chart
.
settings
[
"
graph.x_axis.axis_enabled
"
]
=
false
;
}
}
}
else
{
chart
.
settings
[
"
graph.x_axis.axis_enabled
"
]
=
false
;
...
...
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