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
ff67c421
Commit
ff67c421
authored
9 years ago
by
Tom Robinson
Browse files
Options
Downloads
Patches
Plain Diff
New split axis logic
parent
b800489e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/src/visualizations/lib/utils.js
+36
-39
36 additions, 39 deletions
frontend/src/visualizations/lib/utils.js
with
36 additions
and
39 deletions
frontend/src/visualizations/lib/utils.js
+
36
−
39
View file @
ff67c421
import
_
from
"
underscore
"
;
import
d3
from
"
d3
"
;
import
*
as
colors
from
"
metabase/lib/colors
"
;
const
SPLIT_AXIS_UNSPLIT_COST
=
-
100
;
const
SPLIT_AXIS_COST_FACTOR
=
2
;
// computed size properties (drop 'px' and convert string -> Number)
function
getComputedSizeProperty
(
prop
,
element
)
{
var
val
=
document
.
defaultView
.
getComputedStyle
(
element
,
null
).
getPropertyValue
(
prop
);
...
...
@@ -30,50 +34,43 @@ export function getAvailableCanvasWidth(element) {
return
parentWidth
-
parentPaddingLeft
-
parentPaddingRight
;
}
export
function
computeSplit
(
extents
)
{
// copy and sort the intervals by the lower bound
let
intervals
=
extents
.
map
(
e
=>
e
.
slice
()).
sort
((
a
,
b
)
=>
a
[
0
]
-
b
[
0
]);
// start with a zero width gap
let
gap
=
[
0
,
0
];
// iterate over each interval
let
current
=
intervals
[
0
];
for
(
let
i
=
1
;
i
<
intervals
.
length
;
i
++
)
{
let
next
=
intervals
[
i
];
// merge next interval with the current one if appropriate
if
(
next
[
0
]
<=
current
[
1
])
{
if
(
next
[
1
]
>
current
[
1
])
{
current
[
1
]
=
next
[
1
];
}
// otheriwse update the gap if it's larger than the previously recorded gap
}
else
{
if
(
next
[
0
]
-
current
[
1
]
>
gap
[
1
]
-
gap
[
0
])
{
gap
=
[
current
[
1
],
next
[
0
]];
}
current
=
next
;
}
function
generateSplits
(
list
,
left
=
[],
right
=
[])
{
// NOTE: currently generates all permutations, some of which are equivalent
if
(
list
.
length
===
0
)
{
return
[[
left
,
right
]];
}
else
{
return
[
...
generateSplits
(
list
.
slice
(
1
),
left
.
concat
([
list
[
0
]]),
right
),
...
generateSplits
(
list
.
slice
(
1
),
left
,
right
.
concat
([
list
[
0
]]))
];
}
}
let
partitionIndexes
;
// if there is a gap, and it's larger than an order of magnitude, then split
if
(
gap
[
1
]
-
gap
[
0
]
!==
0
&&
(
gap
[
1
]
/
gap
[
0
])
>=
10
)
{
partitionIndexes
=
[[],[]];
extents
.
forEach
(([
min
,
max
],
index
)
=>
{
// if the end of an extent is less or equal to than the beginning of the gap
// put it in the lower partition
if
(
max
<=
gap
[
0
])
{
partitionIndexes
[
0
].
push
(
index
);
}
else
{
partitionIndexes
[
1
].
push
(
index
);
}
})
// otherwise don't partition
function
cost
(
seriesExtents
)
{
let
axisExtent
=
d3
.
extent
([].
concat
(...
seriesExtents
));
// concat to flatten the array
let
axisRange
=
axisExtent
[
1
]
-
axisExtent
[
0
];
if
(
seriesExtents
.
length
===
0
)
{
return
SPLIT_AXIS_UNSPLIT_COST
;
}
else
{
partitionIndexes
=
[
extents
.
map
((
e
,
i
)
=>
i
)];
return
seriesExtents
.
reduce
((
sum
,
seriesExtent
)
=>
sum
+
Math
.
pow
(
axisRange
/
(
seriesExtent
[
1
]
-
seriesExtent
[
0
]),
SPLIT_AXIS_COST_FACTOR
)
,
0
);
}
}
return
partitionIndexes
;
export
function
computeSplit
(
extents
)
{
let
best
=
null
;
let
bestCost
=
Infinity
;
let
splits
=
generateSplits
(
extents
.
map
((
e
,
i
)
=>
i
)).
map
(
split
=>
[
split
,
cost
(
split
[
0
].
map
(
i
=>
extents
[
i
]))
+
cost
(
split
[
1
].
map
(
i
=>
extents
[
i
]))]
)
for
(
let
[
split
,
splitCost
]
of
splits
)
{
if
(
splitCost
<
bestCost
)
{
best
=
split
;
bestCost
=
splitCost
;
}
}
return
best
.
sort
((
a
,
b
)
=>
a
[
0
]
-
b
[
0
]);
}
const
FRIENDLY_NAME_MAP
=
{
...
...
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