| |
| |
| |
| |
| |
| |
| |
| <template> |
| <div |
| class="sparkline sparklineCard" |
| :class="{ notLinkable: !areSparklinesLinkable }" |
| :data-graph-params="graphParamsAttr" |
| :data-series-indices="seriesIndicesAttr" |
| > |
| |
| |
| <div |
| v-if="sparkline.title" |
| class="sparklineCard__title" |
| > |
| {{ sparkline.title }} |
| </div> |
| <NoComparison |
| :sparkline="sparkline" |
| :all-metrics-documentation="allMetricsDocumentation" |
| /> |
| </div> |
| </template> |
| |
| <script lang="ts"> |
| import { computed, defineComponent, PropType } from 'vue'; |
| import { MatomoUrl } from 'CoreHome'; |
| import NoComparison from './NoComparison.vue'; |
| import { SparklineEntry } from './types'; |
| |
| |
| |
| |
| |
| |
| export default defineComponent({ |
| name: 'SparklineCard', |
| components: { |
| NoComparison, |
| }, |
| props: { |
| sparkline: { |
| type: Object as PropType<SparklineEntry>, |
| required: true, |
| }, |
| areSparklinesLinkable: { |
| type: Boolean, |
| default: true, |
| }, |
| |
| allMetricsDocumentation: { |
| type: Object as PropType<Record<string, string>>, |
| default: () => ({}), |
| }, |
| }, |
| setup(props) { |
| |
| |
| const graphParamsAttr = computed(() => { |
| const { graphParams, url } = props.sparkline; |
| |
| |
| if (graphParams && Object.keys(graphParams).length) { |
| return JSON.stringify(graphParams); |
| } |
| |
| |
| |
| |
| |
| |
| if (url) { |
| const parsed = MatomoUrl.parse(url.substring(url.indexOf('?') + 1)); |
| const derived: Record<string, unknown> = {}; |
| (['columns', 'rows', 'idGoal'] as const).forEach((key) => { |
| if (parsed[key]) { |
| derived[key] = parsed[key]; |
| } |
| }); |
| |
| if (Object.keys(derived).length) { |
| return JSON.stringify(derived); |
| } |
| } |
| |
| return null; |
| }); |
| |
| const seriesIndicesAttr = computed(() => { |
| const { seriesIndices } = props.sparkline; |
| return seriesIndices && seriesIndices.length ? JSON.stringify(seriesIndices) : null; |
| }); |
| |
| return { |
| graphParamsAttr, |
| seriesIndicesAttr, |
| }; |
| }, |
| }); |
| </script> |
| |