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
910afcec
Unverified
Commit
910afcec
authored
2 years ago
by
adam-james
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix condtional to properly render multi-line charts in static-viz (#25216)
parent
f3e0dbbb
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/pulse/render.clj
+12
-18
12 additions, 18 deletions
src/metabase/pulse/render.clj
test/metabase/pulse/render_test.clj
+80
-74
80 additions, 74 deletions
test/metabase/pulse/render_test.clj
with
92 additions
and
92 deletions
src/metabase/pulse/render.clj
+
12
−
18
View file @
910afcec
...
...
@@ -85,17 +85,9 @@
(
#
{
:pin_map
:state
:country
}
display-type
)
(
chart-type
nil
"display-type is %s"
display-type
)
(
#
{
:area
:bar
:combo
:funnel
:progress
:table
:waterfall
}
display-type
)
(
chart-type
display-type
"display-type is %s"
display-type
)
;; for scalar/smartscalar, the display-type might actually be :line, so we can't have line above
(
=
@
col-sample-count
@
row-sample-count
1
)
(
and
(
not=
display-type
:progress
)
(
=
@
col-sample-count
@
row-sample-count
1
))
(
chart-type
:scalar
"result has one row and one column"
)
(
and
(
=
display-type
:smartscalar
)
...
...
@@ -103,19 +95,21 @@
(
seq
insights
))
(
chart-type
:smartscalar
"result has two columns and insights"
)
(
#
{
:line
:area
:bar
:combo
:funnel
:progress
:table
:waterfall
}
display-type
)
(
chart-type
display-type
"display-type is %s"
display-type
)
(
and
(
some?
maybe-dashcard
)
(
>
(
count
(
dashboard-card/dashcard->multi-cards
maybe-dashcard
))
0
)
(
not
(
#
{
:combo
}
display-type
)))
(
chart-type
:multiple
"result has multiple card semantics, a multiple chart"
)
;; we have to check when display-type is :line that there are enough rows/cols to actually create a line chart
;; if there is only 1 row and 1 col, the chart should be considered scalar, actually.
(
and
(
=
@
col-sample-count
2
)
(
>
@
row-sample-count
1
)
(
number-field?
@
col-2
)
(
not
(
#
{
:waterfall
:pie
:table
:area
}
display-type
)))
(
chart-type
:line
"result has 2 cols (%s and %s (number)) and > 1 row"
(
col-description
@
col-1
)
(
col-description
@
col-2
))
(
and
(
=
@
col-sample-count
2
)
(
number-field?
@
col-2
)
(
=
display-type
:pie
))
...
...
This diff is collapsed.
Click to expand it.
test/metabase/pulse/render_test.clj
+
80
−
74
View file @
910afcec
...
...
@@ -38,81 +38,87 @@
"There was a problem with this question."
))))
(
deftest
detect-pulse-chart-type-test
(
is
(
=
:scalar
(
render/detect-pulse-chart-type
{
:display
:anything
}
{}
{
:cols
[{
:base_type
:type/Number
}]
:rows
[[
6
]]})))
(
is
(
=
:smartscalar
(
render/detect-pulse-chart-type
{
:display
:smartscalar
}
{}
{
:cols
[{
:base_type
:type/Temporal
:name
"month"
}
{
:base_type
:type/Number
:name
"apples"
}]
:rows
[[
#
t
"2020"
2
]
[
#
t
"2021"
3
]]
:insights
[{
:name
"apples"
:last-value
3
:previous-value
2
:last-change
50.0
}]})))
(
is
(
=
:bar
(
render/detect-pulse-chart-type
{
:display
:bar
}
{}
{
:cols
[{
:base_type
:type/Text
}
{
:base_type
:type/Number
}]
:rows
[[
"A"
2
]]})))
(
is
(
=
:combo
(
render/detect-pulse-chart-type
{
:display
:combo
}
{}
{
:cols
[{
:base_type
:type/Temporal
}
{
:base_type
:type/Number
}]
:rows
[[
#
t
"2020"
2
]
[
#
t
"2021"
3
]]})))
(
is
(
=
:multiple
(
mt/with-temp*
[
Card
[
card1
{
:display
:something
}]
Card
[
card2
{
:display
:whatever
}]
Dashboard
[
dashboard
]
DashboardCard
[
dc1
{
:dashboard_id
(
u/the-id
dashboard
)
:card_id
(
u/the-id
card1
)}]
DashboardCardSeries
[
_
{
:dashboardcard_id
(
u/the-id
dc1
)
:card_id
(
u/the-id
card2
)}]]
(
render/detect-pulse-chart-type
card1
dc1
{
:cols
[{
:base_type
:type/Temporal
}
(
testing
"Currently unsupported chart types for static-viz return `nil`."
(
is
(
=
[
nil
nil
nil
]
(
map
#
(
render/detect-pulse-chart-type
{
:display
%
}
{}
{
:cols
[{
:base_type
:type/Number
}]
:rows
[[
2
]]})
[
:pin_map
:state
:country
]))))
(
testing
"Queries resulting in no rows return `:empty`."
(
is
(
=
:empty
(
render/detect-pulse-chart-type
{
:display
:line
}
{}
{
:cols
[{
:base_type
:type/Number
}]
:rows
[[
nil
]]}))))
(
testing
"Unrecognized display-types with otherwise valid results return `:table`."
(
is
(
=
:table
(
render/detect-pulse-chart-type
{
:display
:unrecognized
}
{}
{
:cols
[{
:base_type
:type/Text
}
{
:base_type
:type/Number
}]
:rows
[[
#
t
"2020"
2
]
[
#
t
"2021"
3
]]}))))
(
is
(
=
:funnel
(
render/detect-pulse-chart-type
{
:display
:funnel
}
{}
{
:cols
[{
:base_type
:type/Text
}
{
:base_type
:type/Number
}]
:rows
[[
"A"
2
]]})))
;; timeseries line chart
(
is
(
=
:line
(
render/detect-pulse-chart-type
{
:display
:line
}
{}
{
:cols
[{
:base_type
:type/Temporal
}
{
:base_type
:type/Number
}]
:rows
[[
#
t
"2020"
2
]
[
#
t
"2021"
3
]]})))
;; Category line chart
(
is
(
=
:line
(
render/detect-pulse-chart-type
{
:display
:line
}
{}
{
:cols
[{
:base_type
:type/Text
}
{
:base_type
:type/Number
}]
:rows
[[
"Red"
2
]
[
"Blue"
3
]]})))
(
is
(
=
:categorical/donut
(
render/detect-pulse-chart-type
{
:display
:pie
}
{}
{
:cols
[{
:base_type
:type/Text
}
{
:base_type
:type/Number
}]
:rows
[[
"apple"
3
]
[
"banana"
4
]]}))))
:rows
[[
"A"
2
]
[
"B"
4
]]}))))
(
testing
"Scalar and Smartscalar charts are correctly identified"
(
is
(
=
:scalar
(
render/detect-pulse-chart-type
{
:display
:line
}
{}
{
:cols
[{
:base_type
:type/Number
}]
:rows
[[
3
]]})))
(
is
(
=
:scalar
(
render/detect-pulse-chart-type
{
:display
:scalar
}
{}
{
:cols
[{
:base_type
:type/Number
}]
:rows
[[
6
]]})))
(
is
(
=
:smartscalar
(
render/detect-pulse-chart-type
{
:display
:smartscalar
}
{}
{
:cols
[{
:base_type
:type/Temporal
:name
"month"
}
{
:base_type
:type/Number
:name
"apples"
}]
:rows
[[
#
t
"2020"
2
]
[
#
t
"2021"
3
]]
:insights
[{
:name
"apples"
:last-value
3
:previous-value
2
:last-change
50.0
}]}))))
(
testing
"Progress charts are correctly identified"
(
is
(
=
:progress
(
render/detect-pulse-chart-type
{
:display
:progress
}
{}
{
:cols
[{
:base_type
:type/Number
}]
:rows
[[
6
]]}))))
(
testing
"Various Single-Series display-types return correct chart-types."
(
mapv
#
(
is
(
=
%
(
render/detect-pulse-chart-type
{
:display
%
}
{}
{
:cols
[{
:base_type
:type/Text
}
{
:base_type
:type/Number
}]
:rows
[[
"A"
2
]
[
"B"
3
]]})))
[
:line
:area
:bar
:combo
:funnel
:progress
:table
:waterfall
]))
(
testing
"Pie charts are correctly identified and return `:categorical/donut`."
(
is
(
=
:categorical/donut
(
render/detect-pulse-chart-type
{
:display
:pie
}
{}
{
:cols
[{
:base_type
:type/Text
}
{
:base_type
:type/Number
}]
:rows
[[
"apple"
3
]
[
"banana"
4
]]}))))
(
testing
"Dashboard Cards can return `:multiple`."
(
is
(
=
:multiple
(
mt/with-temp*
[
Card
[
card1
{
:display
:pie
}]
Card
[
card2
{
:display
:funnel
}]
Dashboard
[
dashboard
]
DashboardCard
[
dc1
{
:dashboard_id
(
u/the-id
dashboard
)
:card_id
(
u/the-id
card1
)}]
DashboardCardSeries
[
_
{
:dashboardcard_id
(
u/the-id
dc1
)
:card_id
(
u/the-id
card2
)}]]
(
render/detect-pulse-chart-type
card1
dc1
{
:cols
[{
:base_type
:type/Temporal
}
{
:base_type
:type/Number
}]
:rows
[[
#
t
"2020"
2
]
[
#
t
"2021"
3
]]}))))))
(
deftest
make-description-if-needed-test
(
testing
"Use Visualization Settings's description if it exists"
...
...
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