Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Fixed flow errors

  • Loading branch information...
valueof committed Oct 1, 2017
1 parent d22b617 commit 5ceddff0031ba9dd9601343e745eb251a815d8e8
Showing with 28 additions and 13 deletions.
  1. +1 −1 lib/interfaces/d3.js
  2. +5 −1 src/client/Actions.js
  3. +2 −2 src/client/Chart.js
  4. +11 −5 src/client/PageController.js
  5. +8 −3 src/client/dom.js
  6. +1 −1 src/shared/utils.js
@@ -12,7 +12,7 @@ declare class _D3_SVG {

declare class _D3_XHR {
header(key: string, value: string): _D3_XHR;
post(data: string): _D3_XHR;
post(data: string, callback: Function): _D3_XHR;
}

declare class _D3 {
@@ -8,7 +8,11 @@ export default class Actions {
listeners: Listeners;
boundListener: Function;

constructor(el: Element) {
constructor(el: ?Element) {
if (!el) {
throw new Error('root element is not initialized yet')
}

this.rootElement = el
this.listeners = {}
}
@@ -163,12 +163,12 @@ export default class Chart {
// set x- and y-axis scales and position functions
this.xScale = d3.scale.linear().domain([0, this.data.getIndexCount()])

this.xPosition = (d) => Math.floor(this.xScale(d.x), 0)
this.xPosition = (d) => Math.floor(this.xScale(d.x))
this.xBarWidth = (d) => {
// have a pixel space when columns are at least 8px wide
var space = this.plotWidth / this.data.getIndexCount() >= 8 ? 1 : 0
var nextXScale = d.x + 1 < this.data.getIndexCount() ? this.xScale(d.x + 1) : this.plotWidth
return Math.floor(nextXScale, 0) - this.xPosition(d) - space
return Math.floor(nextXScale) - this.xPosition(d) - space
}

this.xPositionLine = (d) => {
@@ -186,7 +186,9 @@ export class PageController {

// Populate UI
let fragment = dom.renderFragment(templates.pageSettings())
document.body.appendChild(fragment)
if (document.body) {
document.body.appendChild(fragment)
}

let url = this.params.url
let link = dom.get('js-downloadDataLink')
@@ -400,7 +402,9 @@ export class PageController {
let chartId = utils.getChartId(params)

let fragment = dom.renderFragment(templates.embedOverlay(chartId))
document.body.appendChild(fragment)
if (document.body) {
document.body.appendChild(fragment)
}
}

closeEmbed(): void {
@@ -455,7 +459,8 @@ export class PageController {
var minWidthForHalfWidth = 1200
var minWidthForFullHeight = 800
var windowWidth = window.innerWidth
var windowHeight = 'innerHeight' in window ? window.innerHeight : document.documentElement.offsetHeight
var offsetHeight = document.documentElement ? document.documentElement.offsetHeight : 0
var windowHeight = 'innerHeight' in window ? window.innerHeight : offsetHeight
var defaultHeight = windowWidth > minWidthForFullHeight ? windowHeight : 'auto'
var chartCount = this.chartObjects ? this.chartObjects.length : 0

@@ -508,8 +513,9 @@ export class PageController {

// scrollHeight is not great as the embed can never get shorter. This is a short term
// fix to deal with this fact.
let height = document.body.scrollHeight
height = height > 600 && document.body.offsetWidth >= 800 ? 600 : height
let offsetWidth = document.body ? document.body.offsetWidth : 0
let height = document.body ? document.body.scrollHeight : 0
height = height > 600 && offsetWidth >= 800 ? 600 : height

// Going to send a modified version of the standard resize context.
var message = {
@@ -51,7 +51,7 @@ function renderFragment(html: string): DocumentFragment {
function get(selector: string, root: ?Element): ?Element {
root = root || document.body

if (/^js\-/.test(selector)) {
if (root && /^js\-/.test(selector)) {
return root.querySelector('.' + selector)
}

@@ -61,7 +61,7 @@ function get(selector: string, root: ?Element): ?Element {
function getAll(selector: string, root: ?Element): Element[] {
root = root || document.body

if (/^js\-/.test(selector)) {
if (root && /^js\-/.test(selector)) {
return Array.prototype.slice.call(root.querySelectorAll('.' + selector))
}

@@ -70,7 +70,12 @@ function getAll(selector: string, root: ?Element): Element[] {

function queryAll(selector: string, root: ?Element): Element[] {
root = root || document.body
return Array.prototype.slice.call(root.querySelectorAll(selector))

if (root) {
return Array.prototype.slice.call(root.querySelectorAll(selector))
}

return []
}

function rect(el: Element): ClientRect {
@@ -25,7 +25,7 @@ function parseChartId(url: string): ?string {
}

function log10Floor(val: number): number {
return Math.floor(Math.log(val) / Math.LN10, 0)
return Math.floor(Math.log(val) / Math.LN10)
}

function parseQueryString(qs: string): Object {

0 comments on commit 5ceddff

Please sign in to comment.
You can’t perform that action at this time.