Skip to content

add mouse-focus scaling signal - #173

Merged
entronad merged 3 commits into
entronad:mainfrom
fawdlstty:add-signal-patch1
Dec 8, 2022
Merged

add mouse-focus scaling signal#173
entronad merged 3 commits into
entronad:mainfrom
fawdlstty:add-signal-patch1

Conversation

@fawdlstty

@fawdlstty fawdlstty commented Dec 7, 2022

Copy link
Copy Markdown
Contributor

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

entronad commented Dec 8, 2022

Copy link
Copy Markdown
Owner

Thanks!

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

Copy link
Copy Markdown
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