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
c7e010c1
Commit
c7e010c1
authored
9 years ago
by
Allen Gilliland
Browse files
Options
Downloads
Patches
Plain Diff
update pivot calculation.
parent
5faaf857
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
resources/frontend_client/app/lib/data_grid.js
+41
-34
41 additions, 34 deletions
resources/frontend_client/app/lib/data_grid.js
with
41 additions
and
34 deletions
resources/frontend_client/app/lib/data_grid.js
+
41
−
34
View file @
c7e010c1
...
...
@@ -7,60 +7,67 @@ var DataGrid = {
// find the lowest cardinality dimension and make it our "pivoted" column
// TODO: we assume dimensions are in the first 2 columns, which is less than ideal
var
pivotCol
=
0
,
normalCol
=
1
,
pivotColValues
=
DataGrid
.
distinctValues
(
data
,
pivotCol
);
if
(
DataGrid
.
cardinality
(
data
,
1
)
<=
pivotColValues
.
length
)
{
pivotCol
=
1
;
normalCol
=
0
;
pivotColValues
=
DataGrid
.
distinctValues
(
data
,
pivotCol
);
normalCol
=
1
,
pivotColValues
=
DataGrid
.
distinctValues
(
data
,
pivotCol
),
normalColValues
=
DataGrid
.
distinctValues
(
data
,
normalCol
);
if
(
normalColValues
.
length
<=
pivotColValues
.
length
)
{
pivotCol
=
1
;
normalCol
=
0
;
var
tmp
=
pivotColValues
;
pivotColValues
=
normalColValues
;
normalColValues
=
tmp
;
}
// sort the
pivot
column values sensibly
// sort the column values sensibly
pivotColValues
.
sort
();
pivot
ColValues
.
unshift
(
null
);
normal
ColValues
.
sort
(
);
// build the pivoted data grid
var
values
=
data
.
rows
.
reduce
(
function
(
last
,
now
)
{
// grab the last "row" from the total dataset (if possible)
var
row
=
(
last
.
length
>
0
)
?
last
[
last
.
length
-
1
]
:
null
;
if
(
row
===
null
||
row
[
0
]
!==
now
[
normalCol
])
{
row
=
Array
.
apply
(
null
,
Array
(
pivotColValues
.
length
)).
map
(
function
()
{
return
null
;
});
row
[
0
]
=
now
[
normalCol
];
last
.
push
(
row
);
}
// make sure that the first element in the pivoted column list is null which makes room for the label of the other column
pivotColValues
.
unshift
(
null
);
// put current value into the result at the correct pivoted index
// TODO: we are hard coding to the 3rd value here, assuming that is always the metric :/
row
[
pivotColValues
.
lastIndexOf
(
now
[
pivotCol
])]
=
now
[
2
];
// start with an empty grid that we'll fill with the appropriate values
var
pivotedRows
=
[];
var
emptyRow
=
Array
.
apply
(
null
,
Array
(
pivotColValues
.
length
)).
map
(
function
()
{
return
null
;
});
for
(
var
i
=
0
;
i
<
normalColValues
.
length
;
i
++
)
{
pivotedRows
.
push
(
_
.
clone
(
emptyRow
));
}
return
last
;
// fill it up with the data
for
(
var
j
=
0
;
j
<
data
.
rows
.
length
;
j
++
)
{
var
normalColIdx
=
normalColValues
.
lastIndexOf
(
data
.
rows
[
j
][
normalCol
]);
var
pivotColIdx
=
pivotColValues
.
lastIndexOf
(
data
.
rows
[
j
][
pivotCol
]);
},
[]);
pivotedRows
[
normalColIdx
][
0
]
=
data
.
rows
[
j
][
normalCol
];
// NOTE: we are hard coding the expectation that the metric is in the 3rd column
pivotedRows
[
normalColIdx
][
pivotColIdx
]
=
data
.
rows
[
j
][
2
];
}
// provide some column metadata to maintain consistency
var
cols
=
pivotColValues
.
map
(
function
(
val
)
{
var
colDef
=
_
.
clone
(
data
.
cols
[
pivotCol
]);
colDef
[
'
display_name
'
]
=
val
||
""
;
colDef
[
'
name
'
]
=
val
||
""
;
return
colDef
;
var
colDef
=
_
.
clone
(
data
.
cols
[
pivotCol
]);
colDef
[
'
display_name
'
]
=
val
||
""
;
colDef
[
'
name
'
]
=
val
||
""
;
return
colDef
;
});
return
{
cols
:
cols
,
columns
:
pivotColValues
,
rows
:
value
s
cols
:
cols
,
columns
:
pivotColValues
,
rows
:
pivotedRow
s
};
},
distinctValues
:
function
(
data
,
colIdx
)
{
var
vals
=
data
.
rows
.
map
(
function
(
r
)
{
return
r
[
colIdx
];
});
var
vals
=
data
.
rows
.
map
(
function
(
r
)
{
return
r
[
colIdx
];
});
return
vals
.
filter
(
function
(
v
,
i
)
{
return
i
==
vals
.
lastIndexOf
(
v
);
});
return
vals
.
filter
(
function
(
v
,
i
)
{
return
i
==
vals
.
lastIndexOf
(
v
);
});
},
cardinality
:
function
(
data
,
colIdx
)
{
return
DataGrid
.
distinctValues
(
data
,
colIdx
).
length
;
return
DataGrid
.
distinctValues
(
data
,
colIdx
).
length
;
}
};
...
...
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