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

add mouse-focus scaling signal #173

Merged
merged 3 commits into from
Dec 8, 2022
Merged

Conversation

fawdlstty
Copy link
Contributor

@fawdlstty fawdlstty commented Dec 7, 2022

This PR adds two default signals for scrolling the mouse wheel when the mouse pointer is over the chart, which will focus on the mouse position and then zoom freely, which is more in line with user habits than the original signal.
Run test:

import 'package:flutter/material.dart';
import 'package:graphic/graphic.dart';

import '../data.dart';

class LineAreaPointPage extends StatelessWidget {
  const LineAreaPointPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Line and Area Element'),
      ),
      backgroundColor: Colors.white,
      body: Column(children: [
        Center(
          child: Container(
            margin: const EdgeInsets.only(top: 10),
            width: 800,
            height: 800,
            child: Chart(
              data: scatterData,
              variables: {
                '0': Variable(
                  accessor: (List datum) => datum[0] as num,
                  scale: LinearScale(min: -200, max: 200),
                ),
                '1': Variable(
                  accessor: (List datum) => datum[1] as num,
                  scale: LinearScale(min: -200, max: 200),
                ),
                '2': Variable(accessor: (List datum) => datum[2] as num),
                '4': Variable(accessor: (List datum) => datum[4].toString()),
              },
              elements: [
                PointElement(
                  size: SizeAttr(variable: '2', values: [10, 5]),
                  color: ColorAttr(
                    variable: '4',
                    values: Defaults.colors10,
                    updaters: {
                      'choose': {true: (_) => Colors.red}
                    },
                  ),
                  shape: ShapeAttr(variable: '4', values: [
                    CircleShape(hollow: false),
                    CircleShape(hollow: false),
                  ]),
                )
              ],
              axes: [
                Defaults.horizontalAxis
                  ..position = 0
                  ..grid = Defaults.strokeStyle
                  ..line = Defaults.strokeStyle,
                Defaults.verticalAxis
                  ..position = 0
                  ..grid = Defaults.strokeStyle
                  ..line = Defaults.strokeStyle,
              ],
              coord: RectCoord(
                horizontalRange: [0, 1],
                verticalRange: [0, 1],
                horizontalRangeUpdater: Defaults.horizontalRangeFocusSignal,
                verticalRangeUpdater: Defaults.verticalRangeFocusSignal,
              ),
              selections: {'choose': PointSelection(toggle: true)},
              tooltip: TooltipGuide(
                anchor: (_) => Offset.zero,
                align: Alignment.bottomRight,
                multiTuples: true,
              ),
            ),
          ),
        ),
      ]),
    );
  }
}

@entronad entronad merged commit 5c81fb6 into entronad:main Dec 8, 2022
@entronad
Copy link
Owner

entronad commented Dec 8, 2022

Thanks!

@fawdlstty fawdlstty deleted the add-signal-patch1 branch December 8, 2022 01:49
@entronad
Copy link
Owner

Published in v1.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants