@vizabi/core
Advanced tools
Comparing version 1.27.1 to 1.28.0
@@ -1,7 +0,7 @@ | ||
// http://vizabi.org v1.27.1 Copyright 2023 Jasper Heeffer and others at Gapminder Foundation | ||
// http://vizabi.org v1.28.0 Copyright 2023 Jasper Heeffer and others at Gapminder Foundation | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('mobx')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'mobx'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Dataframe = {}, global.mobx)); | ||
})(this, (function (exports, mobx) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('mobx'), require('d3')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'mobx', 'd3'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Dataframe = {}, global.mobx, global.d3)); | ||
})(this, (function (exports, mobx, d3) { 'use strict'; | ||
@@ -232,6 +232,2 @@ const directions = { | ||
function ucFirst(string) { | ||
return string.charAt(0).toUpperCase() + string.slice(1); | ||
} | ||
// code from https://github.com/TehShrike/is-mergeable-object | ||
@@ -351,14 +347,17 @@ function isMergeableObject(value) { | ||
function interval(intervalSize) { | ||
const nonTimeInterval = { | ||
offset: (n, d) => isNumeric(n) && isNumeric(d) ? n + d : console.error("Can't offset using non-numeric values", { n, d }), | ||
range: d3.range, | ||
floor: Math.floor, | ||
ceil: Math.ceil, | ||
round: Math.round | ||
}; | ||
//case for quarter | ||
if (intervalSize === "quarter") return d3.utcMonth.every(3); | ||
//special case to make weeks start from monday as per ISO 8601, not sunday | ||
if (intervalSize === "week") intervalSize = "monday"; | ||
return d3['utc' + ucFirst(intervalSize)] || nonTimeInterval; | ||
switch (intervalSize) { | ||
case "year": return d3.utcYear; | ||
case "day": return d3.utcDay; | ||
case "month": return d3.utcMonth; | ||
case "week": return d3.utcMonday; | ||
case "quarter": return d3.utcMonth.every(3); | ||
default: return { | ||
//not a time interval | ||
offset: (n, d) => isNumeric(n) && isNumeric(d) ? n + d : console.error("Can't offset using non-numeric values", { n, d }), | ||
range: d3.range, | ||
floor: Math.floor, | ||
ceil: Math.ceil, | ||
round: Math.round | ||
}; | ||
} | ||
} | ||
@@ -1165,3 +1164,3 @@ | ||
if (lastIndex !== undefined && (i - lastIndex) > 1) { | ||
const gapRows = []; // d3.range(lastIndex + 1, i).map(i => group.get(frameKeys[i])) | ||
const gapRows = []; // d3_range(lastIndex + 1, i).map(i => group.get(frameKeys[i])) | ||
for (let j = lastIndex + 1; j < i; j++) { | ||
@@ -1168,0 +1167,0 @@ const gapFrame = group.get(frameKeys[j]); |
{ | ||
"name": "@vizabi/core", | ||
"version": "1.27.1", | ||
"version": "1.28.0", | ||
"description": "Vizabi core (data layer)", | ||
@@ -69,3 +69,3 @@ "main": "dist/Vizabi.js", | ||
"mobx-utils": "^5.5.2", | ||
"rollup": "^2.56.3", | ||
"rollup": "^2.79.1", | ||
"rollup-plugin-livereload": "^2.0.5", | ||
@@ -72,0 +72,0 @@ "rollup-plugin-replace": "^2.2.0", |
import { encoding } from './encoding'; | ||
import { action, observable, reaction, computed, trace } from 'mobx' | ||
import { FULFILLED } from 'mobx-utils' | ||
import { assign, applyDefaults, relativeComplement, configValue, parseConfigValue, inclusiveRange, combineStates, equals, createModel, stepBeforeInterpolator } from '../utils'; | ||
import { assign, applyDefaults, relativeComplement, configValue, parseConfigValue, inclusiveRange, POSSIBLE_INTERVALS, combineStates, equals, createModel, stepBeforeInterpolator } from '../utils'; | ||
import { DataFrameGroup } from '../../dataframe/dataFrameGroup'; | ||
@@ -9,4 +9,4 @@ import { createKeyFn } from '../../dataframe/dfutils'; | ||
import { DataFrame } from '../../dataframe/dataFrame'; | ||
import { extentOfOrdered } from '../../dataframe/info/extent'; | ||
import { resolveRef } from '../config'; | ||
import {range as d3_range} from "d3"; | ||
@@ -27,4 +27,2 @@ const defaultConfig = { | ||
const POSSIBLE_INTERVALS = ["year", "month", "day", "week", "quarter"]; | ||
const defaults = { | ||
@@ -74,3 +72,3 @@ interpolate: true, | ||
get stepScale() { | ||
const range = d3.range(0, this.stepCount); | ||
const range = d3_range(0, this.stepCount); | ||
const scale = this.scale.d3Type(this.domainValues, range); | ||
@@ -77,0 +75,0 @@ |
import { encoding } from './encoding'; | ||
import { defaultDecorator } from '../utils'; | ||
import {ascending as d3_ascending} from "d3"; | ||
@@ -72,3 +73,3 @@ const defaultConfig = { | ||
const hash = Object.keys(d) | ||
.sort(d3.ascending) | ||
.sort(d3_ascending) | ||
.map(key => key + "-" + d[key]) | ||
@@ -75,0 +76,0 @@ .join("--"); |
@@ -7,2 +7,3 @@ import { assign, applyDefaults, clamp, createModel } from "../utils"; | ||
import { createKeyFn } from "../../dataframe/dfutils"; | ||
import {min as d3_min} from "d3"; | ||
@@ -65,3 +66,3 @@ const defaultConfig = { | ||
[min, max] = limits[key]; | ||
max = d3.min([max, this.starts[key]]); | ||
max = d3_min([max, this.starts[key]]); | ||
this.data.filter.set(key, value, [min, max]); | ||
@@ -68,0 +69,0 @@ } |
import { action } from 'mobx'; | ||
import { applyDefaults, deepclone } from "./utils"; | ||
import {rgb as d3_rgb, color as d3_color} from "d3"; | ||
@@ -117,3 +118,3 @@ const defaultConfig = { | ||
// if the resolved colr value is not an array (has only one shade) -- return it | ||
if (!Array.isArray(color)) return args.shadeID == "shade" ? d3.rgb(palette[args.colorID] || this.parent.d3Scale(args.colorID)).darker(0.5).toString() : color; | ||
if (!Array.isArray(color)) return args.shadeID == "shade" ? d3_rgb(palette[args.colorID] || this.parent.d3Scale(args.colorID)).darker(0.5).toString() : color; | ||
@@ -133,3 +134,3 @@ return color[this.shades[args.shadeID]]; | ||
if(!this.parent.config.palette) this.parent.config.palette = {palette: {}}; | ||
this.parent.config.palette.palette["" + pointer] = value ? d3.color(value).hex() : value; | ||
this.parent.config.palette.palette["" + pointer] = value ? d3_color(value).hex() : value; | ||
}), | ||
@@ -136,0 +137,0 @@ removeColor: action('removeColor', function (pointer) { |
@@ -6,2 +6,3 @@ import { applyDefaults, assign, createModel, isString } from "../utils"; | ||
import { resolveRef } from "../config"; | ||
import {schemeCategory10 as d3_schemeCategory10, interpolateRgb as d3_interpolateRgb} from "d3"; | ||
@@ -12,3 +13,3 @@ const defaultConfig = { | ||
const colors = { | ||
schemeCategory10: d3.schemeCategory10 | ||
schemeCategory10: d3_schemeCategory10 | ||
} | ||
@@ -78,3 +79,3 @@ | ||
scale.interpolate(d3.interpolateRgb.gamma(2.2)); | ||
scale.interpolate(d3_interpolateRgb.gamma(2.2)); | ||
} | ||
@@ -81,0 +82,0 @@ |
import { createModel, isNumeric, parseConfigValue, sortDateSafe } from "../utils"; | ||
import { computed } from "mobx"; | ||
import { | ||
scaleLinear as d3_scaleLinear, | ||
scaleLog as d3_scaleLog, | ||
scaleSymlog as d3_scaleSymlog, | ||
scaleSqrt as d3_scaleSqrt, | ||
scaleOrdinal as d3_scaleOrdinal, | ||
scalePoint as d3_scalePoint, | ||
scaleBand as d3_scaleBand, | ||
scaleUtc as d3_scaleUtc, | ||
leastIndex as d3_leastIndex, | ||
min as d3_min, | ||
max as d3_max, | ||
} from "d3"; | ||
const scales = { | ||
"linear": d3.scaleLinear, | ||
"log": d3.scaleLog, | ||
"genericLog": d3.scaleSymlog, | ||
"sqrt": d3.scaleSqrt, | ||
"ordinal": d3.scaleOrdinal, | ||
"point": d3.scalePoint, | ||
"band": d3.scaleBand, | ||
"time": d3.scaleUtc | ||
"linear": d3_scaleLinear, | ||
"log": d3_scaleLog, | ||
"genericLog": d3_scaleSymlog, | ||
"sqrt": d3_scaleSqrt, | ||
"ordinal": d3_scaleOrdinal, | ||
"point": d3_scalePoint, | ||
"band": d3_scaleBand, | ||
"time": d3_scaleUtc | ||
} | ||
@@ -24,3 +37,3 @@ | ||
if (array.length < 2) return true; | ||
return !(d3.min(array) <= 0 && d3.max(array) >= 0); | ||
return !(d3_min(array) <= 0 && d3_max(array) >= 0); | ||
} | ||
@@ -130,3 +143,3 @@ | ||
domain = [...domain]; | ||
const closestToZeroIdx = d3.leastIndex(domain.map(Math.abs)); | ||
const closestToZeroIdx = d3_leastIndex(domain.map(Math.abs)); | ||
domain[closestToZeroIdx] = 0; | ||
@@ -173,3 +186,3 @@ } | ||
domainIncludes(value, domain = this.domain) { | ||
if ([d3.scaleLinear, d3.scaleLog, d3.scaleSymlog, d3.scaleSqrt, d3.scaleUtc].includes(this.d3Type)) { | ||
if ([d3_scaleLinear, d3_scaleLog, d3_scaleSymlog, d3_scaleSqrt, d3_scaleUtc].includes(this.d3Type)) { | ||
const [min, max] = domain; | ||
@@ -176,0 +189,0 @@ return min <= value && value <= max; |
import { fromPromise } from "mobx-utils"; | ||
import { action, autorun, isObservableArray, observable, onBecomeObserved, onBecomeUnobserved } from "mobx"; | ||
import { | ||
utcParse as d3_utcParse, | ||
utcFormat as d3_utcFormat, | ||
range as d3_range, | ||
utcMonth as d3_utcMonth, | ||
utcYear as d3_utcYear, | ||
utcDay as d3_utcDay, | ||
utcMonday as d3_utcMonday, | ||
} from "d3"; | ||
import { createFilterFn } from "../dataframe/transforms/filter"; | ||
@@ -333,3 +342,3 @@ | ||
if (value instanceof Date) { | ||
return concept?.format ? d3.utcFormat(concept.format)(value) : formatDate(value); | ||
return concept?.format ? d3_utcFormat(concept.format)(value) : formatDate(value); | ||
} | ||
@@ -344,15 +353,20 @@ return ""+value; | ||
export const POSSIBLE_INTERVALS = ["year", "month", "day", "week", "quarter"]; | ||
export function interval(intervalSize) { | ||
const nonTimeInterval = { | ||
offset: (n, d) => isNumeric(n) && isNumeric(d) ? n + d : console.error("Can't offset using non-numeric values", { n, d }), | ||
range: d3.range, | ||
floor: Math.floor, | ||
ceil: Math.ceil, | ||
round: Math.round | ||
}; | ||
//case for quarter | ||
if (intervalSize === "quarter") return d3.utcMonth.every(3); | ||
//special case to make weeks start from monday as per ISO 8601, not sunday | ||
if (intervalSize === "week") intervalSize = "monday"; | ||
return d3['utc' + ucFirst(intervalSize)] || nonTimeInterval; | ||
switch (intervalSize) { | ||
case "year": return d3_utcYear; | ||
case "day": return d3_utcDay; | ||
case "month": return d3_utcMonth; | ||
case "week": return d3_utcMonday; | ||
case "quarter": return d3_utcMonth.every(3); | ||
default: return { | ||
//not a time interval | ||
offset: (n, d) => isNumeric(n) && isNumeric(d) ? n + d : console.error("Can't offset using non-numeric values", { n, d }), | ||
range: d3_range, | ||
floor: Math.floor, | ||
ceil: Math.ceil, | ||
round: Math.round | ||
}; | ||
} | ||
} | ||
@@ -366,11 +380,11 @@ | ||
const defaultParsers = [ | ||
d3.utcParse('%Y'), | ||
d3.utcParse('%Y-%m'), | ||
d3.utcParse('%Y-%m-%d'), | ||
d3.utcParse('%Yw%V'), | ||
d3.utcParse('%Yq%q'), | ||
d3.utcParse('%Y-%m-%dT%HZ'), | ||
d3.utcParse('%Y-%m-%dT%H:%MZ'), | ||
d3.utcParse('%Y-%m-%dT%H:%M:%SZ'), | ||
d3.utcParse('%Y-%m-%dT%H:%M:%S.%LZ') | ||
d3_utcParse('%Y'), | ||
d3_utcParse('%Y-%m'), | ||
d3_utcParse('%Y-%m-%d'), | ||
d3_utcParse('%Yw%V'), | ||
d3_utcParse('%Yq%q'), | ||
d3_utcParse('%Y-%m-%dT%HZ'), | ||
d3_utcParse('%Y-%m-%dT%H:%MZ'), | ||
d3_utcParse('%Y-%m-%dT%H:%M:%SZ'), | ||
d3_utcParse('%Y-%m-%dT%H:%M:%S.%LZ') | ||
]; | ||
@@ -402,3 +416,3 @@ | ||
let parsers = concept.format | ||
? [d3.utcParse(concept.format), ...defaultParsers] | ||
? [d3_utcParse(concept.format), ...defaultParsers] | ||
: defaultParsers; | ||
@@ -405,0 +419,0 @@ return tryParse(valueStr, parsers); |
@@ -6,3 +6,2 @@ import { markerStore } from './marker/markerStore' | ||
import { observable } from 'mobx'; | ||
import * as mobx from 'mobx'; | ||
import { csvReader } from '../reader/csv/csv'; | ||
@@ -35,3 +34,2 @@ import { inlineReader } from '../reader/inline/inline'; | ||
vizabi.versionInfo = { version: __VERSION, build: __BUILD, package: __PACKAGE_JSON_FIELDS }; | ||
vizabi.mobx = mobx; | ||
vizabi.utils = utils; | ||
@@ -38,0 +36,0 @@ vizabi.stores = stores; |
import { assign, pickGetters, relativeComplement } from "../../core/utils"; | ||
import {interpolate as d3_interpolate} from "d3"; | ||
@@ -44,3 +45,3 @@ /** | ||
function interpolateGap(gapRows, startRow, endRow, field, interpolator = d3.interpolate) { | ||
function interpolateGap(gapRows, startRow, endRow, field, interpolator = d3_interpolate) { | ||
const startVal = startRow[field]; | ||
@@ -80,3 +81,3 @@ const endVal = endRow[field]; | ||
if (lastIndex !== undefined && (i - lastIndex) > 1) { | ||
const gapRows = []; // d3.range(lastIndex + 1, i).map(i => group.get(frameKeys[i])) | ||
const gapRows = []; // d3_range(lastIndex + 1, i).map(i => group.get(frameKeys[i])) | ||
for (let j = lastIndex + 1; j < i; j++) { | ||
@@ -83,0 +84,0 @@ const gapFrame = group.get(frameKeys[j]); |
import { DataFrame } from "../dataFrame"; | ||
import {interpolate as d3_interpolate} from "d3"; | ||
/** | ||
@@ -19,3 +20,3 @@ * Interplate between two DataFrames | ||
for (let field of fields) { | ||
newRow[field] = (interpolators[field] || d3.interpolate)(row1[field], row2[field])(mu); | ||
newRow[field] = (interpolators[field] || d3_interpolate)(row1[field], row2[field])(mu); | ||
} | ||
@@ -22,0 +23,0 @@ } else { |
import { inlineReader } from "./../inline/inline"; | ||
import { guessDelimiter } from './guess-delimiter.js'; | ||
import { timeInColumns } from './time-in-columns'; | ||
import { | ||
json as d3_json, | ||
autoType as d3_autoType, | ||
dsvFormat as d3_dsvFormat, | ||
text as d3_text, | ||
} from "d3"; | ||
@@ -59,3 +65,3 @@ const TIME_LIKE_CONCEPTS = ["time", "year", "month", "day", "week", "quarter"]; | ||
function loadFile(){ | ||
let textReader = externalTextReader || d3.text; | ||
let textReader = externalTextReader || d3_text; | ||
return textReader(path) | ||
@@ -78,3 +84,3 @@ .catch(error => { | ||
const rows = d3.dsvFormat(delimiter) | ||
const rows = d3_dsvFormat(delimiter) | ||
//parse, and exclude empty rows | ||
@@ -129,3 +135,3 @@ .parse(text, row => Object.values(row).every(v => !v) ? null : row); | ||
const lowerCaseColumn = column.toLowerCase(); | ||
//skip dtypes config for time column which typed to Date with d3.autoType already ('day' and 'month' timeformats for ex.) | ||
//skip dtypes config for time column which typed to Date with d3_autoType already ('day' and 'month' timeformats for ex.) | ||
if (TIME_LIKE_CONCEPTS.includes(lowerCaseColumn) && !(values[0][column] instanceof Date)) dtypes[column] = lowerCaseColumn; | ||
@@ -138,3 +144,3 @@ return dtypes; | ||
function autotype(rows){ | ||
return rows.map(row => d3.autoType(row)); | ||
return rows.map(row => d3_autoType(row)); | ||
} | ||
@@ -165,3 +171,3 @@ | ||
const path = assetsPath + assetName; | ||
const jsonReader = externalJsonReader || d3.json; | ||
const jsonReader = externalJsonReader || d3_json; | ||
@@ -168,0 +174,0 @@ return jsonReader(path) |
import { DataFrame } from "../../dataframe/dataFrame"; | ||
import { arrayEquals, isNonNullObject, relativeComplement } from "../../core/utils"; | ||
import { | ||
utcParse as d3_utcParse, | ||
autoType as d3_autoType, | ||
} from "d3"; | ||
@@ -159,7 +163,7 @@ /** | ||
}, | ||
year: d3.utcParse("%Y"), | ||
month: d3.utcParse("%Y-%m"), | ||
day: d3.utcParse("%Y-%m-%d"), | ||
week: d3.utcParse("%Yw%V"), | ||
quarter: d3.utcParse("%Yq%q") | ||
year: d3_utcParse("%Y"), | ||
month: d3_utcParse("%Y-%m"), | ||
day: d3_utcParse("%Y-%m-%d"), | ||
week: d3_utcParse("%Yw%V"), | ||
quarter: d3_utcParse("%Yq%q") | ||
} | ||
@@ -170,3 +174,3 @@ | ||
if (dtypes == "auto") | ||
return d3.autoType; | ||
return d3_autoType; | ||
@@ -182,3 +186,3 @@ // create field parsers | ||
if (dtype in dtypeParsers) parser = dtypeParsers[dtype]; | ||
if (isNonNullObject(dtype) && "timeFormat" in dtype) parser = d3.utcParse(dtype.timeFormat); | ||
if (isNonNullObject(dtype) && "timeFormat" in dtype) parser = d3_utcParse(dtype.timeFormat); | ||
@@ -204,3 +208,3 @@ if (!parser) { | ||
/** | ||
* Parse string to js primitives or Date. Based on d3.autoType | ||
* Parse string to js primitives or Date. Based on d3_autoType | ||
* @param {any} value Value to be parsed | ||
@@ -207,0 +211,0 @@ */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1303978
13527