Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added hard-update option for setConfig and react component #105

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/YagrCore/mixins/dynamic-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,13 @@ function areSeriesChanged(a: YagrConfig['series'], b?: YagrConfig['series']) {
return false;
}

function setConfigImpl(yagr: Yagr, batch: Batch, newConfig: Partial<YagrConfig>) {
function setConfigImpl(yagr: Yagr, batch: Batch, newConfig: Partial<YagrConfig>, fullUpdate = false) {
if (fullUpdate) {
yagr.config = {...yagr.config, ...newConfig};
batch.reinit = true;
return;
}

const isChangedKey = isChanged(yagr.config, newConfig);

if (newConfig.title && isChangedKey('title')) {
Expand Down Expand Up @@ -509,8 +515,8 @@ export class DynamicUpdatesMixin<T extends MinimalValidConfig> {
* @param newConfig Partial<YagrConfig>
* @descriptino Sets new config and redraws.
*/
setConfig(this: Yagr<T>, newConfig: Partial<YagrConfig>) {
this.batch((batch) => setConfigImpl(this, batch, newConfig));
setConfig(this: Yagr<T>, newConfig: Partial<YagrConfig>, fullUpdate = false) {
this.batch((batch) => setConfigImpl(this, batch, newConfig, fullUpdate));
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export interface YagrChartProps {
config: MinimalValidConfig;
/** Root component class name */
className?: string;
/** Update strategy */
update?: 'dynamic' | 'hard';
/** Debug data */
debug?: {
filename: string;
Expand All @@ -29,7 +31,7 @@ export interface YagrReactRef {

// eslint-disable-next-line prefer-arrow-callback
export default React.forwardRef(function YagrReact(
{id, config, className = '', debug, onChartLoad, onSelect}: YagrChartProps,
{id, config, className = '', debug, onChartLoad, onSelect, update = 'dynamic'}: YagrChartProps,
ref,
) {
const chartRef = React.useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -63,7 +65,7 @@ export default React.forwardRef(function YagrReact(
}, []);

React.useEffect(() => {
config && chart.current?.setConfig(config);
config && chart.current?.setConfig(config, update === 'hard');
}, [config]);

React.useEffect(() => {
Expand Down