Skip to content
This repository has been archived by the owner on Apr 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #99 from 4mile/cam/subtotal-html
Browse files Browse the repository at this point in the history
Subtotal vis - Allow rendering of HTML values
  • Loading branch information
RichardCzechowski authored Jul 16, 2019
2 parents e9291f6 + 0439413 commit 19eb6a4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions dist/subtotal.js

Large diffs are not rendered by default.

22 changes: 15 additions & 7 deletions src/examples/subtotal/subtotal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ declare var require: any
const themeClassic = require('subtotal-multiple-aggregates/dist/looker-classic.css')
const themeWhite = require('subtotal-multiple-aggregates/dist/looker-white.css')

import { Looker, VisualizationDefinition } from '../types/types'
import { Looker, VisualizationDefinition, LookerChartUtils, Cell } from '../types/types'

declare var looker: Looker
declare var LookerCharts: LookerChartUtils

type Formatter = ((s: any) => string)
const defaultFormatter: Formatter = (x) => x.toString()
Expand Down Expand Up @@ -90,13 +91,18 @@ const vis: Subtotal = {
pivotSet[pivot] = true
}

const htmlForCell = (cell: Cell) => {
return cell.html ? LookerCharts.Utils.htmlForCell(cell) : cell.value
}

const ptData = []
for (const row of data) {
const ptRow: { [key: string]: any } = {}
for (const key of Object.keys(row)) {
const obj = row[key]
const cell = row[key] as Cell
if (pivotSet[key]) continue
ptRow[key] = obj.html || obj.value
const cellValue = htmlForCell(cell)
ptRow[key] = cellValue
}
if (pivots.length === 0) {
// No pivoting, just add each data row.
Expand All @@ -111,8 +117,9 @@ const vis: Subtotal = {
pivotRow[pivot] = LOOKER_ROW_TOTAL_KEY
}
for (const measure of measures) {
const value = row[measure.name][pivotKey].html || row[measure.name][pivotKey].value
pivotRow[measure.name] = value
const cell = row[measure.name][pivotKey] as Cell
const cellValue = htmlForCell(cell)
pivotRow[measure.name] = cellValue
}
}
} else {
Expand All @@ -121,8 +128,9 @@ const vis: Subtotal = {
pivotRow[pivots[i]] = pivotValues[i]
}
for (const measure of measures) {
const value = row[measure.name][flatKey].html || row[measure.name][flatKey].value
pivotRow[measure.name] = value
const cell = row[measure.name][flatKey] as Cell
const cellValue = htmlForCell(cell)
pivotRow[measure.name] = cellValue
}
}
ptData.push(pivotRow)
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7676,7 +7676,7 @@ strip-json-comments@~2.0.1:

subtotal-multiple-aggregates@4mile/subtotal-multiple-aggregates:
version "1.11.0-alpha.0"
resolved "https://codeload.github.com/4mile/subtotal-multiple-aggregates/tar.gz/68efa13c15e9333ed44d014175d2ec3a3e1b2737"
resolved "https://codeload.github.com/4mile/subtotal-multiple-aggregates/tar.gz/dc031eb35d00977e60f93e45618d5ff8989f13bc"
dependencies:
array-flatten "^2.1.1"
pivottable ">=2.7.0"
Expand Down

0 comments on commit 19eb6a4

Please sign in to comment.