| | |
| | |
| | |
| | |
| |
|
| | import * as d3 from 'd3'; |
| | import { SimpleEventHandler } from './utils/SimpleEventHandler'; |
| | import { TextAnalysisAPI } from './api/GLTR_API'; |
| | import { getTokenSurprisalColor, getByteSurprisalColor } from './utils/SurprisalColorConfig'; |
| |
|
| | |
| | |
| | |
| | export interface CommonAppContext { |
| | eventHandler: SimpleEventHandler; |
| | api: TextAnalysisAPI; |
| | tokenSurprisalColorScale: (value: number) => string; |
| | byteSurprisalColorScale: (value: number) => string; |
| | totalSurprisalFormat: (n: number | null) => string; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | export function initializeCommonApp(apiPrefix: string = '', element?: Element): CommonAppContext { |
| | |
| | const targetElement = element || document.body; |
| | |
| | const format = d3.format('.2f'); |
| | return { |
| | eventHandler: new SimpleEventHandler(targetElement), |
| | api: new TextAnalysisAPI(apiPrefix), |
| | tokenSurprisalColorScale: getTokenSurprisalColor, |
| | byteSurprisalColorScale: getByteSurprisalColor, |
| | totalSurprisalFormat: (n: number | null) => n !== null && Number.isFinite(n) ? format(n) : String(n) |
| | }; |
| | } |
| |
|
| |
|