@techie_doubts/editor-plugin-chart 3.0.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/td-editor-plugin-chart.js +410 -42
- package/package.json +1 -1
- package/types/index.d.ts +8 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* TOAST UI Editor : Chart Plugin
|
|
3
|
-
* @version 3.0
|
|
3
|
+
* @version 3.1.0 | Sat Feb 28 2026
|
|
4
4
|
* @author NHN Cloud FE Development Lab <dl_javascript@nhn.com>
|
|
5
5
|
* @license MIT
|
|
6
6
|
*/
|
|
@@ -6449,6 +6449,7 @@ var DEFAULT_DIMENSION_OPTIONS = {
|
|
|
6449
6449
|
};
|
|
6450
6450
|
var FALLBACK_CONTAINER_WIDTH = 600;
|
|
6451
6451
|
var RESERVED_KEYS = ['type', 'url'];
|
|
6452
|
+
var TOOLTIP_FRACTION_DIGITS = 2;
|
|
6452
6453
|
var chart = {
|
|
6453
6454
|
bar: (tui_chart_2026_root_toastui_Chart_default()).barChart,
|
|
6454
6455
|
column: (tui_chart_2026_root_toastui_Chart_default()).columnChart,
|
|
@@ -6458,6 +6459,7 @@ var chart = {
|
|
|
6458
6459
|
};
|
|
6459
6460
|
var chartMap = {};
|
|
6460
6461
|
var effectiveDarkMode = null;
|
|
6462
|
+
var chartStyleInjected = false;
|
|
6461
6463
|
var DARK_CHART_THEME = {
|
|
6462
6464
|
chart: { backgroundColor: '#1a1a1a' },
|
|
6463
6465
|
title: { color: '#e0e0e0' },
|
|
@@ -6483,6 +6485,16 @@ var DARK_CHART_THEME = {
|
|
|
6483
6485
|
body: { color: '#d1d5db' },
|
|
6484
6486
|
},
|
|
6485
6487
|
};
|
|
6488
|
+
function ensureChartStyles() {
|
|
6489
|
+
if (chartStyleInjected || typeof document === 'undefined') {
|
|
6490
|
+
return;
|
|
6491
|
+
}
|
|
6492
|
+
var style = document.createElement('style');
|
|
6493
|
+
style.setAttribute('data-toastui-chart-plugin', '1');
|
|
6494
|
+
style.textContent = "\n.toastui-chart-block {\n text-align: center;\n}\n\n.toastui-chart-block > * {\n margin-left: auto;\n margin-right: auto;\n}\n\n.toastui-chart-block svg,\n.toastui-chart-block canvas {\n max-width: 100%;\n}\n ".trim();
|
|
6495
|
+
document.head.appendChild(style);
|
|
6496
|
+
chartStyleInjected = true;
|
|
6497
|
+
}
|
|
6486
6498
|
function parse(text, callback) {
|
|
6487
6499
|
var _a;
|
|
6488
6500
|
text = trimKeepingTabs(text);
|
|
@@ -6644,11 +6656,331 @@ function getChartDimension(chartOptions, pluginOptions, chartContainer) {
|
|
|
6644
6656
|
height: clamp(height, minHeight, maxHeight),
|
|
6645
6657
|
};
|
|
6646
6658
|
}
|
|
6647
|
-
function
|
|
6659
|
+
function isPlainObject(value) {
|
|
6660
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
6661
|
+
}
|
|
6662
|
+
function mergeChartOptions(baseOptions, overrideOptions) {
|
|
6663
|
+
var base = isPlainObject(baseOptions) ? baseOptions : {};
|
|
6664
|
+
var override = isPlainObject(overrideOptions) ? overrideOptions : {};
|
|
6665
|
+
var merged = __assign({}, base);
|
|
6666
|
+
Object.keys(override).forEach(function (key) {
|
|
6667
|
+
var baseValue = merged[key];
|
|
6668
|
+
var overrideValue = override[key];
|
|
6669
|
+
merged[key] =
|
|
6670
|
+
isPlainObject(baseValue) && isPlainObject(overrideValue)
|
|
6671
|
+
? mergeChartOptions(baseValue, overrideValue)
|
|
6672
|
+
: overrideValue;
|
|
6673
|
+
});
|
|
6674
|
+
return merged;
|
|
6675
|
+
}
|
|
6676
|
+
function getPluginChartOptions(pluginOptions) {
|
|
6677
|
+
var chartOptions = pluginOptions.chartOptions;
|
|
6678
|
+
return isPlainObject(chartOptions) ? chartOptions : {};
|
|
6679
|
+
}
|
|
6680
|
+
function normalizeSeriesStyleKey(value) {
|
|
6681
|
+
var normalized = typeof value.normalize === 'function' ? value.normalize('NFKC') : value;
|
|
6682
|
+
return normalized
|
|
6683
|
+
.replace(/\uFEFF/g, '')
|
|
6684
|
+
.trim()
|
|
6685
|
+
.replace(/^['"]|['"]$/g, '')
|
|
6686
|
+
.trim()
|
|
6687
|
+
.replace(/\s+/g, ' ')
|
|
6688
|
+
.toLowerCase();
|
|
6689
|
+
}
|
|
6690
|
+
function assignSeriesStyleByIndex(chartOptions, chartData) {
|
|
6691
|
+
if (!chartData || !isPlainObject(chartOptions.series)) {
|
|
6692
|
+
return;
|
|
6693
|
+
}
|
|
6694
|
+
var seriesOptions = chartOptions.series;
|
|
6695
|
+
if (!isPlainObject(seriesOptions.styles)) {
|
|
6696
|
+
return;
|
|
6697
|
+
}
|
|
6698
|
+
var styles = seriesOptions.styles;
|
|
6699
|
+
var indexBySeriesName = new Map();
|
|
6700
|
+
chartData.series.forEach(function (seriesItem, seriesIndex) {
|
|
6701
|
+
if (typeof (seriesItem === null || seriesItem === void 0 ? void 0 : seriesItem.name) === 'string' && seriesItem.name.trim()) {
|
|
6702
|
+
indexBySeriesName.set(normalizeSeriesStyleKey(seriesItem.name), seriesIndex);
|
|
6703
|
+
}
|
|
6704
|
+
});
|
|
6705
|
+
Object.keys(styles).forEach(function (styleKey) {
|
|
6706
|
+
if (/^\d+$/.test(styleKey.trim())) {
|
|
6707
|
+
return;
|
|
6708
|
+
}
|
|
6709
|
+
var seriesIndex = indexBySeriesName.get(normalizeSeriesStyleKey(styleKey));
|
|
6710
|
+
if (typeof seriesIndex !== 'number') {
|
|
6711
|
+
return;
|
|
6712
|
+
}
|
|
6713
|
+
var indexKey = String(seriesIndex);
|
|
6714
|
+
if (typeof styles[indexKey] === 'undefined') {
|
|
6715
|
+
styles[indexKey] = styles[styleKey];
|
|
6716
|
+
}
|
|
6717
|
+
});
|
|
6718
|
+
}
|
|
6719
|
+
function escapeHTML(value) {
|
|
6720
|
+
return String(value !== null && value !== void 0 ? value : '')
|
|
6721
|
+
.replace(/&/g, '&')
|
|
6722
|
+
.replace(/</g, '<')
|
|
6723
|
+
.replace(/>/g, '>')
|
|
6724
|
+
.replace(/"/g, '"')
|
|
6725
|
+
.replace(/'/g, ''');
|
|
6726
|
+
}
|
|
6727
|
+
function isNil(value) {
|
|
6728
|
+
return value === null || typeof value === 'undefined';
|
|
6729
|
+
}
|
|
6730
|
+
function isThousandsOptions(value) {
|
|
6731
|
+
return (isPlainObject(value) &&
|
|
6732
|
+
typeof value.mode === 'string' &&
|
|
6733
|
+
['none', 'locale', 'custom'].includes(value.mode));
|
|
6734
|
+
}
|
|
6735
|
+
function resolveThousandsOptions(value) {
|
|
6736
|
+
if (typeof value === 'string') {
|
|
6737
|
+
return value.length ? { mode: 'custom', separator: value } : { mode: 'none' };
|
|
6738
|
+
}
|
|
6739
|
+
if (value === true || value === 1) {
|
|
6740
|
+
return { mode: 'locale' };
|
|
6741
|
+
}
|
|
6742
|
+
return { mode: 'none' };
|
|
6743
|
+
}
|
|
6744
|
+
function splitNumericText(value) {
|
|
6745
|
+
var matched = value.match(/^([+-]?)(\d+)(\.\d+)?$/);
|
|
6746
|
+
if (!matched) {
|
|
6747
|
+
return null;
|
|
6748
|
+
}
|
|
6749
|
+
return {
|
|
6750
|
+
sign: matched[1] || '',
|
|
6751
|
+
integer: matched[2],
|
|
6752
|
+
fraction: matched[3] || '',
|
|
6753
|
+
};
|
|
6754
|
+
}
|
|
6755
|
+
function applyCustomThousandsSeparator(value, separator) {
|
|
6756
|
+
var parts = splitNumericText(value);
|
|
6757
|
+
if (!parts) {
|
|
6758
|
+
return value;
|
|
6759
|
+
}
|
|
6760
|
+
return "" + parts.sign + parts.integer.replace(/\B(?=(\d{3})+(?!\d))/g, separator) + parts.fraction;
|
|
6761
|
+
}
|
|
6762
|
+
function formatAxisValueWithThousands(value, options) {
|
|
6763
|
+
if (options.mode === 'none') {
|
|
6764
|
+
return value;
|
|
6765
|
+
}
|
|
6766
|
+
if (options.mode === 'custom') {
|
|
6767
|
+
return applyCustomThousandsSeparator(value, options.separator || ' ');
|
|
6768
|
+
}
|
|
6769
|
+
var numericValue = Number(value);
|
|
6770
|
+
if (!Number.isFinite(numericValue)) {
|
|
6771
|
+
return value;
|
|
6772
|
+
}
|
|
6773
|
+
var fractionMatched = value.match(/\.(\d+)$/);
|
|
6774
|
+
var fractionLength = fractionMatched ? fractionMatched[1].length : 0;
|
|
6775
|
+
return numericValue.toLocaleString([], {
|
|
6776
|
+
useGrouping: true,
|
|
6777
|
+
minimumFractionDigits: fractionLength,
|
|
6778
|
+
maximumFractionDigits: fractionLength,
|
|
6779
|
+
});
|
|
6780
|
+
}
|
|
6781
|
+
function inferThousandsOptionsFromFormatter(formatter) {
|
|
6782
|
+
try {
|
|
6783
|
+
var probe = String(formatter('1000'));
|
|
6784
|
+
var matched = probe.match(/1([^0-9])000/);
|
|
6785
|
+
if (matched) {
|
|
6786
|
+
return { mode: 'custom', separator: matched[1] };
|
|
6787
|
+
}
|
|
6788
|
+
}
|
|
6789
|
+
catch (error) {
|
|
6790
|
+
return { mode: 'none' };
|
|
6791
|
+
}
|
|
6792
|
+
return { mode: 'none' };
|
|
6793
|
+
}
|
|
6794
|
+
function getYAxisThousandsOptions(tooltipComponent) {
|
|
6795
|
+
var _a, _b, _c;
|
|
6796
|
+
var chartOptions = (_b = (_a = tooltipComponent === null || tooltipComponent === void 0 ? void 0 : tooltipComponent.store) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.options;
|
|
6797
|
+
var yAxisOptions = Array.isArray(chartOptions === null || chartOptions === void 0 ? void 0 : chartOptions.yAxis)
|
|
6798
|
+
? chartOptions.yAxis[0]
|
|
6799
|
+
: chartOptions === null || chartOptions === void 0 ? void 0 : chartOptions.yAxis;
|
|
6800
|
+
if (!isPlainObject(yAxisOptions)) {
|
|
6801
|
+
return { mode: 'none' };
|
|
6802
|
+
}
|
|
6803
|
+
var metadata = yAxisOptions.__editorThousands;
|
|
6804
|
+
if (isThousandsOptions(metadata)) {
|
|
6805
|
+
return metadata;
|
|
6806
|
+
}
|
|
6807
|
+
if (metadata === true) {
|
|
6808
|
+
return { mode: 'locale' };
|
|
6809
|
+
}
|
|
6810
|
+
var yAxisFormatter = (_c = yAxisOptions.label) === null || _c === void 0 ? void 0 : _c.formatter;
|
|
6811
|
+
if (typeof yAxisFormatter === 'function') {
|
|
6812
|
+
return inferThousandsOptionsFromFormatter(yAxisFormatter);
|
|
6813
|
+
}
|
|
6814
|
+
return { mode: 'none' };
|
|
6815
|
+
}
|
|
6816
|
+
function getTooltipFontStyle(themePart) {
|
|
6817
|
+
if (!themePart || typeof themePart !== 'object') {
|
|
6818
|
+
return '';
|
|
6819
|
+
}
|
|
6820
|
+
var declarations = [];
|
|
6821
|
+
if (!isNil(themePart.fontWeight)) {
|
|
6822
|
+
declarations.push("font-weight: " + themePart.fontWeight);
|
|
6823
|
+
}
|
|
6824
|
+
if (themePart.fontFamily) {
|
|
6825
|
+
declarations.push("font-family: " + themePart.fontFamily);
|
|
6826
|
+
}
|
|
6827
|
+
if (!isNil(themePart.fontSize)) {
|
|
6828
|
+
declarations.push("font-size: " + themePart.fontSize + "px");
|
|
6829
|
+
}
|
|
6830
|
+
if (themePart.color) {
|
|
6831
|
+
declarations.push("color: " + themePart.color);
|
|
6832
|
+
}
|
|
6833
|
+
return declarations.join('; ');
|
|
6834
|
+
}
|
|
6835
|
+
function formatTooltipNumber(value, tooltipComponent) {
|
|
6836
|
+
var thousandsOptions = getYAxisThousandsOptions(tooltipComponent);
|
|
6837
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
6838
|
+
if (thousandsOptions.mode === 'locale') {
|
|
6839
|
+
return value.toLocaleString([], {
|
|
6840
|
+
useGrouping: true,
|
|
6841
|
+
minimumFractionDigits: TOOLTIP_FRACTION_DIGITS,
|
|
6842
|
+
maximumFractionDigits: TOOLTIP_FRACTION_DIGITS,
|
|
6843
|
+
});
|
|
6844
|
+
}
|
|
6845
|
+
var formatted = value.toFixed(TOOLTIP_FRACTION_DIGITS);
|
|
6846
|
+
if (thousandsOptions.mode === 'custom') {
|
|
6847
|
+
return applyCustomThousandsSeparator(formatted, thousandsOptions.separator || ' ');
|
|
6848
|
+
}
|
|
6849
|
+
return formatted;
|
|
6850
|
+
}
|
|
6851
|
+
if (Array.isArray(value)) {
|
|
6852
|
+
return value.map(function (item) { return formatTooltipNumber(item, tooltipComponent); }).join(' - ');
|
|
6853
|
+
}
|
|
6854
|
+
return String(value !== null && value !== void 0 ? value : '');
|
|
6855
|
+
}
|
|
6856
|
+
function getTooltipSeriesCollection(tooltipComponent) {
|
|
6857
|
+
var _a, _b;
|
|
6858
|
+
var seriesState = (_b = (_a = tooltipComponent === null || tooltipComponent === void 0 ? void 0 : tooltipComponent.store) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.series;
|
|
6859
|
+
if (!seriesState || typeof seriesState !== 'object') {
|
|
6860
|
+
return [];
|
|
6861
|
+
}
|
|
6862
|
+
var supportedSeriesTypes = ['line', 'area', 'column', 'bar', 'scatter', 'bubble', 'radar'];
|
|
6863
|
+
for (var _i = 0, supportedSeriesTypes_1 = supportedSeriesTypes; _i < supportedSeriesTypes_1.length; _i++) {
|
|
6864
|
+
var seriesType = supportedSeriesTypes_1[_i];
|
|
6865
|
+
var seriesCollection = seriesState[seriesType];
|
|
6866
|
+
if (Array.isArray(seriesCollection === null || seriesCollection === void 0 ? void 0 : seriesCollection.data) && seriesCollection.data.length) {
|
|
6867
|
+
return seriesCollection.data;
|
|
6868
|
+
}
|
|
6869
|
+
}
|
|
6870
|
+
return [];
|
|
6871
|
+
}
|
|
6872
|
+
function getTooltipCategoryIndex(model) {
|
|
6873
|
+
if (!Array.isArray(model === null || model === void 0 ? void 0 : model.data)) {
|
|
6874
|
+
return null;
|
|
6875
|
+
}
|
|
6876
|
+
var indexOwner = model.data.find(function (item) { return Number.isInteger(item === null || item === void 0 ? void 0 : item.index); });
|
|
6877
|
+
return indexOwner ? indexOwner.index : null;
|
|
6878
|
+
}
|
|
6879
|
+
function getTooltipSeriesColor(colorValue) {
|
|
6880
|
+
if (Array.isArray(colorValue)) {
|
|
6881
|
+
var firstColor = colorValue.find(function (value) { return typeof value === 'string' && value.trim(); });
|
|
6882
|
+
return firstColor || '#8ea0bf';
|
|
6883
|
+
}
|
|
6884
|
+
if (typeof colorValue === 'string' && colorValue.trim()) {
|
|
6885
|
+
return colorValue;
|
|
6886
|
+
}
|
|
6887
|
+
return '#8ea0bf';
|
|
6888
|
+
}
|
|
6889
|
+
function normalizeTooltipSeriesValue(rawValue) {
|
|
6890
|
+
if (isNil(rawValue)) {
|
|
6891
|
+
return null;
|
|
6892
|
+
}
|
|
6893
|
+
if (typeof rawValue === 'number') {
|
|
6894
|
+
return Number.isFinite(rawValue) ? rawValue : null;
|
|
6895
|
+
}
|
|
6896
|
+
if (typeof rawValue === 'string') {
|
|
6897
|
+
var trimmed = rawValue.trim();
|
|
6898
|
+
if (!trimmed) {
|
|
6899
|
+
return null;
|
|
6900
|
+
}
|
|
6901
|
+
var asNumber = Number(trimmed);
|
|
6902
|
+
return Number.isFinite(asNumber) ? asNumber : trimmed;
|
|
6903
|
+
}
|
|
6904
|
+
if (Array.isArray(rawValue)) {
|
|
6905
|
+
if (!rawValue.length) {
|
|
6906
|
+
return null;
|
|
6907
|
+
}
|
|
6908
|
+
if (rawValue.length >= 2) {
|
|
6909
|
+
var secondValue = normalizeTooltipSeriesValue(rawValue[1]);
|
|
6910
|
+
if (!isNil(secondValue)) {
|
|
6911
|
+
return secondValue;
|
|
6912
|
+
}
|
|
6913
|
+
}
|
|
6914
|
+
for (var index = rawValue.length - 1; index >= 0; index -= 1) {
|
|
6915
|
+
var candidate = normalizeTooltipSeriesValue(rawValue[index]);
|
|
6916
|
+
if (!isNil(candidate)) {
|
|
6917
|
+
return candidate;
|
|
6918
|
+
}
|
|
6919
|
+
}
|
|
6920
|
+
return null;
|
|
6921
|
+
}
|
|
6922
|
+
if (typeof rawValue === 'object') {
|
|
6923
|
+
if ('y' in rawValue) {
|
|
6924
|
+
return normalizeTooltipSeriesValue(rawValue.y);
|
|
6925
|
+
}
|
|
6926
|
+
if ('value' in rawValue) {
|
|
6927
|
+
return normalizeTooltipSeriesValue(rawValue.value);
|
|
6928
|
+
}
|
|
6929
|
+
}
|
|
6930
|
+
return null;
|
|
6931
|
+
}
|
|
6932
|
+
function wrapTooltipTemplate(theme, headerMarkup, bodyMarkup) {
|
|
6933
|
+
var borderWidth = Number.isFinite(theme === null || theme === void 0 ? void 0 : theme.borderWidth) ? theme.borderWidth : 1;
|
|
6934
|
+
var borderStyle = (theme === null || theme === void 0 ? void 0 : theme.borderStyle) || 'solid';
|
|
6935
|
+
var borderColor = (theme === null || theme === void 0 ? void 0 : theme.borderColor) || '#d7dce8';
|
|
6936
|
+
var borderRadius = Number.isFinite(theme === null || theme === void 0 ? void 0 : theme.borderRadius) ? theme.borderRadius : 8;
|
|
6937
|
+
var background = (theme === null || theme === void 0 ? void 0 : theme.background) || '#ffffff';
|
|
6938
|
+
var containerStyle = "border: " + borderWidth + "px " + borderStyle + " " + borderColor + ";border-radius: " + borderRadius + "px;background: " + background + ";";
|
|
6939
|
+
return "<div class=\"td-chart-tooltip\" style=\"" + containerStyle + "\">" + headerMarkup + bodyMarkup + "</div>";
|
|
6940
|
+
}
|
|
6941
|
+
function buildFullSeriesTooltip(tooltipComponent, model, defaultTemplate, theme) {
|
|
6942
|
+
var seriesCollection = getTooltipSeriesCollection(tooltipComponent);
|
|
6943
|
+
var categoryIndex = getTooltipCategoryIndex(model);
|
|
6944
|
+
if (!seriesCollection.length || isNil(categoryIndex) || categoryIndex < 0) {
|
|
6945
|
+
return wrapTooltipTemplate(theme, (defaultTemplate === null || defaultTemplate === void 0 ? void 0 : defaultTemplate.header) || '', (defaultTemplate === null || defaultTemplate === void 0 ? void 0 : defaultTemplate.body) || '');
|
|
6946
|
+
}
|
|
6947
|
+
var visibleModelSeries = new Map();
|
|
6948
|
+
for (var _i = 0, _a = model.data || []; _i < _a.length; _i++) {
|
|
6949
|
+
var tooltipData = _a[_i];
|
|
6950
|
+
if (Number.isInteger(tooltipData === null || tooltipData === void 0 ? void 0 : tooltipData.seriesIndex)) {
|
|
6951
|
+
visibleModelSeries.set(tooltipData.seriesIndex, tooltipData);
|
|
6952
|
+
}
|
|
6953
|
+
}
|
|
6954
|
+
var seriesRows = seriesCollection
|
|
6955
|
+
.map(function (seriesItem, seriesIndex) {
|
|
6956
|
+
var _a, _b;
|
|
6957
|
+
var tooltipData = visibleModelSeries.get(seriesIndex);
|
|
6958
|
+
var label = (tooltipData === null || tooltipData === void 0 ? void 0 : tooltipData.label) || (seriesItem === null || seriesItem === void 0 ? void 0 : seriesItem.name) || "Series " + (seriesIndex + 1);
|
|
6959
|
+
var color = getTooltipSeriesColor((_a = tooltipData === null || tooltipData === void 0 ? void 0 : tooltipData.color) !== null && _a !== void 0 ? _a : seriesItem === null || seriesItem === void 0 ? void 0 : seriesItem.color);
|
|
6960
|
+
var rawSeriesValue = Array.isArray(seriesItem === null || seriesItem === void 0 ? void 0 : seriesItem.rawData)
|
|
6961
|
+
? seriesItem.rawData[categoryIndex]
|
|
6962
|
+
: null;
|
|
6963
|
+
var rawValue = (_b = tooltipData === null || tooltipData === void 0 ? void 0 : tooltipData.value) !== null && _b !== void 0 ? _b : rawSeriesValue;
|
|
6964
|
+
var normalizedValue = normalizeTooltipSeriesValue(rawValue);
|
|
6965
|
+
var valueMarkup = isNil(normalizedValue)
|
|
6966
|
+
? '<span class="td-chart-tooltip-none">None</span>'
|
|
6967
|
+
: escapeHTML(formatTooltipNumber(normalizedValue, tooltipComponent));
|
|
6968
|
+
return "<div class=\"td-chart-tooltip-series\">\n <span class=\"td-chart-series-name\">\n <i class=\"td-chart-icon\" style=\"background: " + escapeHTML(color) + "\"></i>\n <span class=\"td-chart-name\">" + escapeHTML(label) + "</span>\n </span>\n <span class=\"td-chart-series-value\">" + valueMarkup + "</span>\n </div>";
|
|
6969
|
+
})
|
|
6970
|
+
.join('');
|
|
6971
|
+
var headerMarkup = model.category
|
|
6972
|
+
? "<div class=\"td-chart-tooltip-category\" style=\"" + getTooltipFontStyle(theme === null || theme === void 0 ? void 0 : theme.header) + "\">" + escapeHTML(model.category) + "</div>"
|
|
6973
|
+
: '';
|
|
6974
|
+
var bodyMarkup = "<div class=\"td-chart-tooltip-series-wrapper\" style=\"" + getTooltipFontStyle(theme === null || theme === void 0 ? void 0 : theme.body) + "\">" + seriesRows + "</div>";
|
|
6975
|
+
return wrapTooltipTemplate(theme, headerMarkup, bodyMarkup);
|
|
6976
|
+
}
|
|
6977
|
+
function setDefaultOptions(chartOptions, pluginOptions, chartContainer, chartData) {
|
|
6978
|
+
chartOptions = mergeChartOptions(getPluginChartOptions(pluginOptions), chartOptions);
|
|
6648
6979
|
chartOptions = Object.assign({
|
|
6649
6980
|
editorChart: {},
|
|
6650
6981
|
chart: {},
|
|
6651
6982
|
exportMenu: {},
|
|
6983
|
+
tooltip: {},
|
|
6652
6984
|
}, chartOptions);
|
|
6653
6985
|
var _a = getChartDimension(chartOptions, pluginOptions, chartContainer), width = _a.width, height = _a.height;
|
|
6654
6986
|
chartOptions.chart.width = width;
|
|
@@ -6657,28 +6989,49 @@ function setDefaultOptions(chartOptions, pluginOptions, chartContainer) {
|
|
|
6657
6989
|
chartOptions.editorChart.type = chartOptions.editorChart.type || 'column';
|
|
6658
6990
|
// default visibility of export menu
|
|
6659
6991
|
chartOptions.exportMenu.visible = !!chartOptions.exportMenu.visible;
|
|
6992
|
+
if (typeof chartOptions.tooltip.transition === 'undefined') {
|
|
6993
|
+
chartOptions.tooltip.transition = false;
|
|
6994
|
+
}
|
|
6995
|
+
if (typeof chartOptions.tooltip.formatter !== 'function') {
|
|
6996
|
+
chartOptions.tooltip.formatter = function formatter(value) {
|
|
6997
|
+
return formatTooltipNumber(value, this);
|
|
6998
|
+
};
|
|
6999
|
+
}
|
|
7000
|
+
if (typeof chartOptions.tooltip.template !== 'function') {
|
|
7001
|
+
chartOptions.tooltip.template = function template(model, defaultTemplate, theme) {
|
|
7002
|
+
return buildFullSeriesTooltip(this, model, defaultTemplate, theme);
|
|
7003
|
+
};
|
|
7004
|
+
}
|
|
6660
7005
|
['xAxis', 'yAxis'].forEach(function (axis) {
|
|
6661
7006
|
var axisOpts = chartOptions[axis];
|
|
6662
7007
|
if (!axisOpts) {
|
|
6663
7008
|
return;
|
|
6664
7009
|
}
|
|
6665
|
-
var
|
|
6666
|
-
|
|
6667
|
-
|
|
6668
|
-
|
|
6669
|
-
|
|
6670
|
-
|
|
6671
|
-
|
|
6672
|
-
|
|
6673
|
-
|
|
6674
|
-
|
|
6675
|
-
|
|
6676
|
-
|
|
6677
|
-
}
|
|
6678
|
-
|
|
6679
|
-
|
|
6680
|
-
|
|
7010
|
+
var axisList = Array.isArray(axisOpts) ? axisOpts : [axisOpts];
|
|
7011
|
+
axisList.forEach(function (axisOption) {
|
|
7012
|
+
if (!isPlainObject(axisOption)) {
|
|
7013
|
+
return;
|
|
7014
|
+
}
|
|
7015
|
+
var normalizedAxisOption = axisOption;
|
|
7016
|
+
var _a = normalizedAxisOption, suffix = _a.suffix, thousands = _a.thousands;
|
|
7017
|
+
var thousandsOptions = resolveThousandsOptions(thousands);
|
|
7018
|
+
normalizedAxisOption.__editorThousands = thousandsOptions;
|
|
7019
|
+
delete normalizedAxisOption.suffix;
|
|
7020
|
+
delete normalizedAxisOption.thousands;
|
|
7021
|
+
if (suffix || thousandsOptions.mode !== 'none') {
|
|
7022
|
+
normalizedAxisOption.label = normalizedAxisOption.label || {};
|
|
7023
|
+
normalizedAxisOption.label.formatter = function (value) {
|
|
7024
|
+
var result = String(value);
|
|
7025
|
+
result = formatAxisValueWithThousands(result, thousandsOptions);
|
|
7026
|
+
if (suffix) {
|
|
7027
|
+
result = "" + result + suffix;
|
|
7028
|
+
}
|
|
7029
|
+
return result;
|
|
7030
|
+
};
|
|
7031
|
+
}
|
|
7032
|
+
});
|
|
6681
7033
|
});
|
|
7034
|
+
assignSeriesStyleByIndex(chartOptions, chartData);
|
|
6682
7035
|
return chartOptions;
|
|
6683
7036
|
}
|
|
6684
7037
|
function isDarkMode(el) {
|
|
@@ -6687,7 +7040,7 @@ function isDarkMode(el) {
|
|
|
6687
7040
|
}
|
|
6688
7041
|
function destroyChart() {
|
|
6689
7042
|
Object.keys(chartMap).forEach(function (id) {
|
|
6690
|
-
var container = document.querySelector("[data-chart-id
|
|
7043
|
+
var container = document.querySelector("[data-chart-id=\"" + id + "\"]");
|
|
6691
7044
|
if (!container) {
|
|
6692
7045
|
chartMap[id].destroy();
|
|
6693
7046
|
delete chartMap[id];
|
|
@@ -6699,7 +7052,7 @@ function doRenderChart(id, text, usageStatistics, pluginOptions, chartContainer)
|
|
|
6699
7052
|
try {
|
|
6700
7053
|
parse(text, function (parsedInfo) {
|
|
6701
7054
|
var _a = parsedInfo || {}, data = _a.data, options = _a.options;
|
|
6702
|
-
var chartOptions = setDefaultOptions(options, pluginOptions, chartContainer);
|
|
7055
|
+
var chartOptions = setDefaultOptions(options, pluginOptions, chartContainer, data);
|
|
6703
7056
|
var chartType = chartOptions.editorChart.type;
|
|
6704
7057
|
var dark = effectiveDarkMode !== null ? effectiveDarkMode : isDarkMode(chartContainer);
|
|
6705
7058
|
if (dark) {
|
|
@@ -6725,13 +7078,20 @@ function doRenderChart(id, text, usageStatistics, pluginOptions, chartContainer)
|
|
|
6725
7078
|
chartContainer.innerHTML = 'invalid chart data';
|
|
6726
7079
|
}
|
|
6727
7080
|
}
|
|
6728
|
-
function renderChart(id, text, usageStatistics, pluginOptions) {
|
|
7081
|
+
function renderChart(id, text, usageStatistics, pluginOptions, retryCount) {
|
|
7082
|
+
if (retryCount === void 0) { retryCount = 0; }
|
|
6729
7083
|
// should draw the chart after rendering container element
|
|
6730
|
-
var chartContainer = document.querySelector("[data-chart-id
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
7084
|
+
var chartContainer = document.querySelector("[data-chart-id=\"" + id + "\"]");
|
|
7085
|
+
if (!chartContainer) {
|
|
7086
|
+
if (retryCount < 8) {
|
|
7087
|
+
requestAnimationFrame(function () {
|
|
7088
|
+
renderChart(id, text, usageStatistics, pluginOptions, retryCount + 1);
|
|
7089
|
+
});
|
|
7090
|
+
}
|
|
7091
|
+
return;
|
|
6734
7092
|
}
|
|
7093
|
+
destroyChart();
|
|
7094
|
+
doRenderChart(id, text, usageStatistics, pluginOptions, chartContainer);
|
|
6735
7095
|
}
|
|
6736
7096
|
function reRenderAllCharts(usageStatistics, pluginOptions, forceDark) {
|
|
6737
7097
|
effectiveDarkMode = forceDark;
|
|
@@ -6750,15 +7110,8 @@ function reRenderAllCharts(usageStatistics, pluginOptions, forceDark) {
|
|
|
6750
7110
|
function generateId() {
|
|
6751
7111
|
return "chart-" + Math.random().toString(36).substr(2, 10);
|
|
6752
7112
|
}
|
|
6753
|
-
var timer = null;
|
|
6754
|
-
function clearTimer() {
|
|
6755
|
-
if (timer) {
|
|
6756
|
-
clearTimeout(timer);
|
|
6757
|
-
timer = null;
|
|
6758
|
-
}
|
|
6759
|
-
}
|
|
6760
7113
|
function getEditorRoot(instance) {
|
|
6761
|
-
var _a
|
|
7114
|
+
var _a;
|
|
6762
7115
|
var elements = null;
|
|
6763
7116
|
try {
|
|
6764
7117
|
elements = (_a = instance.getEditorElements) === null || _a === void 0 ? void 0 : _a.call(instance);
|
|
@@ -6766,13 +7119,19 @@ function getEditorRoot(instance) {
|
|
|
6766
7119
|
catch (e) {
|
|
6767
7120
|
elements = null;
|
|
6768
7121
|
}
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
7122
|
+
var selectors = ['.toastui-editor-defaultUI', '.td-editor-defaultUI'];
|
|
7123
|
+
return (selectors
|
|
7124
|
+
.map(function (selector) { var _a, _b; return ((_a = elements === null || elements === void 0 ? void 0 : elements.mdPreview) === null || _a === void 0 ? void 0 : _a.closest(selector)) || ((_b = elements === null || elements === void 0 ? void 0 : elements.wwEditor) === null || _b === void 0 ? void 0 : _b.closest(selector)); })
|
|
7125
|
+
.find(Boolean) ||
|
|
7126
|
+
selectors.map(function (selector) { return document.querySelector(selector); }).find(Boolean) ||
|
|
7127
|
+
null);
|
|
6772
7128
|
}
|
|
6773
7129
|
function detectDarkMode(instance) {
|
|
6774
|
-
var
|
|
6775
|
-
|
|
7130
|
+
var root = getEditorRoot(instance);
|
|
7131
|
+
if (!root) {
|
|
7132
|
+
return false;
|
|
7133
|
+
}
|
|
7134
|
+
return (root.classList.contains('toastui-editor-dark') || root.classList.contains('td-editor-dark'));
|
|
6776
7135
|
}
|
|
6777
7136
|
/**
|
|
6778
7137
|
* Chart plugin
|
|
@@ -6786,6 +7145,7 @@ function detectDarkMode(instance) {
|
|
|
6786
7145
|
* @param {number|string} [options.height='auto'] - default height
|
|
6787
7146
|
*/
|
|
6788
7147
|
function chartPlugin(context, options) {
|
|
7148
|
+
ensureChartStyles();
|
|
6789
7149
|
var _a = context.usageStatistics, usageStatistics = _a === void 0 ? true : _a;
|
|
6790
7150
|
var instance = context.instance;
|
|
6791
7151
|
var scheduled = false;
|
|
@@ -6833,7 +7193,11 @@ function chartPlugin(context, options) {
|
|
|
6833
7193
|
rootObserver.observe(root, { attributes: true, attributeFilter: ['class'] });
|
|
6834
7194
|
};
|
|
6835
7195
|
context.eventEmitter.listen('changeTheme', function (theme) {
|
|
6836
|
-
|
|
7196
|
+
if (theme === 'dark' || theme === 'light') {
|
|
7197
|
+
scheduleReRender({ themeOverride: theme === 'dark' });
|
|
7198
|
+
return;
|
|
7199
|
+
}
|
|
7200
|
+
scheduleReRender({ deferFrames: 2 });
|
|
6837
7201
|
});
|
|
6838
7202
|
context.eventEmitter.listen('changeMode', function () {
|
|
6839
7203
|
bindThemeObserver();
|
|
@@ -6854,8 +7218,8 @@ function chartPlugin(context, options) {
|
|
|
6854
7218
|
toHTMLRenderers: {
|
|
6855
7219
|
chart: function (node) {
|
|
6856
7220
|
var id = generateId();
|
|
6857
|
-
|
|
6858
|
-
|
|
7221
|
+
var encodedText = encodeURIComponent(node.literal || '');
|
|
7222
|
+
requestAnimationFrame(function () {
|
|
6859
7223
|
renderChart(id, node.literal, usageStatistics, options);
|
|
6860
7224
|
});
|
|
6861
7225
|
return [
|
|
@@ -6863,7 +7227,11 @@ function chartPlugin(context, options) {
|
|
|
6863
7227
|
type: 'openTag',
|
|
6864
7228
|
tagName: 'div',
|
|
6865
7229
|
outerNewLine: true,
|
|
6866
|
-
attributes: {
|
|
7230
|
+
attributes: {
|
|
7231
|
+
class: 'toastui-chart-block',
|
|
7232
|
+
'data-chart-id': id,
|
|
7233
|
+
'data-chart-text': encodedText,
|
|
7234
|
+
},
|
|
6867
7235
|
},
|
|
6868
7236
|
{ type: 'closeTag', tagName: 'div', outerNewLine: true },
|
|
6869
7237
|
];
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { PluginContext, PluginInfo } from '@techie_doubts/tui.editor.2026';
|
|
2
|
+
import type { BaseOptions } from '@techie_doubts/tui.chart.2026';
|
|
2
3
|
|
|
3
4
|
export interface PluginOptions {
|
|
4
|
-
minWidth
|
|
5
|
-
maxWidth
|
|
6
|
-
minHeight
|
|
7
|
-
maxHeight
|
|
8
|
-
width
|
|
9
|
-
height
|
|
5
|
+
minWidth?: number;
|
|
6
|
+
maxWidth?: number;
|
|
7
|
+
minHeight?: number;
|
|
8
|
+
maxHeight?: number;
|
|
9
|
+
width?: number | 'auto';
|
|
10
|
+
height?: number | 'auto';
|
|
11
|
+
chartOptions?: BaseOptions;
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
export default function chartPlugin(context: PluginContext, options: PluginOptions): PluginInfo;
|