chart2music
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -25,3 +25,19 @@ interface AudioEngine { | ||
declare type ExpandedKeyRegistration = { | ||
key: { | ||
key: string; | ||
shiftKey?: boolean; | ||
ctrlKey?: boolean; | ||
altKey?: boolean; | ||
metaKey?: boolean; | ||
}; | ||
} & { | ||
callback: (point: c2mCallbackType) => void; | ||
title?: string; | ||
keyDescription?: string; | ||
description?: string; | ||
force?: boolean; | ||
}; | ||
declare type SupportedInputType = SupportedDataPointType | number; | ||
declare type AxisScale = "linear" | "log10"; | ||
declare type SonifyTypes = { | ||
@@ -49,2 +65,3 @@ type: SUPPORTED_CHART_TYPES | SUPPORTED_CHART_TYPES[]; | ||
format?: (value: number) => string; | ||
type?: AxisScale; | ||
}; | ||
@@ -69,2 +86,3 @@ declare enum SUPPORTED_CHART_TYPES { | ||
maxWidth?: number; | ||
customHotkeys?: ExpandedKeyRegistration[]; | ||
}; | ||
@@ -119,3 +137,3 @@ declare type c2mGolangReturn = { | ||
private _setData; | ||
setData(data: SonifyTypes["data"], axes?: SonifyTypes["axes"]): void; | ||
setData(data: SonifyTypes["data"], axes?: SonifyTypes["axes"], pointIndex?: number, groupName?: string): void; | ||
getCurrent(): { | ||
@@ -154,2 +172,2 @@ group: string; | ||
export { c2m, c2mChart, c2mChart as default }; | ||
export { c2mChart as default }; |
@@ -1,2 +0,2 @@ | ||
var c2mChart = (function (exports) { | ||
var c2mChart = (function () { | ||
'use strict'; | ||
@@ -127,5 +127,2 @@ | ||
} | ||
unregisterKeyEvent(key) { | ||
delete this._keyMap[key]; | ||
} | ||
generateHelpDialog() { | ||
@@ -248,6 +245,18 @@ const dialog = document.createElement("div"); | ||
const interpolateBin = (point, min, max, bins) => { | ||
const interpolateBin = (point, min, max, bins, scale) => { | ||
return scale === "linear" | ||
? interpolateBinLinear(point, min, max, bins) | ||
: interpolateBinLog(point, min, max, bins); | ||
}; | ||
const interpolateBinLinear = (point, min, max, bins) => { | ||
const pct = (point - min) / (max - min); | ||
return Math.floor(bins * pct); | ||
}; | ||
const interpolateBinLog = (pointRaw, minRaw, maxRaw, bins) => { | ||
const point = Math.log10(pointRaw); | ||
const min = Math.log10(minRaw); | ||
const max = Math.log10(maxRaw); | ||
const pct = (point - min) / (max - min); | ||
return Math.floor(bins * pct); | ||
}; | ||
const calcPan = (pct) => (pct * 2 - 1) * 0.98; | ||
@@ -416,3 +425,4 @@ const generateSummary = ({ type, title, dataRows, x, y, y2, live = false }) => { | ||
label: userAxis?.label ?? "", | ||
format: userAxis?.format ?? defaultFormat | ||
format: userAxis?.format ?? defaultFormat, | ||
type: userAxis?.type ?? "linear" | ||
}; | ||
@@ -550,2 +560,3 @@ }; | ||
}; | ||
const valid_axis_types = ["linear", "log10"]; | ||
const validateInputAxes = (axes) => { | ||
@@ -560,2 +571,13 @@ if (typeof axes === "undefined") { | ||
} | ||
for (const axis in axes) { | ||
const thisAxis = axes[axis]; | ||
if (typeof thisAxis.type === "string" && | ||
!valid_axis_types.includes(thisAxis.type)) { | ||
return `Axis ${axis} has an unsupported axis type "${thisAxis.type}". Valid axis types are: ${valid_axis_types.join(", ")}.`; | ||
} | ||
if (thisAxis.type === "log10" && | ||
(thisAxis.minimum === 0 || thisAxis.maximum === 0)) { | ||
return `Axis ${axis} has type "log10", but has a minimum or maximum value of 0. No values <= 0 are supported for logarithmic axes.`; | ||
} | ||
} | ||
return ""; | ||
@@ -1036,6 +1058,6 @@ }; | ||
} | ||
setData(data, axes) { | ||
setData(data, axes, pointIndex, groupName) { | ||
this._setData(data, axes); | ||
this._pointIndex = 0; | ||
this._groupIndex = 0; | ||
this._pointIndex = Math.min(Math.max(pointIndex ?? 0, 0), this._data[0].length - 1); | ||
this._groupIndex = Math.max(this._groups.indexOf(groupName), 0); | ||
this._sr.render(`${this._title || "Chart"} updated`); | ||
@@ -1255,2 +1277,17 @@ } | ||
]); | ||
const hotkeyCallbackWrapper = (cb) => { | ||
cb({ | ||
slice: this._groups[this._groupIndex], | ||
index: this._pointIndex | ||
}); | ||
}; | ||
this._options.customHotkeys?.forEach((hotkey) => { | ||
this._keyEventManager.registerKeyEvent({ | ||
...hotkey, | ||
key: keyboardEventToString(hotkey.key), | ||
callback: () => { | ||
hotkeyCallbackWrapper(hotkey.callback); | ||
} | ||
}); | ||
}); | ||
} | ||
@@ -1422,3 +1459,3 @@ _setHertzClamps(lowerIndex, upperIndex) { | ||
} | ||
const yBin = interpolateBin(current.y, this._yAxis.minimum, this._yAxis.maximum, hertzes.length - 1); | ||
const yBin = interpolateBin(current.y, this._yAxis.minimum, this._yAxis.maximum, hertzes.length - 1, this._yAxis.type); | ||
this._audioEngine.playDataPoint(hertzes[yBin], xPan, NOTE_LENGTH); | ||
@@ -1431,3 +1468,3 @@ return; | ||
} | ||
const yBin = interpolateBin(current.y2, this._y2Axis.minimum, this._y2Axis.maximum, hertzes.length - 1); | ||
const yBin = interpolateBin(current.y2, this._y2Axis.minimum, this._y2Axis.maximum, hertzes.length - 1, this._y2Axis.type); | ||
this._audioEngine.playDataPoint(hertzes[yBin], xPan, NOTE_LENGTH); | ||
@@ -1442,3 +1479,3 @@ return; | ||
} | ||
const yBin = interpolateBin(current[stat], this._yAxis.minimum, this._yAxis.maximum, hertzes.length - 1); | ||
const yBin = interpolateBin(current[stat], this._yAxis.minimum, this._yAxis.maximum, hertzes.length - 1, this._yAxis.type); | ||
this._audioEngine.playDataPoint(hertzes[yBin], xPan, NOTE_LENGTH); | ||
@@ -1452,3 +1489,3 @@ return; | ||
} | ||
const yBin = interpolateBin(current[stat], this._yAxis.minimum, this._yAxis.maximum, hertzes.length - 1); | ||
const yBin = interpolateBin(current[stat], this._yAxis.minimum, this._yAxis.maximum, hertzes.length - 1, this._yAxis.type); | ||
setTimeout(() => { | ||
@@ -1490,10 +1527,4 @@ this._audioEngine.playDataPoint(hertzes[yBin], xPan, NOTE_LENGTH); | ||
exports.c2m = c2m; | ||
exports.c2mChart = c2mChart; | ||
exports["default"] = c2mChart; | ||
return c2mChart; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
return exports; | ||
})({}); | ||
})(); |
{ | ||
"name": "chart2music", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/index.mjs", |
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
133646
6
3167